Skip to content

Commit

Permalink
feat(channels): add an option to remove channel videos on channel rem…
Browse files Browse the repository at this point in the history
…oval
  • Loading branch information
AXeL-dev committed Oct 15, 2022
1 parent 554e6eb commit 281e72b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/store/reducers/videos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { VideoCache, Video, VideoFlags, VideoFlag } from 'types';
import { VideoCache, Video, VideoFlags, VideoFlag, Channel } from 'types';

type VideoWithId = Pick<VideoCache, 'id'>;
type AddVideoPayload = Video | Omit<VideoCache, 'flags'>;
Expand Down Expand Up @@ -213,6 +213,10 @@ export const videosSlice = createSlice({
});
}
},
removeChannelVideos: (state, action: PayloadAction<Channel>) => {
const { id: channelId } = action.payload;
state.list = state.list.filter((video) => video.channelId !== channelId);
},
},
});

Expand All @@ -228,6 +232,7 @@ export const {
archiveVideosByFlag,
setVideosFlag,
saveVideos,
removeChannelVideos,
} = videosSlice.actions;

export default videosSlice.reducer;
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import React from 'react';
import React, { useState } from 'react';
import {
Box,
Button,
Checkbox,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
FormControlLabel,
FormGroup,
} from '@mui/material';
import { Channel } from 'types';
import ChannelPicture from '../ChannelPicture';

interface RemoveChannelDialogProps {
open: boolean;
channel: Channel;
onClose: (confirmed?: boolean) => void;
onClose: (confirmed?: boolean, shouldRemoveVideos?: boolean) => void;
}

export default function RemoveChannelDialog(props: RemoveChannelDialogProps) {
const { open, channel, onClose } = props;
const [shouldRemoveVideos, setShouldRemoveVideos] = useState(false);

const handleConfirm = () => {
onClose(true);
onClose(true, shouldRemoveVideos);
};

const handleClose = () => {
onClose(false);
};

const handleRemoveVideosToggle = () => {
setShouldRemoveVideos(!shouldRemoveVideos);
};

return (
<Dialog open={open} onClose={handleClose}>
<DialogContent>
Expand All @@ -47,6 +55,18 @@ export default function RemoveChannelDialog(props: RemoveChannelDialogProps) {
<DialogContentText>
Are you sure that you want to remove this channel?
</DialogContentText>
<FormGroup sx={{ pt: 1 }}>
<FormControlLabel
control={
<Checkbox
checked={shouldRemoveVideos}
size="small"
onClick={handleRemoveVideosToggle}
/>
}
label="Remove the channel videos as well?"
/>
</FormGroup>
</Box>
</Box>
</DialogContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAppDispatch } from 'store';
import { removeChannel, setChannelFilters } from 'store/reducers/channels';
import RemoveChannelDialog from './RemoveChannelDialog';
import ChannelFiltersDialog from './ChannelFiltersDialog';
import { removeChannelVideos } from 'store/reducers/videos';

interface ChannelDialogsProps {
channel: Channel;
Expand All @@ -20,9 +21,12 @@ function ChannelDialogs(props: ChannelDialogsProps) {
<RemoveChannelDialog
open={openedDialog === 'remove-channel'}
channel={channel}
onClose={(confirmed) => {
onClose={(confirmed, shouldRemoveVideos) => {
if (confirmed) {
dispatch(removeChannel(channel));
if (shouldRemoveVideos) {
dispatch(removeChannelVideos(channel));
}
}
onClose();
}}
Expand Down

0 comments on commit 281e72b

Please sign in to comment.