Compare commits

...
6 changed files with 14 additions and 65 deletions

No files matched your search

@@ -49,7 +49,7 @@ import type { BrowsePlaylistDetail, BrowseSong } from "@otunes/convex/types"
import type { CoverPalette } from "@/lib/cover-palette" import type { CoverPalette } from "@/lib/cover-palette"
import { longListProps } from "@/lib/list" import { longListProps } from "@/lib/list"
import { rememberSongs } from "@/lib/song-cache" import { rememberSongs } from "@/lib/song-cache"
import { showError, showSuccess } from "@/lib/toast" import { showError } from "@/lib/toast"
import { playlistCoverUrl } from "@/lib/urls" import { playlistCoverUrl } from "@/lib/urls"
import { radius, spacing, useThemeColors } from "@/lib/theme" import { radius, spacing, useThemeColors } from "@/lib/theme"
@@ -206,7 +206,6 @@ function PlaylistContent({
if (!playlistId) return false if (!playlistId) return false
try { try {
await removeSongs({ playlistId, songIds: [songId] }) await removeSongs({ playlistId, songIds: [songId] })
showSuccess("Removed from playlist")
return true return true
} catch (error) { } catch (error) {
showError( showError(
@@ -233,10 +232,8 @@ function PlaylistContent({
try { try {
if (isSubscribed) { if (isSubscribed) {
await unsubscribe({ playlistId }) await unsubscribe({ playlistId })
showSuccess("Unsubscribed")
} else { } else {
await subscribe({ playlistId }) await subscribe({ playlistId })
showSuccess("Subscribed")
} }
} catch (error) { } catch (error) {
showError( showError(
@@ -250,7 +247,6 @@ function PlaylistContent({
if (!playlistId) return if (!playlistId) return
try { try {
await deletePlaylist({ playlistId }) await deletePlaylist({ playlistId })
showSuccess("Playlist deleted")
router.back() router.back()
} catch (error) { } catch (error) {
showError( showError(
+8 -19
View File
@@ -22,7 +22,7 @@ import { initialsFromName } from "@/lib/format"
import { useCachedQuery } from "@/hooks/use-cached-query" import { useCachedQuery } from "@/hooks/use-cached-query"
import { clearLocalData, signOutToSignIn } from "@/lib/session" import { clearLocalData, signOutToSignIn } from "@/lib/session"
import { radius, spacing, useThemeColors } from "@/lib/theme" import { radius, spacing, useThemeColors } from "@/lib/theme"
import { showError, showSuccess } from "@/lib/toast" import { showError } from "@/lib/toast"
import type { PlaybackQuality } from "@/lib/urls" import type { PlaybackQuality } from "@/lib/urls"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
import type { Id } from "@otunes/convex/_generated/dataModel" import type { Id } from "@otunes/convex/_generated/dataModel"
@@ -179,7 +179,6 @@ function ProfileSection({ user }: { user: CurrentUser }) {
await updateImage({ await updateImage({
image: `data:${mime};base64,${result.assets[0].base64}`, image: `data:${mime};base64,${result.assets[0].base64}`,
}) })
showSuccess("Profile photo updated")
} catch (error) { } catch (error) {
showError( showError(
error instanceof Error ? error.message : "Failed to update photo" error instanceof Error ? error.message : "Failed to update photo"
@@ -190,7 +189,6 @@ function ProfileSection({ user }: { user: CurrentUser }) {
async function removeImage() { async function removeImage() {
try { try {
await updateImage({ image: null }) await updateImage({ image: null })
showSuccess("Profile photo removed")
} catch (error) { } catch (error) {
showError( showError(
error instanceof Error ? error.message : "Failed to remove photo" error instanceof Error ? error.message : "Failed to remove photo"
@@ -209,7 +207,6 @@ function ProfileSection({ user }: { user: CurrentUser }) {
await updatePassword({ newPassword }) await updatePassword({ newPassword })
setNewPassword("") setNewPassword("")
setConfirmPassword("") setConfirmPassword("")
showSuccess("Password updated")
} catch (error) { } catch (error) {
showError( showError(
error instanceof Error ? error.message : "Failed to update password" error instanceof Error ? error.message : "Failed to update password"
@@ -258,9 +255,8 @@ function ProfileSection({ user }: { user: CurrentUser }) {
variant="secondary" variant="secondary"
disabled={name.trim() === user.name} disabled={name.trim() === user.name}
onPress={() => onPress={() =>
void updateName({ name: name.trim() }).then( void updateName({ name: name.trim() }).catch((error: Error) =>
() => showSuccess("Name updated"), showError(error.message)
(error: Error) => showError(error.message)
) )
} }
/> />
@@ -279,9 +275,8 @@ function ProfileSection({ user }: { user: CurrentUser }) {
variant="secondary" variant="secondary"
disabled={email.trim() === user.email} disabled={email.trim() === user.email}
onPress={() => onPress={() =>
void updateEmail({ email: email.trim() }).then( void updateEmail({ email: email.trim() }).catch((error: Error) =>
() => showSuccess("Email updated"), showError(error.message)
(error: Error) => showError(error.message)
) )
} }
/> />
@@ -407,7 +402,6 @@ function LibrarySection() {
setUpdating(true) setUpdating(true)
try { try {
await updateLibrary({}) await updateLibrary({})
showSuccess("Library updated")
} catch (error) { } catch (error) {
showError( showError(
error instanceof Error error instanceof Error
@@ -427,8 +421,7 @@ function LibrarySection() {
onPress={async () => { onPress={async () => {
setCleaningHls(true) setCleaningHls(true)
try { try {
const result = await cleanupHlsStreams({}) await cleanupHlsStreams({})
showSuccess(`Removed ${result.removed} idle HLS streams`)
} catch (error) { } catch (error) {
showError( showError(
error instanceof Error error instanceof Error
@@ -529,10 +522,7 @@ function UsersSection({
void setAdmin({ void setAdmin({
userId: user._id, userId: user._id,
isAdmin: !user.isAdmin, isAdmin: !user.isAdmin,
}).then( }).catch((error: Error) => showError(error.message))
() => showSuccess("Updated permissions"),
(error: Error) => showError(error.message)
)
} }
style={styles.userActionButton} style={styles.userActionButton}
/> />
@@ -540,8 +530,7 @@ function UsersSection({
title="Delete" title="Delete"
variant="destructive" variant="destructive"
onPress={() => onPress={() =>
void deleteUserMutation({ userId: user._id }).then( void deleteUserMutation({ userId: user._id }).catch(
() => showSuccess("User deleted"),
(error: Error) => showError(error.message) (error: Error) => showError(error.message)
) )
} }
+3 -18
View File
@@ -25,8 +25,8 @@ import { fetchCachedQuery } from "@otunes/convex/client/cached-query"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
import type { OwnedPlaylistForAdd } from "@otunes/convex/types" import type { OwnedPlaylistForAdd } from "@otunes/convex/types"
import type { Id } from "@otunes/convex/_generated/dataModel" import type { Id } from "@otunes/convex/_generated/dataModel"
import { showError, showSuccess } from "@/lib/toast"
import { useAppNavigation } from "@/lib/app-navigation" import { useAppNavigation } from "@/lib/app-navigation"
import { showError } from "@/lib/toast"
import { useThemeColors } from "@/lib/theme" import { useThemeColors } from "@/lib/theme"
type AddToPlaylistContextValue = { type AddToPlaylistContextValue = {
@@ -169,27 +169,17 @@ export function AddToPlaylistProvider({ children }: { children: ReactNode }) {
}, []) }, [])
const handleAddToPlaylist = useCallback( const handleAddToPlaylist = useCallback(
async ( async (playlistId: Id<"playlists">, existing: Id<"songs">[]) => {
playlistId: Id<"playlists">,
title: string,
existing: Id<"songs">[]
) => {
if (addingToPlaylistId) return if (addingToPlaylistId) return
const existingSet = new Set(existing) const existingSet = new Set(existing)
const toAdd = pendingSongIds.filter((id) => !existingSet.has(id)) const toAdd = pendingSongIds.filter((id) => !existingSet.has(id))
if (toAdd.length === 0) { if (toAdd.length === 0) {
showSuccess(`All selected songs are already in ${title}`)
closeAddToPlaylist() closeAddToPlaylist()
return return
} }
setAddingToPlaylistId(playlistId) setAddingToPlaylistId(playlistId)
try { try {
await addSongs({ playlistId, songIds: toAdd }) await addSongs({ playlistId, songIds: toAdd })
showSuccess(
toAdd.length > 1
? `Added ${toAdd.length} songs to ${title}`
: `Added to ${title}`
)
closeAddToPlaylist() closeAddToPlaylist()
} catch (error) { } catch (error) {
showError( showError(
@@ -211,7 +201,6 @@ export function AddToPlaylistProvider({ children }: { children: ReactNode }) {
name, name,
songIds: pendingSongIds, songIds: pendingSongIds,
}) })
showSuccess("Playlist created")
setCreateOpen(false) setCreateOpen(false)
closeAddToPlaylist() closeAddToPlaylist()
push(`/playlist/${playlistId}`) push(`/playlist/${playlistId}`)
@@ -281,11 +270,7 @@ export function AddToPlaylistProvider({ children }: { children: ReactNode }) {
style={styles.row} style={styles.row}
disabled={addingToPlaylistId !== null} disabled={addingToPlaylistId !== null}
onPress={() => onPress={() =>
void handleAddToPlaylist( void handleAddToPlaylist(playlist.id, playlist.songIds)
playlist.id,
playlist.title,
playlist.songIds
)
} }
> >
<Text style={{ color: colors.foreground }}> <Text style={{ color: colors.foreground }}>
+1 -12
View File
@@ -13,7 +13,7 @@ import {
import { useCachedQuery } from "@/hooks/use-cached-query" import { useCachedQuery } from "@/hooks/use-cached-query"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
import type { Id } from "@otunes/convex/_generated/dataModel" import type { Id } from "@otunes/convex/_generated/dataModel"
import { showError, showSuccess } from "@/lib/toast" import { showError } from "@/lib/toast"
/** /**
* `useMutation(...).withOptimisticUpdate(...)` with a stable identity. The * `useMutation(...).withOptimisticUpdate(...)` with a stable identity. The
@@ -178,10 +178,8 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
try { try {
if (idsRef.current.songIds.has(songId)) { if (idsRef.current.songIds.has(songId)) {
await unfavoriteSong({ songId }) await unfavoriteSong({ songId })
showSuccess("Removed from favorites")
} else { } else {
await favoriteSong({ songId }) await favoriteSong({ songId })
showSuccess("Added to favorites")
} }
} catch (error) { } catch (error) {
showError( showError(
@@ -197,10 +195,8 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
try { try {
if (idsRef.current.albumIds.has(albumId)) { if (idsRef.current.albumIds.has(albumId)) {
await unfavoriteAlbum({ albumId }) await unfavoriteAlbum({ albumId })
showSuccess("Removed from favorites")
} else { } else {
await favoriteAlbum({ albumId }) await favoriteAlbum({ albumId })
showSuccess("Added to favorites")
} }
} catch (error) { } catch (error) {
showError( showError(
@@ -216,10 +212,8 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
try { try {
if (idsRef.current.artistIds.has(artistId)) { if (idsRef.current.artistIds.has(artistId)) {
await unfavoriteArtist({ artistId }) await unfavoriteArtist({ artistId })
showSuccess("Removed from favorites")
} else { } else {
await favoriteArtist({ artistId }) await favoriteArtist({ artistId })
showSuccess("Added to favorites")
} }
} catch (error) { } catch (error) {
showError( showError(
@@ -236,11 +230,6 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
if (unique.length === 0) return if (unique.length === 0) return
try { try {
await favoriteSongsMutation({ songIds: unique }) await favoriteSongsMutation({ songIds: unique })
showSuccess(
unique.length > 1
? `Favorited ${unique.length} songs`
: "Added to favorites"
)
} catch (error) { } catch (error) {
showError( showError(
error instanceof Error ? error.message : "Failed to update favorites" error instanceof Error ? error.message : "Failed to update favorites"
+1 -3
View File
@@ -7,7 +7,7 @@ import { useCacheScope } from "@/contexts/persistent-cache"
import { useFavorites } from "@/contexts/favorites" import { useFavorites } from "@/contexts/favorites"
import { usePlaybackActions } from "@/contexts/playback" import { usePlaybackActions } from "@/contexts/playback"
import { useAppNavigation } from "@/lib/app-navigation" import { useAppNavigation } from "@/lib/app-navigation"
import { showError, showSuccess } from "@/lib/toast" import { showError } from "@/lib/toast"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
import { fetchCachedQuery } from "@otunes/convex/client/cached-query" import { fetchCachedQuery } from "@otunes/convex/client/cached-query"
import type { Id } from "@otunes/convex/_generated/dataModel" import type { Id } from "@otunes/convex/_generated/dataModel"
@@ -55,11 +55,9 @@ export function useMediaMenuActions() {
switch (action) { switch (action) {
case "play-next": case "play-next":
await addToQueueNext(songIds) await addToQueueNext(songIds)
showSuccess("Queued to play next")
break break
case "play-last": case "play-last":
await addToQueueLast(songIds) await addToQueueLast(songIds)
showSuccess("Queued to play last")
break break
case "shuffle": case "shuffle":
await playShuffled(songIds) await playShuffled(songIds)
-8
View File
@@ -1,13 +1,5 @@
import { toast } from "sonner-native" import { toast } from "sonner-native"
export function showToast(message: string) {
toast(message)
}
export function showError(message: string) { export function showError(message: string) {
toast.error(message) toast.error(message)
} }
export function showSuccess(message: string) {
toast.success(message)
}