Repository navigation
feat(library): add to playlist from everywhere, to several playlists at once #403
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1326,6 +1326,8 @@ export class OverlayManager { | |
| this.focusMainWindow(); | ||
| return; | ||
| } | ||
| // the playlist picker is a dialog in the main window: bring it forward | ||
| if (action.type === "addToPlaylist") this.focusMainWindow(); | ||
|
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. Split the overlay manager responsibilities. This file reaches 1480 lines. Separate IPC routing, settings persistence, shortcut management and window lifecycle into focused modules. Keep window ownership explicit across those modules. As per path instructions, “No file over 150 lines. Suggest splitting into components, hooks or utilities.”
|
||
| if (this.mainWindow && !this.mainWindow.isDestroyed()) { | ||
| this.mainWindow.webContents.send("overlay:action", action); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,11 @@ let request: Promise<void> | null = null; | |
| const listeners = new Set<() => void>(); | ||
| let view = { data: cache, error: undefined as unknown, isLoading: true }; | ||
|
|
||
| /** the playlist list as last loaded, for non-React callers (shortcuts) */ | ||
|
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. Remove the new source comments. Remove both documentation blocks. Preserve the distinction between unknown overlap and zero overlap in the return type and supporting documentation. As per path instructions, “No comments of any kind in code”. Also applies to: 100-104
|
||
| export function getCachedPlaylists(): LibraryPlaylistSummary[] { | ||
| return cache.playlists; | ||
| } | ||
|
|
||
| export function notifyLibraryChanged() { | ||
| window.dispatchEvent(new Event("library:changed")); | ||
| } | ||
|
|
@@ -92,6 +97,23 @@ export function evictPlaylistFromCache(id: string) { | |
| emit(); | ||
| } | ||
|
|
||
| /** | ||
| * how many of `trackIds` a playlist already holds, read from the detail cache | ||
| * only (no request). `undefined` when that playlist hasn't been opened yet or | ||
| * only its first page is known, so callers can't claim "not in playlist". | ||
| */ | ||
| export function cachedPlaylistOverlap( | ||
|
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. Split the playlist hooks module to meet the file-size limit. This file extends beyond Line 386. Separate playlist-list state, playlist-detail loading and cache-access utilities. Keep shared cache ownership explicit so the new readers continue to observe the same state. As per path instructions, “No file over 150 lines.”
|
||
| playlistId: string, | ||
| trackIds: string[], | ||
| ): number | undefined { | ||
| const detail = queryCache.get<LibraryPlaylistDetail>( | ||
| `playlist:detail:${playlistId}`, | ||
| ); | ||
| if (!detail || detail.partial) return undefined; | ||
| const present = new Set(detail.tracks.map((track) => track.id)); | ||
| return trackIds.filter((id) => present.has(id)).length; | ||
| } | ||
|
|
||
| function emit(error?: unknown, isLoading = false) { | ||
| view = { data: cache, error, isLoading }; | ||
| listeners.forEach((l) => l()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { useMemo, useSyncExternalStore } from "react"; | ||
| import { | ||
| readRecentPlaylists, | ||
| subscribeRecentPlaylists, | ||
| } from "../services/addToPlaylists"; | ||
|
|
||
| /** ids of the playlists the user added to most recently, newest first */ | ||
|
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. Remove the source comment. Keep the hook name and return type as the code-level description. As per path instructions, “No comments of any kind in code”.
|
||
| export function useRecentPlaylists(): string[] { | ||
| const raw = useSyncExternalStore( | ||
| subscribeRecentPlaylists, | ||
| () => JSON.stringify(readRecentPlaylists()), | ||
| () => "[]", | ||
| ); | ||
| return useMemo(() => JSON.parse(raw) as string[], [raw]); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { showToast } from "@/shared/ui"; | ||
| import { | ||
| addTracksToPlaylists, | ||
| rememberRecentPlaylists, | ||
| undoAddToPlaylists, | ||
| type AddableTrack, | ||
| type AddToPlaylistsResult, | ||
| } from "../services/addToPlaylists"; | ||
|
|
||
| type Translate = ( | ||
| key: string, | ||
| vars?: Record<string, string | number>, | ||
| ) => string; | ||
|
|
||
| /** | ||
| * One toast for every add flow (picker, submenu, selection bar, shortcuts), | ||
| * with an Undo that deletes exactly the items this add created. | ||
| */ | ||
|
Comment on lines
+15
to
+18
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. Remove both source comments. Remove the documentation block and the comment above As per path instructions, “No comments of any kind in code”. Also applies to: 81-81
|
||
| export function reportAddResult( | ||
| result: AddToPlaylistsResult, | ||
| playlistTitles: Map<string, string>, | ||
| trackCount: number, | ||
| t: Translate, | ||
| ): void { | ||
| const notes: string[] = []; | ||
| if (trackCount > 1 && result.added > 0) { | ||
| notes.push(t("playlist_picker.songs_added", { count: result.added })); | ||
| } | ||
| if (result.alreadyIn > 0 && result.added > 0) { | ||
| notes.push(t("playlist_picker.some_already", { count: result.alreadyIn })); | ||
| } | ||
| if (result.skippedLocal > 0) { | ||
| notes.push( | ||
| t("playlist_picker.local_skipped", { count: result.skippedLocal }), | ||
| ); | ||
| } | ||
| const description = notes.join(" · ") || undefined; | ||
|
|
||
| if (result.added > 0) { | ||
| const touched = result.playlistsTouched; | ||
| const message = | ||
| touched.length === 1 | ||
| ? t("playlist_picker.added_to", { | ||
| count: 1, | ||
| name: playlistTitles.get(touched[0]) ?? "", | ||
| }) | ||
| : t("playlist_picker.added_to", { count: touched.length }); | ||
| const items = result.items; | ||
| showToast(message, "checkmark", { | ||
| description, | ||
| action: { | ||
| label: t("playlist_picker.undo"), | ||
| onClick: () => { | ||
| void undoAddToPlaylists(items).then(() => | ||
| showToast(t("playlist_picker.undone"), "checkmark"), | ||
| ); | ||
| }, | ||
| }, | ||
| }); | ||
| return; | ||
| } | ||
| if (result.failed > 0) { | ||
| showToast(t("common.failed_add_playlist"), "error", { description }); | ||
| return; | ||
| } | ||
| if (result.alreadyIn > 0) { | ||
| showToast( | ||
| trackCount === 1 | ||
| ? t("common.track_already_in_playlist") | ||
| : t("playlist_picker.already_everywhere"), | ||
| "info", | ||
| { description }, | ||
| ); | ||
| return; | ||
| } | ||
| if (result.skippedLocal > 0) { | ||
| showToast(t("common.failed_add_playlist"), "info", { description }); | ||
| } | ||
| } | ||
|
|
||
| /** add + remember as recent + toast, for one-click entry points */ | ||
| export async function addAndReport( | ||
| tracks: AddableTrack[], | ||
| playlists: { id: string; title: string }[], | ||
| t: Translate, | ||
| ): Promise<AddToPlaylistsResult> { | ||
| const ids = playlists.map((p) => p.id); | ||
| const result = await addTracksToPlaylists(tracks, ids); | ||
| if (result.added > 0 || result.alreadyIn > 0) rememberRecentPlaylists(ids); | ||
| reportAddResult( | ||
| result, | ||
| new Map(playlists.map((p) => [p.id, p.title])), | ||
| tracks.length, | ||
| t, | ||
| ); | ||
| return result; | ||
| } | ||
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.
Remove the new inline comment.
Keep the action-specific focus call without the comment. As per path instructions, “No comments of any kind in code (no //, /* */, JSDoc). Flag every one.”
Source: Path instructions