-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fullstack) : get track from playlist.
- Loading branch information
1 parent
e6f02cd
commit da62dfb
Showing
8 changed files
with
185 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import FontAwesome from "@expo/vector-icons/FontAwesome"; | ||
import { JSONTrack, Playlist } from "commons/backend-types"; | ||
import { router } from "expo-router"; | ||
import { useEffect, useState } from "react"; | ||
import { FlatList, Pressable, StyleSheet } from "react-native"; | ||
|
||
import { useWebSocket } from "./_layout"; | ||
import { Text, View } from "../../../../components/Tamed"; | ||
import SearchedTrackItem from "../../../../components/room/SearchedTrackItem"; | ||
import { useSupabaseUserHook } from "../../../../lib/useSupabaseUser"; | ||
|
||
export default function Library() { | ||
const [playlists, setPlaylists] = useState<Playlist[]>([]); | ||
|
||
const user = useSupabaseUserHook(); | ||
const socket = useWebSocket(); | ||
useEffect(() => { | ||
console.log(user); | ||
const spotifyUser = user?.identities?.filter( | ||
(ptf) => ptf.provider === "spotify" | ||
)[0]; | ||
socket?.emit("user:playlists", spotifyUser?.id, setPlaylists); | ||
}, [socket, user]); | ||
|
||
return ( | ||
<FlatList | ||
data={playlists} | ||
renderItem={({ item }) => <Item playlist={item} />} | ||
/> | ||
); | ||
} | ||
|
||
function Item(props: { playlist: Playlist }) { | ||
const playlist = props.playlist; | ||
|
||
const [showTracks, setShowTracks] = useState(false); | ||
const [tracks, setTracks] = useState<JSONTrack[]>([]); | ||
|
||
const socket = useWebSocket(); | ||
|
||
useEffect(() => { | ||
if (showTracks) | ||
socket?.emit("user:playlistTrack", playlist.playlistId, setTracks); | ||
}, [socket, showTracks]); | ||
|
||
return ( | ||
<View> | ||
<Pressable | ||
onPress={() => setShowTracks(!showTracks)} | ||
style={styles.playlistHeader} | ||
> | ||
<FontAwesome | ||
name={`arrow-${showTracks ? "down" : "up"}`} | ||
style={styles.playlistHeaderInner} | ||
/> | ||
<Text style={styles.playlistHeaderInner}>{playlist.name}</Text> | ||
</Pressable> | ||
{showTracks && ( | ||
<FlatList | ||
data={tracks} | ||
renderItem={({ item }) => { | ||
return ( | ||
<View style={{ paddingLeft: 50 }}> | ||
<SearchedTrackItem | ||
track={item} | ||
handleAddMusic={() => { | ||
socket?.emit("queue:add", new URL(item.url).toString()); | ||
|
||
router.back(); | ||
router.back(); | ||
}} | ||
/> | ||
</View> | ||
); | ||
}} | ||
/> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
playlistHeader: { | ||
flexDirection: "row", | ||
alignItems: "center", | ||
paddingVertical: 15, | ||
}, | ||
playlistHeaderInner: { | ||
fontFamily: "Outfit-Bold", | ||
paddingLeft: 10, | ||
fontSize: 15, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { FlatList, Pressable } from "react-native"; | ||
|
||
import { useWebSocket } from "./_layout"; | ||
import { Text } from "../../../../components/Tamed"; | ||
|
||
export default function Playlist(props: { playlistId: string }) { | ||
const [tracks, setTracks] = useState([]); | ||
|
||
const socket = useWebSocket(); | ||
useEffect(() => { | ||
socket?.emit("user:playlists", props.playlistId, setTracks); | ||
}, [socket]); | ||
|
||
return ( | ||
<FlatList | ||
data={tracks} | ||
renderItem={({ item }) => ( | ||
<Pressable onPress={() => alert(item)}> | ||
<Text>{item}</Text> | ||
</Pressable> | ||
)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters