- {children}
+
+ {children}
+
diff --git a/apps/web/components/app-sidebar.tsx b/apps/web/components/app-sidebar.tsx
index ed30562..e8c9729 100644
--- a/apps/web/components/app-sidebar.tsx
+++ b/apps/web/components/app-sidebar.tsx
@@ -48,6 +48,8 @@ import { playlistCoverUrl } from "@/lib/cover-urls"
import { useCachedQuery } from "@/hooks/use-cached-query"
import { useMounted } from "@/hooks/use-mounted"
import { clearPersistentCache } from "@/lib/persistent-cache"
+import { clearOfflinePages, DOWNLOADS_PATH } from "@/lib/downloads"
+import { OfflineLink } from "@/components/offline-gate"
import { resetPlaybackStores } from "@otunes/convex/client/playback-store"
const OptionsModal = dynamic(() =>
@@ -63,7 +65,13 @@ const library = [
{ title: "Albums", path: "/library/albums", icon: Disc3 },
{ title: "Artists", path: "/library/artists", icon: Mic },
{ title: "Songs", path: "/library/songs", icon: Music2 },
- { title: "Downloads", path: "/library/downloads", icon: ArrowDownToLine },
+ // Opens offline, so it uses OfflineLink.
+ {
+ title: "Downloads",
+ path: DOWNLOADS_PATH,
+ icon: ArrowDownToLine,
+ worksOffline: true,
+ },
]
export function AppSidebar() {
@@ -83,6 +91,7 @@ export function AppSidebar() {
await signOut()
resetPlaybackStores()
await clearPersistentCache()
+ await clearOfflinePages()
router.push("/signin")
}
@@ -160,10 +169,23 @@ export function AppSidebar() {
}
asChild
>
-
setOpenMobile(false)}>
-
-
{item.title}
-
+ {item.worksOffline ? (
+
setOpenMobile(false)}
+ >
+
+ {item.title}
+
+ ) : (
+
setOpenMobile(false)}
+ >
+
+
{item.title}
+
+ )}
))}
diff --git a/apps/web/components/downloads-provider.tsx b/apps/web/components/downloads-provider.tsx
index 5a775b9..802c119 100644
--- a/apps/web/components/downloads-provider.tsx
+++ b/apps/web/components/downloads-provider.tsx
@@ -21,8 +21,12 @@ import { useDownloadsVersion } from "@/hooks/use-downloads"
import {
downloadQueue,
readRememberedDownloadQuality,
+ DOWNLOADS_PATH,
+ downloadedCollectionPath,
+ OTHER_DOWNLOADS_PATH,
registerDownloadsServiceWorker,
requestPersistentStorage,
+ saveDownloadPagesForOffline,
writeRememberedDownloadQuality,
} from "@/lib/downloads"
import { api } from "@otunes/convex/_generated/api"
@@ -278,6 +282,27 @@ function useFailureToasts() {
}, [])
}
+/** Keeps Downloads and each downloaded collection's page saved for offline. */
+function OfflinePagesSync() {
+ useDownloadsVersion()
+ const collectionPaths = downloadQueue
+ .collections()
+ .map(downloadedCollectionPath)
+ const hasOtherSongs = downloadQueue.otherSongIds().length > 0
+ // A string, so the effect reruns only when the saved set changes.
+ const pathsKey = collectionPaths.join("\n")
+
+ React.useEffect(() => {
+ if (!pathsKey && !hasOtherSongs) return
+ saveDownloadPagesForOffline([
+ DOWNLOADS_PATH,
+ OTHER_DOWNLOADS_PATH,
+ ...(pathsKey ? pathsKey.split("\n") : []),
+ ])
+ }, [pathsKey, hasOtherSongs])
+ return null
+}
+
export function DownloadsProvider({ children }: { children: React.ReactNode }) {
const [pending, setPending] = React.useState<{
target: DownloadTarget
@@ -329,6 +354,7 @@ export function DownloadsProvider({ children }: { children: React.ReactNode }) {
{children}
+
setPending(null)}
diff --git a/apps/web/components/downloads-view.tsx b/apps/web/components/downloads-view.tsx
index 14d3c99..0612424 100644
--- a/apps/web/components/downloads-view.tsx
+++ b/apps/web/components/downloads-view.tsx
@@ -2,32 +2,24 @@
import * as React from "react"
import Image from "next/image"
-import Link from "next/link"
import { Star } from "lucide-react"
import { FAVORITES_DOWNLOAD_ID } from "@/components/downloads-provider"
import { PageHeader } from "@/components/library-skeletons"
-import {
- FROM_DOWNLOADS_PARAM,
- useDownloadsVersion,
-} from "@/hooks/use-downloads"
+import { OfflineLink } from "@/components/offline-gate"
+import { useDownloadsVersion } from "@/hooks/use-downloads"
import { albumGridClassName } from "@/lib/album-grid-classes"
import { albumCoverUrl, playlistCoverUrl } from "@/lib/cover-urls"
-import { downloadQueue } from "@/lib/downloads"
+import {
+ downloadedCollectionPath,
+ downloadQueue,
+ OTHER_DOWNLOADS_PATH,
+} from "@/lib/downloads"
import type { DownloadedCollection } from "@otunes/convex/client/download-queue"
import { formatBytes } from "@otunes/convex/download-quality"
-export const OTHER_DOWNLOADS_PATH = "/library/downloads/other"
export const OTHER_DOWNLOADS_TITLE = "Other Downloaded Songs"
-function collectionHref({ kind, id }: DownloadedCollection) {
- if (kind === "album") return `/album/${id}?${FROM_DOWNLOADS_PARAM}`
- if (id === FAVORITES_DOWNLOAD_ID) {
- return `/playlist/favorites?${FROM_DOWNLOADS_PARAM}`
- }
- return `/playlist/${id}?${FROM_DOWNLOADS_PARAM}`
-}
-
function CollectionCover({ collection }: { collection: DownloadedCollection }) {
if (collection.id === FAVORITES_DOWNLOAD_ID) {
return (
@@ -63,7 +55,7 @@ function DownloadCard({
cover: React.ReactNode
}) {
return (
-
+
{cover}
@@ -75,7 +67,7 @@ function DownloadCard({
{subtitle}
-
+
)
}
@@ -138,7 +130,7 @@ export function DownloadsView() {
{rows.map(({ collection, bytes }) => (