Skip to content

Commit

Permalink
♻️ refactor: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 26, 2024
1 parent 5e76458 commit 75c3714
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/app/(main)/profile/(home)/[[...slugs]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Skeleton } from 'antd';
import dynamic from 'next/dynamic';

import SkeletonLoading from '@/components/SkeletonLoading';
import { enableClerk } from '@/const/auth';
import { metadataModule } from '@/server/metadata';
import { translation } from '@/server/translation';
Expand All @@ -13,7 +13,7 @@ import Client from '../Client';
const ClerkProfile = dynamic(() => import('../../features/ClerkProfile'), {
loading: () => (
<div style={{ flex: 1 }}>
<SkeletonLoading paragraph={{ rows: 8 }} title={false} />
<Skeleton paragraph={{ rows: 8 }} title={false} />
</div>
),
});
Expand Down
10 changes: 2 additions & 8 deletions src/app/(main)/profile/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import SkeletonLoading from '@/components/SkeletonLoading';
import FullLoading from '@/components/Loading/BrandTextLoading';

export default () => {
return (
<div style={{ flex: 1 }}>
<SkeletonLoading paragraph={{ rows: 8 }} title={false} />
</div>
);
};
export default () => <FullLoading />;
4 changes: 2 additions & 2 deletions src/app/(main)/profile/security/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Skeleton } from 'antd';
import dynamic from 'next/dynamic';
import { notFound } from 'next/navigation';

import SkeletonLoading from '@/components/SkeletonLoading';
import { enableClerk } from '@/const/auth';
import { metadataModule } from '@/server/metadata';
import { translation } from '@/server/translation';
Expand All @@ -10,7 +10,7 @@ import { isMobileDevice } from '@/utils/server/responsive';
const ClerkProfile = dynamic(() => import('../features/ClerkProfile'), {
loading: () => (
<div style={{ flex: 1 }}>
<SkeletonLoading paragraph={{ rows: 8 }} title={false} />
<Skeleton paragraph={{ rows: 8 }} title={false} />
</div>
),
});
Expand Down
12 changes: 2 additions & 10 deletions src/database/server/models/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@/database/utils/genWhere';
import { idGenerator } from '@/database/utils/idGenerator';
import { parseAgentConfig } from '@/server/globalConfig/parseDefaultAgent';
import { ChatSessionList, LobeAgentSession } from '@/types/session';
import { ChatSessionList, LobeAgentSession, SessionRankItem } from '@/types/session';
import { merge } from '@/utils/merge';

import {
Expand Down Expand Up @@ -119,15 +119,7 @@ export class SessionModel {
return result[0].count;
};

rank = async (): Promise<
{
avatar: string | null;
backgroundColor: string | null;
count: number;
id: string;
title: string | null;
}[]
> => {
rank = async (): Promise<SessionRankItem[]> => {
return this.db
.select({
avatar: agents.avatar,
Expand Down
10 changes: 2 additions & 8 deletions src/database/server/models/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
genWhere,
} from '@/database/utils/genWhere';
import { idGenerator } from '@/database/utils/idGenerator';
import { TopicRankItem } from '@/types/topic';

import { NewMessage, TopicItem, messages, topics } from '../../schemas';

Expand Down Expand Up @@ -126,14 +127,7 @@ export class TopicModel {
return result[0].count;
};

rank = async (): Promise<
{
count: number;
id: string;
sessionId: string | null;
title: string | null;
}[]
> => {
rank = async (): Promise<TopicRankItem[]> => {
return this.db
.select({
count: count(messages.id).as('count'),
Expand Down
6 changes: 2 additions & 4 deletions src/services/message/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dayjs from 'dayjs';

import { INBOX_SESSION_ID } from '@/const/session';
import { clientDB } from '@/database/client/db';
import { MessageModel } from '@/database/server/models/message';
Expand Down Expand Up @@ -52,9 +50,9 @@ export class ClientService extends BaseClientService implements IMessageService
return data as unknown as ChatMessage[];
};

async countMessages(params?: { endDate?: string; range?: [string, string]; startDate?: string }) {
countMessages: IMessageService['countMessages'] = async (params) => {
return this.messageModel.count(params);
}
};

getAllMessagesInSession: IMessageService['getAllMessagesInSession'] = async (sessionId) => {
const data = this.messageModel.queryBySessionId(this.toDbSessionId(sessionId));
Expand Down
8 changes: 2 additions & 6 deletions src/services/message/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ export class ServerService implements IMessageService {
});
};

countMessages = async (params?: {
endDate?: string;
range?: [string, string];
startDate?: string;
}): Promise<number> => {
countMessages: IMessageService['countMessages'] = async (params) => {
return lambdaClient.message.count.query(params);
}
};

updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
return lambdaClient.message.update.mutate({ id, value: { error } });
Expand Down
6 changes: 5 additions & 1 deletion src/services/message/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export interface IMessageService {
getMessages(sessionId: string, topicId?: string): Promise<ChatMessage[]>;
getAllMessages(): Promise<ChatMessage[]>;
getAllMessagesInSession(sessionId: string): Promise<ChatMessage[]>;
countMessages(): Promise<number>;
countMessages(params?: {
endDate?: string;
range?: [string, string];
startDate?: string;
}): Promise<number>;

updateMessageError(id: string, error: ChatMessageError): Promise<any>;
updateMessage(id: string, message: Partial<MessageItem>): Promise<any>;
Expand Down
8 changes: 4 additions & 4 deletions src/services/session/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export class ClientService extends BaseClientService implements ISessionService
}
};

async countSessions(params?: { endDate?: string; range?: [string, string]; startDate?: string }) {
countSessions: ISessionService['countSessions'] = async (params) => {
return this.sessionModel.count(params);
}
};

async rankSessions() {
rankSessions: ISessionService['rankSessions'] = async () => {
return this.sessionModel.rank();
}
};

searchSessions: ISessionService['searchSessions'] = async (keyword) => {
return this.sessionModel.queryByKeyword(keyword);
Expand Down
10 changes: 5 additions & 5 deletions src/services/session/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export class ServerService implements ISessionService {
return lambdaClient.session.getGroupedSessions.query();
};

countSessions = async (params?: {
endDate?: string;
range?: [string, string];
startDate?: string;
}): Promise<number> => {
countSessions: ISessionService['countSessions'] = async (params) => {
return lambdaClient.session.countSessions.query(params);
};

rankSessions: ISessionService['rankSessions'] = async () => {
return lambdaClient.session.rankSessions.query();
};

updateSession: ISessionService['updateSession'] = (id, data) => {
const { group, pinned, meta, updatedAt } = data;
return lambdaClient.session.updateSession.mutate({
Expand Down
11 changes: 2 additions & 9 deletions src/services/session/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LobeSessions,
SessionGroupItem,
SessionGroups,
SessionRankItem,
UpdateSessionParams,
} from '@/types/session';

Expand All @@ -36,15 +37,7 @@ export interface ISessionService {
range?: [string, string];
startDate?: string;
}): Promise<number>;
rankSessions(): Promise<
{
avatar: string | null;
count: number;
id: string;
title: string | null;
backgroundColor: string | null;
}[]
>;
rankSessions(): Promise<SessionRankItem[]>;
searchSessions(keyword: string): Promise<LobeSessions>;

updateSession(id: string, data: Partial<UpdateSessionParams>): Promise<any>;
Expand Down
15 changes: 4 additions & 11 deletions src/services/topic/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,13 @@ export class ClientService extends BaseClientService implements ITopicService {
return data as unknown as Promise<ChatTopic[]>;
};

async countTopics(params?: { endDate?: string; range?: [string, string]; startDate?: string }) {
countTopics: ITopicService['countTopics'] = async (params) => {
return this.topicModel.count(params);
}
};

async rankTopics(): Promise<
{
count: number;
id: string;
sessionId: string | null;
title: string | null;
}[]
> {
rankTopics: ITopicService['rankTopics'] = async () => {
return this.topicModel.rank();
}
};

updateTopic: ITopicService['updateTopic'] = async (id, data) => {
return this.topicModel.update(id, data as any);
Expand Down
19 changes: 4 additions & 15 deletions src/services/topic/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,13 @@ export class ServerService implements ITopicService {
getAllTopics: ITopicService['getAllTopics'] = () =>
lambdaClient.topic.getAllTopics.query() as any;

countTopics = async(params?: {
endDate?: string;
range?: [string, string];
startDate?: string;
}): Promise<number> => {
countTopics: ITopicService['countTopics'] = async (params) => {
return lambdaClient.topic.countTopics.query(params);
}
};

rankTopics = async (): Promise<
{
count: number;
id: string;
sessionId: string | null;
title: string | null;
}[]
> => {
rankTopics: ITopicService['rankTopics'] = async () => {
return lambdaClient.topic.rankTopics.query();
}
};

searchTopics: ITopicService['searchTopics'] = (keywords, sessionId) =>
lambdaClient.topic.searchTopics.query({
Expand Down
17 changes: 7 additions & 10 deletions src/services/topic/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable typescript-sort-keys/interface */
import { BatchTaskResult } from '@/types/service';
import { ChatTopic } from '@/types/topic';
import { ChatTopic, TopicRankItem } from '@/types/topic';

export interface CreateTopicParams {
favorite?: boolean;
Expand All @@ -22,15 +22,12 @@ export interface ITopicService {

getTopics(params: QueryTopicParams): Promise<ChatTopic[]>;
getAllTopics(): Promise<ChatTopic[]>;
countTopics(): Promise<number>;
rankTopics(): Promise<
{
id: string;
title: string | null;
count: number;
sessionId: string | null;
}[]
>;
countTopics(params?: {
endDate?: string;
range?: [string, string];
startDate?: string;
}): Promise<number>;
rankTopics(): Promise<TopicRankItem[]>;
searchTopics(keyword: string, sessionId?: string): Promise<ChatTopic[]>;

updateTopic(id: string, data: Partial<ChatTopic>): Promise<any>;
Expand Down
8 changes: 8 additions & 0 deletions src/types/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ export interface UpdateSessionParams {
pinned?: boolean;
updatedAt: Date;
}

export interface SessionRankItem {
avatar: string | null;
backgroundColor: string | null;
count: number;
id: string;
title: string | null;
}
7 changes: 7 additions & 0 deletions src/types/topic/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ export interface ChatTopic extends Omit<BaseDataModel, 'meta'> {
}

export type ChatTopicMap = Record<string, ChatTopic>;

export interface TopicRankItem {
count: number;
id: string;
sessionId: string | null;
title: string | null;
}

0 comments on commit 75c3714

Please sign in to comment.