-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(frontend): Split friends.ts store into focused modules #120
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
Merged
enko
merged 2 commits into
refactor/store-action-wrapper
from
refactor/split-friends-store
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
2 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { derived, writable } from 'svelte/store'; | ||
| import type { FacetFilters } from '$shared'; | ||
|
|
||
|
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. The |
||
| export interface FriendListFilterState { | ||
| query: string; | ||
| filters: FacetFilters; | ||
| } | ||
|
|
||
| const initialFilterState: FriendListFilterState = { | ||
| query: '', | ||
| filters: {}, | ||
| }; | ||
|
|
||
| function createFriendListFilterStore() { | ||
| const { subscribe, set, update } = writable<FriendListFilterState>(initialFilterState); | ||
|
|
||
| return { | ||
| subscribe, | ||
|
|
||
| setQuery: (query: string) => { | ||
| update((state) => ({ ...state, query })); | ||
| }, | ||
|
|
||
| setFilters: (filters: FacetFilters) => { | ||
| update((state) => ({ ...state, filters })); | ||
| }, | ||
|
|
||
| setState: (query: string, filters: FacetFilters) => { | ||
| set({ query, filters }); | ||
| }, | ||
|
|
||
| clear: () => { | ||
| set(initialFilterState); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export const friendListFilter = createFriendListFilterStore(); | ||
|
|
||
| export const friendListQuery = derived(friendListFilter, ($filter) => $filter.query); | ||
|
|
||
| export const hasFriendListFilters = derived( | ||
| friendListFilter, | ||
| ($filter) => | ||
| $filter.query.trim().length > 0 || | ||
| Object.values($filter.filters).some((arr) => arr && arr.length > 0), | ||
| ); | ||
|
|
||
| /** | ||
| * Build URL search params from filter state. | ||
| * Pure utility — does not read the store; pass a state snapshot. | ||
| */ | ||
| export function buildSearchParams(state: FriendListFilterState): URLSearchParams { | ||
| const params = new URLSearchParams(); | ||
|
|
||
| if (state.query.trim()) { | ||
| params.set('q', state.query.trim()); | ||
| } | ||
|
|
||
| for (const [key, values] of Object.entries(state.filters)) { | ||
| if (values && values.length > 0) { | ||
| params.set(key, values.join(',')); | ||
| } | ||
| } | ||
|
|
||
| return params; | ||
| } | ||
|
|
||
| /** | ||
| * Parse URL search params into filter state. | ||
| * Pure utility — does not read the store. | ||
| */ | ||
| export function parseSearchParams(params: URLSearchParams): FriendListFilterState { | ||
| const query = params.get('q') ?? ''; | ||
| const filters: FacetFilters = {}; | ||
|
|
||
| const stringArrayKeys = [ | ||
| 'country', | ||
| 'city', | ||
| 'organization', | ||
| 'job_title', | ||
| 'department', | ||
| 'circles', | ||
| ] as const; | ||
| for (const key of stringArrayKeys) { | ||
| const value = params.get(key); | ||
| if (value) { | ||
| filters[key] = value.split(','); | ||
| } | ||
| } | ||
|
|
||
| const relationshipCategory = params.get('relationship_category'); | ||
| if (relationshipCategory) { | ||
| filters.relationship_category = relationshipCategory.split(',') as ( | ||
| | 'family' | ||
| | 'professional' | ||
| | 'social' | ||
| )[]; | ||
| } | ||
|
|
||
| return { query, filters }; | ||
| } | ||
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.
The
buildSearchParamsandparseSearchParamsmethods take an externalFriendListFilterStateargument rather than reading the store's own current state. This creates an unusual API where callers must subscribe and pass state back in manually. Consider either (a) making these pure utility functions exported separately from the store, or (b) using Svelte'sget(friendListFilter)internally so callers invoke them without arguments. The current design leaks internal state shape to callers unnecessarily.