Skip to content

Commit

Permalink
refactor: rename viewed flag to seen
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Aug 31, 2022
1 parent 182b811 commit d081523
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/store/reducers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const defaultSettings = {
autoPlayVideos: true,
recentVideosSeniority: VideosSeniority.OneDay,
recentViewFilters: {
viewed: true,
seen: true,
watchLater: true,
ignored: false,
others: true,
},
watchLaterViewFilters: {
viewed: true,
seen: true,
archived: true,
others: true,
},
Expand Down
6 changes: 3 additions & 3 deletions src/store/reducers/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ export const videosSlice = createSlice({
},
clearWatchLaterList: (
state,
action: PayloadAction<{ viewedOnly: boolean } | undefined>,
action: PayloadAction<{ seenOnly: boolean } | undefined>,
) => {
const { viewedOnly } = action.payload || {};
const { seenOnly } = action.payload || {};
state.list = state.list.map((video) =>
video.flags.toWatchLater
? {
...video,
flags: {
...video.flags,
toWatchLater: viewedOnly ? !video.flags.viewed : false,
toWatchLater: seenOnly ? !video.flags.seen : false,
},
}
: video,
Expand Down
10 changes: 5 additions & 5 deletions src/store/selectors/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export const selectRecentOnlyVideos = (channel?: Channel) =>
),
);

export const selectViewedVideos = (channel?: Channel) =>
export const selectSeenVideos = (channel?: Channel) =>
createSelector(selectVideos, (videos) =>
videos.filter(
({ flags, channelId }) =>
flags.viewed && (!channel || channel.id === channelId),
flags.seen && (!channel || channel.id === channelId),
),
);

Expand Down Expand Up @@ -126,15 +126,15 @@ export const selectWatchLaterVideosCount = createSelector(
},
);

export const selectViewedWatchLaterVideosCount = createSelector(
export const selectSeenWatchLaterVideosCount = createSelector(
selectVideos,
selectActiveChannels,
(videos, activeChannels) => {
const activeChannelsIds = activeChannels.map(({ id }) => id);
return videos.filter(
({ flags, channelId }) =>
flags.toWatchLater &&
flags.viewed &&
flags.seen &&
activeChannelsIds.includes(channelId),
).length;
},
Expand All @@ -144,7 +144,7 @@ export const selectVideoMeta = (video: Video) =>
createSelector(selectVideos, (videos) => {
const { flags } = videos.find(({ id }) => id === video.id) || {};
return {
isViewed: flags?.viewed || false,
isSeen: flags?.seen || false,
isToWatchLater: flags?.toWatchLater || false,
isArchived: flags?.archived || false,
isIgnored: flags?.ignored || false,
Expand Down
2 changes: 1 addition & 1 deletion src/store/utils/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const removeOutdatedVideos = (videos: VideoCache[], settings: Settings) => {
log('Removing outdated videos.');
return videos.filter(
({ flags, publishedAt }) =>
flags.viewed ||
flags.seen ||
flags.toWatchLater ||
((flags.recent || flags.ignored) &&
elapsedDays(publishedAt) <= settings.recentVideosSeniority) ||
Expand Down
4 changes: 2 additions & 2 deletions src/types/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export interface HomeDisplayOptions {
}

export interface RecentViewFilters {
viewed: boolean;
seen: boolean;
watchLater: boolean;
ignored: boolean;
others: boolean;
}

export interface WatchLaterViewFilters {
viewed: boolean;
seen: boolean;
archived: boolean;
others: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Video {
}

export type VideoFlags = Partial<{
viewed: boolean;
seen: boolean;
toWatchLater: boolean;
notified: boolean;
archived: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { Video } from 'types';
import { useAppSelector } from 'store';
import { selectVideoMeta } from 'store/selectors/videos';

interface ViewedBadgeProps {
interface SeenBadgeProps {
video: Video;
}

function ViewedBadge(props: ViewedBadgeProps) {
function SeenBadge(props: SeenBadgeProps) {
const { video } = props;
const { isViewed } = useAppSelector(selectVideoMeta(video));
const { isSeen } = useAppSelector(selectVideoMeta(video));

return isViewed ? (
<Tooltip title="Viewed" aria-label="viewed">
return isSeen ? (
<Tooltip title="Seen" aria-label="seen">
<Box
sx={{
display: 'flex',
Expand All @@ -33,4 +33,4 @@ function ViewedBadge(props: ViewedBadgeProps) {
) : null;
}

export default ViewedBadge;
export default SeenBadge;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Box } from '@mui/material';
import { HomeView, Video } from 'types';
import ViewedBadge from './ViewedBadge';
import SeenBadge from './SeenBadge';
import ArchivedBadge from './ArchivedBadge';
import IgnoredBadge from './IgnoredBadge';

Expand All @@ -24,7 +24,7 @@ function VideoBadges(props: VideoBadgesProps) {
gap: '4px',
}}
>
<ViewedBadge video={video} />
<SeenBadge video={video} />
<IgnoredBadge video={video} view={view} />
<ArchivedBadge video={video} view={view} />
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { useAppDispatch, useAppSelector } from 'store';
import { addVideoFlag, removeVideoFlag } from 'store/reducers/videos';
import { selectVideoMeta } from 'store/selectors/videos';

interface ViewedActionProps {
interface SeenActionProps {
video: Video;
}

function ViewedAction(props: ViewedActionProps) {
function SeenAction(props: SeenActionProps) {
const { video } = props;
const { isViewed } = useAppSelector(selectVideoMeta(video));
const { isSeen } = useAppSelector(selectVideoMeta(video));
const dispatch = useAppDispatch();

return !isViewed ? (
<Tooltip title="Mark as viewed" aria-label="mark-as-viewed">
return !isSeen ? (
<Tooltip title="Mark as seen" aria-label="mark-as-seen">
<IconButton
sx={{
color: '#eee',
Expand All @@ -33,7 +33,7 @@ function ViewedAction(props: ViewedActionProps) {
dispatch(
addVideoFlag({
video,
flag: 'viewed',
flag: 'seen',
}),
);
}}
Expand All @@ -42,7 +42,7 @@ function ViewedAction(props: ViewedActionProps) {
</IconButton>
</Tooltip>
) : (
<Tooltip title="Mark as unviewed" aria-label="mark-as-unviewed">
<Tooltip title="Mark as unseen" aria-label="mark-as-unseen">
<IconButton
sx={{
display: 'flex',
Expand All @@ -59,7 +59,7 @@ function ViewedAction(props: ViewedActionProps) {
dispatch(
removeVideoFlag({
video,
flag: 'viewed',
flag: 'seen',
}),
);
}}
Expand All @@ -70,4 +70,4 @@ function ViewedAction(props: ViewedActionProps) {
);
}

export default ViewedAction;
export default SeenAction;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Box } from '@mui/material';
import { HomeView, Video } from 'types';
import WatchLaterAction from './WatchLaterAction';
import ViewedAction from './ViewedAction';
import SeenAction from './SeenAction';
import ArchiveAction from './ArchiveAction';
import IgnoreAction from './IgnoreAction';

Expand All @@ -26,7 +26,7 @@ function VideoTopActions(props: VideoTopActionsProps) {
}}
>
<IgnoreAction video={video} view={view} />
<ViewedAction video={video} />
<SeenAction video={video} />
<ArchiveAction video={video} view={view} />
<WatchLaterAction video={video} view={view} />
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function VideoCard(props: VideoCardProps) {
dispatch(
addVideoFlag({
video,
flag: 'viewed',
flag: 'seen',
}),
);
}}
Expand All @@ -122,7 +122,7 @@ function VideoCard(props: VideoCardProps) {
dispatch(
addVideoFlag({
video,
flag: 'viewed',
flag: 'seen',
}),
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const options: {
value: keyof Filters;
}[] = [
{
label: 'Viewed',
value: 'viewed',
label: 'Seen',
value: 'seen',
},
{
label: 'Watch later',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ function RecentViewOptions(props: RecentViewOptionsProps) {
setAnchorEl(null);
};

const handleMarkVideosAsViewed = () => {
const handleMarkVideosAsSeen = () => {
setConfirmationDialogProps({
open: true,
title: `Mark unflagged videos as viewed (${videos.length})`,
text: 'Are you sure that you want to mark all the unflagged videos as viewed?',
title: `Mark unflagged videos as seen (${videos.length})`,
text: 'Are you sure that you want to mark all the unflagged videos as seen?',
onClose: (confirmed) => {
if (confirmed) {
dispatch(
setVideosFlag({
videos,
flag: 'viewed',
flag: 'seen',
}),
);
}
Expand Down Expand Up @@ -111,11 +111,11 @@ function RecentViewOptions(props: RecentViewOptionsProps) {
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
>
<MenuItem onClick={handleMarkVideosAsViewed}>
<MenuItem onClick={handleMarkVideosAsSeen}>
<ListItemIcon>
<VisibilityIcon />
</ListItemIcon>
<ListItemText>Mark unflagged videos as viewed</ListItemText>
<ListItemText>Mark unflagged videos as seen</ListItemText>
</MenuItem>
<MenuItem onClick={handleMarkVideosAsIgnored}>
<ListItemIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const options: {
value: keyof Filters;
}[] = [
{
label: 'Viewed',
value: 'viewed',
label: 'Seen',
value: 'seen',
},
{
label: 'Archived',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from 'store/reducers/videos';
import {
selectWatchLaterVideos,
selectViewedWatchLaterVideosCount,
selectSeenWatchLaterVideosCount,
} from 'store/selectors/videos';
import { Nullable } from 'types';
import { downloadFile } from 'helpers/file';
Expand All @@ -34,7 +34,7 @@ interface WatchLaterViewOptionsProps {
function WatchLaterViewOptions(props: WatchLaterViewOptionsProps) {
const { videosCount } = props;
const watchLaterVideos = useAppSelector(selectWatchLaterVideos());
const viewedCount = useAppSelector(selectViewedWatchLaterVideosCount);
const seenCount = useAppSelector(selectSeenWatchLaterVideosCount);
const dispatch = useAppDispatch();
const [anchorEl, setAnchorEl] = useState<Nullable<HTMLElement>>(null);
const open = Boolean(anchorEl);
Expand Down Expand Up @@ -90,14 +90,14 @@ function WatchLaterViewOptions(props: WatchLaterViewOptionsProps) {
handleClose();
};

const handleRemoveViewed = () => {
const handleRemoveSeen = () => {
setConfirmationDialogProps({
open: true,
title: `Remove viewed videos (${viewedCount})`,
text: 'Are you sure that you want to remove all viewed videos from the watch later list?',
title: `Remove seen videos (${seenCount})`,
text: 'Are you sure that you want to remove all seen videos from the watch later list?',
onClose: (confirmed) => {
if (confirmed) {
dispatch(clearWatchLaterList({ viewedOnly: true }));
dispatch(clearWatchLaterList({ seenOnly: true }));
}
setConfirmationDialogProps((state) => ({
...state,
Expand Down Expand Up @@ -155,12 +155,12 @@ function WatchLaterViewOptions(props: WatchLaterViewOptionsProps) {
</ListItemIcon>
<ListItemText>Remove all videos</ListItemText>
</MenuItem>
{viewedCount > 0 ? (
<MenuItem onClick={handleRemoveViewed}>
{seenCount > 0 ? (
<MenuItem onClick={handleRemoveSeen}>
<ListItemIcon>
<VisibilityOffIcon />
</ListItemIcon>
<ListItemText>Remove viewed videos</ListItemText>
<ListItemText>Remove seen videos</ListItemText>
</MenuItem>
) : null}
<MenuItem onClick={handleExport}>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/webext/Background/ChannelChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function ChannelChecker(props: ChannelCheckerProps) {
const checkedVideosIds = cachedVideos
.filter(
({ flags }) =>
flags.viewed ||
flags.seen ||
flags.toWatchLater ||
flags.notified ||
flags.recent,
Expand Down
Loading

0 comments on commit d081523

Please sign in to comment.