File tree Expand file tree Collapse file tree 2 files changed +18
-30
lines changed Expand file tree Collapse file tree 2 files changed +18
-30
lines changed Original file line number Diff line number Diff line change @@ -158,25 +158,16 @@ export function ChatPage({
158
158
// Useful for determining which session has been loaded (i.e. still on `new, empty session` or `previous session`)
159
159
const loadedIdSessionRef = useRef < number | null > ( existingChatSessionId ) ;
160
160
161
- // Assistants
162
- const { visibleAssistants, hiddenAssistants : _ } = classifyAssistants (
163
- user ,
164
- availableAssistants
165
- ) ;
166
-
167
- const [ finalAssistants , setFinalAssistants ] = useState ( visibleAssistants ) ;
168
-
169
- useEffect ( ( ) => {
170
- const { visibleAssistants : updatedVisibleAssistants } = classifyAssistants (
161
+ // Assistants in order
162
+ const { finalAssistants } = useMemo ( ( ) => {
163
+ const { visibleAssistants, hiddenAssistants : _ } = classifyAssistants (
171
164
user ,
172
165
availableAssistants
173
166
) ;
174
- setFinalAssistants (
175
- user
176
- ? orderAssistantsForUser ( updatedVisibleAssistants , user )
177
- : updatedVisibleAssistants
178
- ) ;
179
- console . log ( orderAssistantsForUser ( updatedVisibleAssistants , user ) ) ;
167
+ const finalAssistants = user
168
+ ? orderAssistantsForUser ( visibleAssistants , user )
169
+ : visibleAssistants ;
170
+ return { finalAssistants } ;
180
171
} , [ user , availableAssistants ] ) ;
181
172
182
173
const existingChatSessionAssistantId = selectedChatSession ?. persona_id ;
Original file line number Diff line number Diff line change @@ -44,25 +44,22 @@ export function AssistantsTab({
44
44
} )
45
45
) ;
46
46
47
- function handleDragEnd ( event : DragEndEvent ) {
47
+ async function handleDragEnd ( event : DragEndEvent ) {
48
48
const { active, over } = event ;
49
49
50
50
if ( over && active . id !== over . id ) {
51
- setAssistants ( ( items ) => {
52
- const oldIndex = items . findIndex (
53
- ( item ) => item . id . toString ( ) === active . id
54
- ) ;
55
- const newIndex = items . findIndex (
56
- ( item ) => item . id . toString ( ) === over . id
57
- ) ;
58
- const updatedAssistants = arrayMove ( items , oldIndex , newIndex ) ;
51
+ const oldIndex = assistants . findIndex (
52
+ ( item ) => item . id . toString ( ) === active . id
53
+ ) ;
54
+ const newIndex = assistants . findIndex (
55
+ ( item ) => item . id . toString ( ) === over . id
56
+ ) ;
57
+ const updatedAssistants = arrayMove ( assistants , oldIndex , newIndex ) ;
59
58
60
- updateUserAssistantList ( updatedAssistants . map ( ( a ) => a . id ) ) ;
61
-
62
- return updatedAssistants ;
63
- } ) ;
59
+ setAssistants ( updatedAssistants ) ;
60
+ await updateUserAssistantList ( updatedAssistants . map ( ( a ) => a . id ) ) ;
61
+ refreshUser ( ) ;
64
62
}
65
- refreshUser ( ) ;
66
63
}
67
64
68
65
return (
You can’t perform that action at this time.
0 commit comments