diff --git a/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
index 899d455..fede3e1 100644
--- a/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
@@ -1,31 +1,30 @@
-import { useQuery } from "convex/react"
-import { ScrollView, StyleSheet } from "react-native"
+import { usePaginatedQuery } from "convex/react"
-import { MediaGrid } from "@/components/media-cards"
+import { MediaGridList } from "@/components/media-cards"
import { LoadingView } from "@/components/ui/primitives"
import { contentBottomInset } from "@/components/player"
import { api } from "@otunes/convex/_generated/api"
-import { spacing, useThemeColors } from "@/lib/theme"
+
+const PAGE_SIZE = 50
export default function AlbumsScreen() {
- const colors = useThemeColors()
- const albums = useQuery(api.library.browseAlbums)
+ const { results, status, loadMore } = usePaginatedQuery(
+ api.library.browseAlbumsPaginated,
+ {},
+ { initialNumItems: PAGE_SIZE }
+ )
- if (albums === undefined) {
+ if (results === undefined) {
return
}
return (
-
-
-
+ {
+ if (status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ />
)
}
-
-const styles = StyleSheet.create({
- content: { padding: spacing.lg },
-})
diff --git a/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
index 83a7411..a8679e5 100644
--- a/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
@@ -1,5 +1,5 @@
-import { useQuery } from "convex/react"
-import { Pressable, ScrollView, StyleSheet, Text } from "react-native"
+import { usePaginatedQuery } from "convex/react"
+import { FlatList, Pressable, StyleSheet, Text } from "react-native"
import { MediaContextMenu } from "@/components/media-context-menu"
import { CoverImage } from "@/components/cover-image"
@@ -13,26 +13,36 @@ import type { BrowseArtist } from "@otunes/convex/types"
import { artistCoverUrl } from "@/lib/urls"
import { spacing, useThemeColors } from "@/lib/theme"
+const PAGE_SIZE = 50
+
export default function ArtistsScreen() {
const { push } = useAppNavigation()
const colors = useThemeColors()
const { config } = useServerConfig()
- const artists = useQuery(api.library.browseArtists)
+ const { results, status, loadMore } = usePaginatedQuery(
+ api.library.browseArtistsPaginated,
+ {},
+ { initialNumItems: PAGE_SIZE }
+ )
const { handleArtistAction, isArtistFavorite } = useMediaMenuActions()
- if (artists === undefined || !config) {
+ if (results === undefined || !config) {
return
}
return (
- artist.id}
style={{ flex: 1, backgroundColor: colors.background }}
contentContainerStyle={{ paddingBottom: contentBottomInset }}
contentInsetAdjustmentBehavior="automatic"
- >
- {artists.map((artist: BrowseArtist) => (
+ onEndReached={() => {
+ if (status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ onEndReachedThreshold={0.5}
+ renderItem={({ item: artist }: { item: BrowseArtist }) => (
void handleArtistAction(artist, action)}
@@ -49,8 +59,8 @@ export default function ArtistsScreen() {
{artist.name}
- ))}
-
+ )}
+ />
)
}
diff --git a/apps/mobile/app/(app)/(tabs)/home/index.tsx b/apps/mobile/app/(app)/(tabs)/home/index.tsx
index c558f8e..ab683b1 100644
--- a/apps/mobile/app/(app)/(tabs)/home/index.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/index.tsx
@@ -1,4 +1,4 @@
-import { useQuery } from "convex/react"
+import { usePaginatedQuery } from "convex/react"
import { memo, useRef } from "react"
import { ScrollView, StyleSheet } from "react-native"
@@ -9,6 +9,8 @@ import { api } from "@otunes/convex/_generated/api"
import type { BrowseAlbum, PlaylistSummary } from "@otunes/convex/types"
import { spacing, useThemeColors } from "@/lib/theme"
+const CAROUSEL_ITEM_LIMIT = 10
+
const HomeCarousels = memo(function HomeCarousels({
recentlyAdded,
recentlyPlayed,
@@ -36,8 +38,16 @@ const HomeCarousels = memo(function HomeCarousels({
export default function HomeScreen() {
const colors = useThemeColors()
- const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
- const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
+ const { results: recentlyAdded } = usePaginatedQuery(
+ api.library.browseRecentlyAddedPaginated,
+ {},
+ { initialNumItems: CAROUSEL_ITEM_LIMIT }
+ )
+ const { results: recentlyPlayed } = usePaginatedQuery(
+ api.library.browseRecentlyPlayedPaginated,
+ {},
+ { initialNumItems: CAROUSEL_ITEM_LIMIT }
+ )
const cachedData = useRef<{
recentlyAdded?: BrowseAlbum[]
recentlyPlayed?: (BrowseAlbum | PlaylistSummary)[]
diff --git a/apps/mobile/app/(app)/(tabs)/home/recently-added.tsx b/apps/mobile/app/(app)/(tabs)/home/recently-added.tsx
index cd47c4b..d15b47e 100644
--- a/apps/mobile/app/(app)/(tabs)/home/recently-added.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/recently-added.tsx
@@ -1,31 +1,30 @@
-import { useQuery } from "convex/react"
-import { ScrollView, StyleSheet } from "react-native"
+import { usePaginatedQuery } from "convex/react"
-import { MediaGrid } from "@/components/media-cards"
+import { MediaGridList } from "@/components/media-cards"
import { LoadingView } from "@/components/ui/primitives"
import { contentBottomInset } from "@/components/player"
import { api } from "@otunes/convex/_generated/api"
-import { spacing, useThemeColors } from "@/lib/theme"
+
+const PAGE_SIZE = 50
export default function RecentlyAddedScreen() {
- const colors = useThemeColors()
- const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
+ const { results, status, loadMore } = usePaginatedQuery(
+ api.library.browseRecentlyAddedPaginated,
+ {},
+ { initialNumItems: PAGE_SIZE }
+ )
- if (recentlyAdded === undefined) {
+ if (results === undefined) {
return
}
return (
-
-
-
+ {
+ if (status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ />
)
}
-
-const styles = StyleSheet.create({
- content: { padding: spacing.lg },
-})
diff --git a/apps/mobile/app/(app)/(tabs)/home/recently-played.tsx b/apps/mobile/app/(app)/(tabs)/home/recently-played.tsx
index 9051572..92b5ae7 100644
--- a/apps/mobile/app/(app)/(tabs)/home/recently-played.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/recently-played.tsx
@@ -1,31 +1,30 @@
-import { useQuery } from "convex/react"
-import { ScrollView, StyleSheet } from "react-native"
+import { usePaginatedQuery } from "convex/react"
-import { MediaGrid } from "@/components/media-cards"
+import { MediaGridList } from "@/components/media-cards"
import { LoadingView } from "@/components/ui/primitives"
import { contentBottomInset } from "@/components/player"
import { api } from "@otunes/convex/_generated/api"
-import { spacing, useThemeColors } from "@/lib/theme"
+
+const PAGE_SIZE = 50
export default function RecentlyPlayedScreen() {
- const colors = useThemeColors()
- const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
+ const { results, status, loadMore } = usePaginatedQuery(
+ api.library.browseRecentlyPlayedPaginated,
+ {},
+ { initialNumItems: PAGE_SIZE }
+ )
- if (recentlyPlayed === undefined) {
+ if (results === undefined) {
return
}
return (
-
-
-
+ {
+ if (status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ />
)
}
-
-const styles = StyleSheet.create({
- content: { padding: spacing.lg },
-})
diff --git a/apps/mobile/app/(app)/(tabs)/library/index.tsx b/apps/mobile/app/(app)/(tabs)/library/index.tsx
index af035e4..76b2ef0 100644
--- a/apps/mobile/app/(app)/(tabs)/library/index.tsx
+++ b/apps/mobile/app/(app)/(tabs)/library/index.tsx
@@ -1,4 +1,4 @@
-import { useQuery } from "convex/react"
+import { usePaginatedQuery } from "convex/react"
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { SymbolView } from "expo-symbols"
import { Platform } from "react-native"
@@ -11,6 +11,8 @@ import { useAppNavigation } from "@/lib/app-navigation"
import { api } from "@otunes/convex/_generated/api"
import { appleMusic, spacing, useThemeColors } from "@/lib/theme"
+const RECENTLY_ADDED_PREVIEW_SIZE = 4
+
const links = [
{ title: "Playlists", href: "/browse/playlists", icon: "music.note.list" as const },
{ title: "Artists", href: "/browse/artists", icon: "mic.fill" as const },
@@ -46,7 +48,11 @@ function LibraryIcon({ name }: { name: (typeof links)[number]["icon"] }) {
export default function LibraryScreen() {
const { push } = useAppNavigation()
const colors = useThemeColors()
- const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
+ const { results: recentlyAdded } = usePaginatedQuery(
+ api.library.browseRecentlyAddedPaginated,
+ {},
+ { initialNumItems: RECENTLY_ADDED_PREVIEW_SIZE }
+ )
return (
) : (
-
+
)}
diff --git a/apps/mobile/components/media-cards.tsx b/apps/mobile/components/media-cards.tsx
index 6e63957..522af1a 100644
--- a/apps/mobile/components/media-cards.tsx
+++ b/apps/mobile/components/media-cards.tsx
@@ -1,6 +1,6 @@
import { Ionicons } from "@expo/vector-icons"
import { memo, useCallback } from "react"
-import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
+import { FlatList, Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { CoverImage } from "@/components/cover-image"
import { MediaContextMenu } from "@/components/media-context-menu"
@@ -11,7 +11,7 @@ import type { BrowseAlbum, BrowseArtist, PlaylistSummary } from "@otunes/convex/
import { albumCoverUrl, artistCoverUrl, playlistCoverUrl } from "@/lib/urls"
import { carouselCardWidth, radius, spacing, useThemeColors, useTwoColumnCardWidth } from "@/lib/theme"
-type MediaItem = BrowseAlbum | BrowseArtist | PlaylistSummary
+export type MediaItem = BrowseAlbum | BrowseArtist | PlaylistSummary
export const AlbumCard = memo(function AlbumCard({
album,
@@ -175,6 +175,38 @@ export function MediaGrid({ content }: { content: MediaItem[] }) {
)
}
+export function MediaGridList({
+ content,
+ paddingBottom,
+ onEndReached,
+}: {
+ content: MediaItem[]
+ paddingBottom: number
+ onEndReached?: () => void
+}) {
+ const cardWidth = useTwoColumnCardWidth()
+ const colors = useThemeColors()
+
+ return (
+ item.id}
+ numColumns={2}
+ style={{ flex: 1, backgroundColor: colors.background }}
+ contentContainerStyle={[styles.gridListContent, { paddingBottom }]}
+ columnWrapperStyle={styles.gridListRow}
+ contentInsetAdjustmentBehavior="automatic"
+ onEndReached={onEndReached}
+ onEndReachedThreshold={0.5}
+ renderItem={({ item }) => (
+
+
+
+ )}
+ />
+ )
+}
+
function ContentCarouselBody({
title,
href,
@@ -250,4 +282,11 @@ const styles = StyleSheet.create({
flexWrap: "wrap",
gap: spacing.md,
},
+ gridListContent: {
+ padding: spacing.lg,
+ gap: spacing.md,
+ },
+ gridListRow: {
+ gap: spacing.md,
+ },
})