Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 672ff1f

Browse files
committed
Merge branch 'bot_ui_improvements' into 'master'
BotUI: UI/UX improvements See merge request postgres-ai/database-lab!878
2 parents 5e74458 + 201893e commit 672ff1f

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

‎ui/packages/platform/src/pages/Bot/Command/Command.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export const Command = React.memo((props: Props) => {
168168
useEffect(() => {
169169
if (!inputRef.current) return
170170
if (window.innerWidth > theme.breakpoints.values.md) inputRef.current.focus()
171+
setValue('')
171172
}, [threadId]);
172173

173174

‎ui/packages/platform/src/pages/Bot/hooks.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {getChats} from "api/bot/getChats";
1414
import {useAlertSnackbar} from "@postgres.ai/shared/components/AlertSnackbar/useAlertSnackbar";
1515
import {localStorage} from "../../helpers/localStorage";
1616
import { makeChatPublic } from "../../api/bot/makeChatPublic";
17+
import { usePrev } from "../../hooks/usePrev";
1718

1819

1920
const WS_URL = process.env.REACT_APP_WS_URL || '';
@@ -41,26 +42,34 @@ type UseAiBotReturnType = {
4142
wsReadyState: ReadyState;
4243
changeChatVisibility: (threadId: string, isPublic: boolean) => void;
4344
isChangeVisibilityLoading: boolean;
44-
unsubscribe: (threadId: string) => void
45+
unsubscribe: (threadId: string) => void;
46+
chatsList: UseBotChatsListHook['chatsList'];
47+
chatsListLoading: UseBotChatsListHook['loading'];
48+
getChatsList: UseBotChatsListHook['getChatsList']
4549
}
4650

4751
type UseAiBotArgs = {
4852
threadId?: string;
49-
prevThreadId?: string;
50-
onChatLoadingError?: () => void;
53+
orgId?: number
5154
}
5255

5356
export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
54-
const { threadId, onChatLoadingError } = args;
57+
const { threadId, orgId } = args;
5558
const { showMessage, closeSnackbar } = useAlertSnackbar();
5659
let location = useLocation<{skipReloading?: boolean}>();
5760

61+
const {
62+
chatsList,
63+
loading: chatsListLoading,
64+
getChatsList,
65+
} = useBotChatsList(orgId);
66+
5867
const [messages, setMessages] = useState<BotMessage[] | null>(null);
5968
const [isLoading, setLoading] = useState<boolean>(false);
6069
const [error, setError] = useState<ErrorType | null>(null);
6170
const [wsLoading, setWsLoading] = useState<boolean>(false);
6271
const [isChangeVisibilityLoading, setIsChangeVisibilityLoading] = useState<boolean>(false)
63-
72+
6473
const token = localStorage.getAuthToken()
6574

6675
const onWebSocketError = (error: WebSocketEventMap['error']) => {
@@ -92,6 +101,9 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
92101
});
93102
}
94103
}
104+
} else if (threadId !== messageData.thread_id) {
105+
const threadInList = chatsList?.find((item) => item.thread_id === messageData.thread_id)
106+
if (!threadInList) getChatsList()
95107
}
96108
} else {
97109
showMessage('An error occurred. Please try again')
@@ -137,7 +149,6 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
137149
if (response && response.length > 0) {
138150
setMessages(response);
139151
} else {
140-
if (onChatLoadingError) onChatLoadingError();
141152
setError({
142153
code: 404,
143154
message: 'Specified chat not found or you have no access.',
@@ -168,7 +179,6 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
168179
} else if (threadId) {
169180
subscribe(threadId)
170181
}
171-
172182
return () => {
173183
isCancelled = true;
174184
};
@@ -294,15 +304,18 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
294304
sendMessage,
295305
clearChat,
296306
messages,
297-
unsubscribe
307+
unsubscribe,
308+
chatsList,
309+
chatsListLoading,
310+
getChatsList
298311
}
299312
}
300313

301314
type UseBotChatsListHook = {
302315
chatsList: BotMessage[] | null;
303316
error: Response | null;
304317
loading: boolean;
305-
getChatsList: () => void
318+
getChatsList: () => void;
306319
};
307320

308321
export const useBotChatsList = (orgId?: number): UseBotChatsListHook => {

‎ui/packages/platform/src/pages/Bot/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ export const BotPage = (props: BotPageProps) => {
103103
wsReadyState,
104104
isChangeVisibilityLoading,
105105
changeChatVisibility,
106-
unsubscribe
106+
unsubscribe,
107+
chatsListLoading,
108+
getChatsList,
109+
chatsList
107110
} = useAiBot({
108111
threadId: match.params.threadId,
112+
orgId: orgData.id
109113
});
110-
const {chatsList, loading: chatsListLoading, getChatsList} = useBotChatsList(orgData.id);
111114

112115
const matches = useMediaQuery(theme.breakpoints.down('sm'));
113116

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /