Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: threads sorting order after updated #4319

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions web/helpers/atoms/Thread.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@
* Get the active thread state
*/
export const activeThreadStateAtom = atom<ThreadState | undefined>((get) => {
const threadId = get(activeThreadIdAtom)
if (!threadId) {
console.debug('Active thread id is undefined')
return undefined

Check warning on line 93 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

90-93 lines are not covered with tests
}

return get(threadStatesAtom)[threadId]

Check warning on line 96 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

96 line is not covered with tests
})

/**
Expand All @@ -107,7 +107,7 @@
return undefined
}

return get(threadModelParamsAtom)[threadId]

Check warning on line 110 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

110 line is not covered with tests
}
)
/// End Active Thread Atom
Expand All @@ -130,19 +130,19 @@
*/
export const createNewThreadAtom = atom(null, (get, set, newThread: Thread) => {
// create thread state for this new thread
const currentState = { ...get(threadStatesAtom) }

Check warning on line 133 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

133 line is not covered with tests

const threadState: ThreadState = {

Check warning on line 135 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

135 line is not covered with tests
hasMore: false,
waitingForResponse: false,
lastMessage: undefined,
}
currentState[newThread.id] = threadState
set(threadStatesAtom, currentState)

Check warning on line 141 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

140-141 lines are not covered with tests

// add the new thread on top of the thread list to the state
const threads = get(threadsAtom)
set(threadsAtom, [newThread, ...threads])

Check warning on line 145 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

144-145 lines are not covered with tests
})

/**
Expand All @@ -163,13 +163,13 @@
export const updateThreadWaitingForResponseAtom = atom(
null,
(get, set, threadId: string, waitingForResponse: boolean) => {
const currentState = { ...get(threadStatesAtom) }
currentState[threadId] = {

Check warning on line 167 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

166-167 lines are not covered with tests
...currentState[threadId],
waitingForResponse,
error: undefined,
}
set(threadStatesAtom, currentState)

Check warning on line 172 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

172 line is not covered with tests
}
)

Expand All @@ -179,9 +179,9 @@
export const updateThreadStateLastMessageAtom = atom(
null,
(get, set, threadId: string, lastContent?: ThreadContent[]) => {
const currentState = { ...get(threadStatesAtom) }
const lastMessage = lastContent?.[0]?.text?.value ?? ''
currentState[threadId] = {

Check warning on line 184 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

182-184 lines are not covered with tests
...currentState[threadId],
lastMessage,
}
Expand All @@ -200,12 +200,12 @@
)

// sort new threads based on updated at
threads.sort((thread1, thread2) => {
const aDate = new Date(thread1.updated ?? 0)
const bDate = new Date(thread2.updated ?? 0)
return bDate.getTime() - aDate.getTime()
threads.sort((a, b) => {
return ((a.metadata?.updated_at as number) ?? 0) >
((b.metadata?.updated_at as number) ?? 0)
? -1
: 1
})

set(threadsAtom, threads)
}
)
Expand Down
Loading