mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-29 14:02:19 +00:00
fix(threads): persist selectedThreadId across reloads (#1168)
This commit is contained in:
@@ -245,9 +245,17 @@ const Conversations = ({ variant = 'page' }: ConversationsProps = {}) => {
|
||||
return;
|
||||
}
|
||||
if (data.threads.length > 0) {
|
||||
const mostRecent = data.threads[0];
|
||||
dispatch(setSelectedThread(mostRecent.id));
|
||||
void dispatch(loadThreadMessages(mostRecent.id));
|
||||
// Prefer the thread the user was last viewing (persisted across
|
||||
// reloads via redux-persist on the `thread` slice). Only fall
|
||||
// through to "most recent" if that thread no longer exists
|
||||
// server-side (deleted, purged, or different user).
|
||||
const persistedId = threadStateForSelect.selectedThreadId;
|
||||
const resumeId =
|
||||
persistedId && data.threads.some(t => t.id === persistedId)
|
||||
? persistedId
|
||||
: data.threads[0].id;
|
||||
dispatch(setSelectedThread(resumeId));
|
||||
void dispatch(loadThreadMessages(resumeId));
|
||||
} else {
|
||||
void handleCreateNewThread();
|
||||
}
|
||||
|
||||
@@ -52,10 +52,17 @@ const notificationPersistConfig = {
|
||||
};
|
||||
const persistedNotificationReducer = persistReducer(notificationPersistConfig, notificationReducer);
|
||||
|
||||
// Persist only the user's last-viewed thread id so a reload resumes where
|
||||
// they were instead of falling through to "create a new thread". The
|
||||
// thread list and per-thread message caches are re-fetched from the core
|
||||
// on boot, so we deliberately don't persist them.
|
||||
const threadPersistConfig = { key: 'thread', storage, whitelist: ['selectedThreadId'] };
|
||||
const persistedThreadReducer = persistReducer(threadPersistConfig, threadReducer);
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
socket: socketReducer,
|
||||
thread: threadReducer,
|
||||
thread: persistedThreadReducer,
|
||||
chatRuntime: chatRuntimeReducer,
|
||||
channelConnections: persistedChannelConnectionsReducer,
|
||||
accounts: persistedAccountsReducer,
|
||||
|
||||
Reference in New Issue
Block a user