-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
[slightly less scuffed bugfix]: Update table rating/favorite when updated anywhere … #707
Merged
jeffvli
merged 6 commits into
jeffvli:development
from
kgarner7:scuffed-fix-rating-favorite
Sep 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7f0b71c
[scuffed bugfix]: Update table rating/favorite when updated anywhere …
kgarner7 11292b9
merge dev
kgarner7 030b6bf
restore should update song
kgarner7 c6f4eeb
update song rating/favorite/played everywhere except playlist
kgarner7 98a7123
special rule for playlists
kgarner7 c7ba49b
use iterator instead
kgarner7 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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { MutableRefObject, useCallback, useEffect } from 'react'; | ||
import { usePlayerStore } from '/@/renderer/store'; | ||
import type { AgGridReact } from '@ag-grid-community/react'; | ||
|
||
export const useFavoriteChange = ( | ||
handler: (ids: string[], favorite: boolean) => void, | ||
enabled: boolean, | ||
) => { | ||
useEffect(() => { | ||
if (!enabled) return () => {}; | ||
|
||
const unSubChange = usePlayerStore.subscribe( | ||
(state) => state.favorite, | ||
(value) => value && handler(value.ids, value.favorite), | ||
); | ||
|
||
return () => { | ||
unSubChange(); | ||
}; | ||
}, [handler, enabled]); | ||
}; | ||
|
||
export const useTableFavoriteChange = ( | ||
tableRef: MutableRefObject<AgGridReact | null>, | ||
enabled: boolean, | ||
) => { | ||
const handler = useCallback( | ||
(ids: string[], favorite: boolean) => { | ||
const api = tableRef.current?.api; | ||
if (api) { | ||
for (const id of ids) { | ||
const node = api.getRowNode(id); | ||
if (node && node.data.userFavorite !== favorite) { | ||
node.setDataValue('userFavorite', favorite); | ||
} | ||
} | ||
} | ||
}, | ||
[tableRef], | ||
); | ||
|
||
useFavoriteChange(handler, enabled); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { MutableRefObject, useCallback, useEffect } from 'react'; | ||
import { usePlayerStore } from '/@/renderer/store'; | ||
import type { AgGridReact } from '@ag-grid-community/react'; | ||
|
||
export const useRatingChange = ( | ||
handler: (ids: string[], rating: number | null) => void, | ||
enabled: boolean, | ||
) => { | ||
useEffect(() => { | ||
if (!enabled) return () => {}; | ||
|
||
const unSubChange = usePlayerStore.subscribe( | ||
(state) => state.rating, | ||
(value) => value && handler(value.ids, value.rating), | ||
); | ||
|
||
return () => { | ||
unSubChange(); | ||
}; | ||
}, [enabled, handler]); | ||
}; | ||
|
||
export const useTableRatingChange = ( | ||
tableRef: MutableRefObject<AgGridReact | null>, | ||
enabled: boolean, | ||
) => { | ||
const handler = useCallback( | ||
(ids: string[], rating: number | null) => { | ||
const api = tableRef.current?.api; | ||
if (api) { | ||
for (const id of ids) { | ||
const node = api.getRowNode(id); | ||
if (node && node.data.userRating !== rating) { | ||
node.setDataValue('userRating', rating); | ||
api.redrawRows({ rowNodes: [node] }); | ||
} | ||
} | ||
} | ||
}, | ||
[tableRef], | ||
); | ||
|
||
useRatingChange(handler, enabled); | ||
}; |
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
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.
Duplicate songs can exist in playlists which is why uniqueId is used here.