fix: show empty chat state for loaded sessions
Show the empty chat logo when a session has no messages Keep skeletons only for real session hydration Avoid misleading loading UI after reverting the last message
This commit is contained in:
@@ -274,6 +274,12 @@ export const ChatContainer: React.FC = () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
const sessionMessageCount = useSessionMessageCount(currentSessionId ?? '');
|
const sessionMessageCount = useSessionMessageCount(currentSessionId ?? '');
|
||||||
|
const hasLoadedSessionMessages = useDirectorySync(
|
||||||
|
React.useCallback(
|
||||||
|
(state) => (currentSessionId ? state.message[currentSessionId] !== undefined : false),
|
||||||
|
[currentSessionId],
|
||||||
|
),
|
||||||
|
);
|
||||||
// Messages from sync system
|
// Messages from sync system
|
||||||
const sessionMessageRecords = useSessionMessageRecords(currentSessionId ?? '');
|
const sessionMessageRecords = useSessionMessageRecords(currentSessionId ?? '');
|
||||||
const sessionMessages = currentSessionId ? sessionMessageRecords : EMPTY_MESSAGES;
|
const sessionMessages = currentSessionId ? sessionMessageRecords : EMPTY_MESSAGES;
|
||||||
@@ -398,8 +404,6 @@ export const ChatContainer: React.FC = () => {
|
|||||||
};
|
};
|
||||||
}, [currentSessionId, sessionMessages.length, sync]);
|
}, [currentSessionId, sessionMessages.length, sync]);
|
||||||
|
|
||||||
const hasSessionMessagesEntry = sessionMessages.length > 0 || (currentSessionId ? sync.hasMore(currentSessionId) : false);
|
|
||||||
|
|
||||||
const { isMobile } = useDeviceInfo();
|
const { isMobile } = useDeviceInfo();
|
||||||
const draftOpen = Boolean(newSessionDraft?.open);
|
const draftOpen = Boolean(newSessionDraft?.open);
|
||||||
const isDesktopExpandedInput = isExpandedInput && !isMobile;
|
const isDesktopExpandedInput = isExpandedInput && !isMobile;
|
||||||
@@ -577,12 +581,11 @@ export const ChatContainer: React.FC = () => {
|
|||||||
};
|
};
|
||||||
}, [currentSessionId, isDesktopExpandedInput, scrollRef]);
|
}, [currentSessionId, isDesktopExpandedInput, scrollRef]);
|
||||||
|
|
||||||
const hasHistoryMetadata = Boolean(historyMeta);
|
|
||||||
const lastScrolledSessionRef = React.useRef<string | null>(null);
|
const lastScrolledSessionRef = React.useRef<string | null>(null);
|
||||||
|
|
||||||
const isSessionHydrating =
|
const isSessionHydrating =
|
||||||
Boolean(currentSessionId)
|
Boolean(currentSessionId)
|
||||||
&& (!hasSessionMessagesEntry || !hasHistoryMetadata || historyMeta?.loading === true);
|
&& !hasLoadedSessionMessages;
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!currentSessionId) {
|
if (!currentSessionId) {
|
||||||
@@ -613,7 +616,7 @@ export const ChatContainer: React.FC = () => {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!currentSessionId) return;
|
if (!currentSessionId) return;
|
||||||
if (hasSessionMessagesEntry && hasHistoryMetadata) return;
|
if (hasLoadedSessionMessages) return;
|
||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
await loadMessages(currentSessionId).finally(() => {
|
await loadMessages(currentSessionId).finally(() => {
|
||||||
@@ -635,7 +638,7 @@ export const ChatContainer: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
}, [currentSessionId, hasHistoryMetadata, hasSessionMessagesEntry, isPinned, loadMessages, resumeToLatestInstant, sessionMessages.length, sessionStatusForCurrent.type]);
|
}, [currentSessionId, hasLoadedSessionMessages, isPinned, loadMessages, resumeToLatestInstant, sessionStatusForCurrent.type]);
|
||||||
|
|
||||||
if (!currentSessionId && !draftOpen) {
|
if (!currentSessionId && !draftOpen) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user