-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to view friends' liked songs (#171)
* Remove genre requirement for hydrating tracks * Extend song view to support viewing friends' songs * Add ability to view friends' liked songs in feed view
- Loading branch information
Showing
6 changed files
with
158 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { getFeed } from '@/services/friends'; | ||
import { Genre, Playlist, Song } from '@/types'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const useFeed = () => { | ||
const [songs, setSongs] = useState<Array<Song & { username: string }>>([]); | ||
const [playlists, setPlaylists] = useState< | ||
Array<Playlist & { username: string }> | ||
>([]); | ||
const [genres, setGenres] = useState<Array<Genre & { username: string }>>([]); | ||
|
||
const fetchFeed = async () => { | ||
console.log('fetching feed'); | ||
let newSongs: Array<Song & { username: string }> = []; | ||
let newPlaylists: Array<Playlist & { username: string }> = []; | ||
let newGenres: Array<Genre & { username: string }> = []; | ||
|
||
const feed = await getFeed(); | ||
feed.forEach((element) => { | ||
newSongs = [ | ||
...newSongs, | ||
...element.likedSongs.map((song) => ({ | ||
...song, | ||
username: element.username, | ||
})), | ||
]; | ||
newPlaylists = [ | ||
...newPlaylists, | ||
...element.playlists.map((playlist) => ({ | ||
...playlist, | ||
username: element.username, | ||
})), | ||
]; | ||
newGenres = [ | ||
...newGenres, | ||
...element.preferences.map((preference) => ({ | ||
...preference, | ||
username: element.username, | ||
})), | ||
]; | ||
}); | ||
|
||
console.log(newSongs); | ||
console.log(newPlaylists); | ||
console.log(newGenres); | ||
|
||
setSongs(newSongs); | ||
setPlaylists(newPlaylists); | ||
setGenres(newGenres); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchFeed(); | ||
}, []); | ||
|
||
return { songs, playlists, genres, fetchFeed }; | ||
}; |
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