Skip to content

Commit

Permalink
Show playlist panel after creating first playlist (#3044)
Browse files Browse the repository at this point in the history
* Show playlist panel after creating first playlist

Kind of awkward if you get stuck on the very first screen in the app x:

* fixes
  • Loading branch information
goto-bus-stop authored Sep 28, 2024
1 parent 7c4096e commit cb1f034
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/containers/AddToPlaylistMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function AddToPlaylistMenuContainer() {
if ('error' in result) {
throw result.error;
}
return result.payload;
return result.payload.playlist;
}, [dispatch]);
const onSelect = useCallback((playlist: Playlist) => {
if (isFavorite) {
Expand Down
15 changes: 12 additions & 3 deletions src/reducers/playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,18 @@ const createPlaylist = createAsyncThunk('playlists/create', async (name: string)
createdAt: string,
size: number,
},
meta: {
active: boolean,
},
}>(['/playlists', {
method: 'post',
data: { name },
}]);

return response.data satisfies Playlist;
const playlist = response.data satisfies Playlist;
const { active } = response.meta;

return { playlist, active };
});

const deletePlaylist = createAsyncThunk('playlists/delete', async (playlistID: string) => {
Expand Down Expand Up @@ -584,11 +590,14 @@ const slice = createSlice({
.addCase(createPlaylist.fulfilled, (state, action) => {
delete state.playlists[action.meta.requestId];

const playlist = action.payload;
const { playlist, active } = action.payload;
state.playlists[playlist._id] = playlist;
if (state.selectedPlaylistID === action.meta.requestId) {
if (state.selectedPlaylistID === action.meta.requestId || active) {
state.selectedPlaylistID = playlist._id;
}
if (active) {
state.activePlaylistID = playlist._id;
}
})
.addCase(renamePlaylist.fulfilled, (state, action) => {
const playlist = state.playlists[action.payload._id];
Expand Down
3 changes: 2 additions & 1 deletion src/sources/youtube/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const importPlaylist = createAsyncThunk('youtube/importPlaylist', async (
data: { id: sourceID, name },
}]);

api.dispatch(createPlaylist.fulfilled(playlist, api.requestId, name));
// TODO: `active: false` is definitely a lie here!
api.dispatch(createPlaylist.fulfilled({ playlist, active: false }, api.requestId, name));
});

const slice = createSlice({
Expand Down

0 comments on commit cb1f034

Please sign in to comment.