-
Notifications
You must be signed in to change notification settings - Fork 2
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: ActiveSources + type Sources #82
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,20 @@ export const activeMessageAtom = atom( | |
|
||
// sources, active sources, selected source | ||
export const retrievedSourcesAtom = atom<Source[]>([]); | ||
export const activeSourcesIdsAtom = atom<string[]>([]); | ||
export const activeSourcesIdsAtom = atom<string[] | null>(null); | ||
export const selectedSourceIdAtom = atom<string | null>(null); | ||
|
||
export const activeSourcesAtom = atom( | ||
(get) => { | ||
const retrievedSources = get(retrievedSourcesAtom); | ||
const activeIds = get(activeSourcesIdsAtom); | ||
// Simply filter sources to only include those with IDs in the activeIds array | ||
|
||
// If activeIds is null, return null | ||
if (activeIds === null) { | ||
return null; | ||
} | ||
|
||
// Otherwise filter sources to only include those with IDs in the activeIds array | ||
return retrievedSources.filter(source => activeIds.includes(source.id)); | ||
} | ||
); | ||
|
@@ -169,7 +175,7 @@ export const addUserMessageAtom = atom( | |
|
||
// Update sources-related state. | ||
set(retrievedSourcesAtom, sourcesDataWithIds); | ||
set(activeSourcesIdsAtom, []); | ||
set(activeSourcesIdsAtom, null); | ||
set(selectedSourceIdAtom, null); | ||
return sourcesDataWithIds; | ||
}; | ||
|
@@ -324,7 +330,7 @@ const searchSourcesAtom = atom( | |
set(retrievedSourcesAtom, sourcesDataWithIds); | ||
|
||
// Optionally reset related state associated with sources. | ||
set(activeSourcesIdsAtom, []); | ||
set(activeSourcesIdsAtom, null); | ||
set(selectedSourceIdAtom, null); | ||
|
||
return sourcesDataWithIds; | ||
|
@@ -357,7 +363,7 @@ const clearSourcesAtom = atom(null, (_get, set, { action, response }: { | |
}) => { | ||
console.log('clearSourcesAtom', action, response); | ||
set(retrievedSourcesAtom, []); | ||
set(activeSourcesIdsAtom, []); | ||
set(activeSourcesIdsAtom, null); | ||
set(selectedSourceIdAtom, null); | ||
}); | ||
|
||
|
@@ -367,10 +373,12 @@ const setActiveSourcesAtom = atom(null, (_get, set, { action, response }: { | |
response: SetActiveSourcesActionResponse | ||
}) => { | ||
console.log('setActiveSourcesAtom', action, response); | ||
// Use response.activeSourceIds if provided, otherwise use action.sourceIds | ||
// Ensure we never set to null - empty array is used for reset | ||
const activeSourceIds = response.activeSourceIds ?? action.sourceIds; | ||
if (activeSourceIds) { | ||
set(activeSourcesIdsAtom, activeSourceIds); | ||
} | ||
|
||
// Convert null to empty array to ensure we never set null directly | ||
set(activeSourcesIdsAtom, activeSourceIds === null ? [] : activeSourceIds); | ||
}); | ||
|
||
// set selected source | ||
|
@@ -497,10 +505,10 @@ export const dispatchAtom = atom( | |
|
||
const activeSourcesIds = get(activeSourcesIdsAtom); | ||
|
||
// If activeSourcesIds is empty, use all retrievedSources | ||
// If activeSourcesIds is null, pass null as activeSources | ||
// Otherwise use the filtered sources from activeSourcesAtom | ||
const activeSources = activeSourcesIds.length === 0 | ||
? retrievedSources | ||
const activeSources = activeSourcesIds === null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the atom not return null either way? handling at two places? |
||
? null | ||
: get(activeSourcesAtom); | ||
|
||
// ---- Call the handler | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow setting null from hook?