From fe07c2b52f4c2af08bf3aa81d87084da4bced93d Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Fri, 10 Jul 2026 15:34:14 +0000 Subject: [PATCH] feat(mobile): swipe to remove songs (#9) Co-authored-by: Rem Helper Reviewed-on: https://git.abunchofknowitalls.com/joshuafhiggins/otunes/pulls/9 --- .../app/(app)/(tabs)/home/playlist/[id].tsx | 445 ++++++++++++++---- 1 file changed, 348 insertions(+), 97 deletions(-) diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index dfec04d..b204a86 100644 --- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx @@ -1,6 +1,26 @@ import { useMutation, usePaginatedQuery, useQuery } from "convex/react" +import { + Button as SwiftUIButton, + ContextMenu, + Host, + List, + RNHostView, + SwipeActions, +} from "@expo/ui/swift-ui" +import { + frame, + listRowBackground, + listRowInsets, + listRowSeparator, + listSectionSpacing, + listRowSpacing, + listStyle, + onAppear, + scrollContentBackground, +} from "@expo/ui/swift-ui/modifiers" import { Stack, useLocalSearchParams, useRouter } from "expo-router" -import { FlatList, Pressable, StyleSheet, Text, View } from "react-native" +import { FlatList, Platform, Pressable, StyleSheet, Text, View } from "react-native" +import ReanimatedSwipeable from "react-native-gesture-handler/ReanimatedSwipeable" import { Ionicons } from "@expo/vector-icons" import { CoverImage } from "@/components/cover-image" @@ -18,11 +38,14 @@ import { useCoverBackgroundColor } from "@/hooks/use-cover-background-color" import { useMediaMenuActions } from "@/hooks/use-media-menu-actions" import { api } from "@otunes/convex/_generated/api" import type { Id } from "@otunes/convex/_generated/dataModel" +import type { BrowseSong } from "@otunes/convex/types" +import { shareMediaLink } from "@/lib/share-media-link" import { showError, showSuccess } from "@/lib/toast" import { playlistCoverUrl } from "@/lib/urls" import { radius, spacing, useThemeColors } from "@/lib/theme" const PAGE_SIZE = 50 +const NATIVE_LOAD_MORE_THRESHOLD = 10 export default function PlaylistScreen() { const { id } = useLocalSearchParams<{ id: string }>() @@ -88,6 +111,11 @@ export default function PlaylistScreen() { } const songIds = allSongIds + const serverUrl = config.serverUrl + + function maybeLoadMore() { + if (status === "CanLoadMore") loadMore(PAGE_SIZE) + } async function handleSubscribeToggle() { if (!playlist?.id) return @@ -124,6 +152,109 @@ export default function PlaylistScreen() { void handlePlaylistDetailAction(songIds, action) } + async function handleRemoveSong(songId: Id<"songs">) { + if (!playlist?.id) return + try { + await removeSongs({ playlistId: playlist.id, songIds: [songId] }) + showSuccess("Removed from playlist") + } catch (error) { + showError(error instanceof Error ? error.message : "Failed to remove from playlist") + } + } + + function renderSongRow(song: BrowseSong, includeContextMenu = true) { + const row = ( + void playFromSong(song.id, songIds)} + contextMenu={ + includeContextMenu + ? { + favorited: isSongFavorite(song.id), + playlistLabel: "Add to Another Playlist", + navigation: { + artist: { id: song.artist.id }, + album: { id: song.album.id }, + }, + share: { + type: "song", + albumId: song.album.id, + songId: song.id, + }, + onAction: (action) => void handleSongAction(song, action), + } + : undefined + } + /> + ) + + return row + } + + function renderNativeSongContextMenu(song: BrowseSong) { + return ( + + + void shareMediaLink(serverUrl, { + type: "song", + albumId: song.album.id, + songId: song.id, + }) + } + /> + void handleSongAction(song, "playlist")} + /> + void handleSongAction(song, "play-next")} + /> + void handleSongAction(song, "play-last")} + /> + void handleSongAction(song, "shuffle")} + /> + void handleSongAction(song, "go-artist")} + /> + void handleSongAction(song, "go-album")} + /> + void handleSongAction(song, "favorite")} + /> + + ) + } + + const nativeListRowModifiers = [ + listRowBackground(backgroundColor), + listRowInsets({ top: 0, leading: 0, bottom: 0, trailing: 0 }), + listRowSeparator("hidden"), + ] + const nativeSongRowModifiers = [ + frame({ height: 32 }), + ] + const shouldUseNativeSwipeList = + Platform.OS === "ios" && playlist.isOwner && playlist.id + return ( <> - song.id} - style={{ flex: 1, backgroundColor }} - contentContainerStyle={{ paddingBottom: contentBottomInset }} - contentInsetAdjustmentBehavior="automatic" - onEndReached={() => { - if (status === "CanLoadMore") loadMore(PAGE_SIZE) - }} - onEndReachedThreshold={0.5} - ListHeaderComponent={ - - - {playlist.title} - {playlist.owner.name} - - {!playlist.isOwner && playlist.id ? ( - void handleSubscribeToggle()} - style={[ - styles.iconAction, - { - backgroundColor: playlist.isSubscribed - ? colors.muted - : colors.primary, - }, + {shouldUseNativeSwipeList ? ( + + + + + playlist.id && void playPlaylist(playlist.id)} + onShuffle={() => playlist.id && void playPlaylistShuffled(playlist.id)} + /> + + + {songs.map((song, index) => { + const nearEnd = index >= songs.length - NATIVE_LOAD_MORE_THRESHOLD + return ( + - - - ) : null} -