Skip to content

Commit

Permalink
Implement FF and rewind schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa committed Feb 29, 2024
1 parent 3d1e700 commit fb6e336
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions web2/src/components/channel_config/ChannelProgrammingConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ import Delete from '@mui/icons-material/Delete';
import { useRemoveDuplicates } from '../../hooks/programming_controls/useRemoveDuplicates.ts';
import { range } from 'lodash-es';
import { useRestrictHours } from '../../hooks/programming_controls/useRestrictHours.ts';
import { FastForward, FastRewind } from '@mui/icons-material';
import {
useFastForwardSchedule,
useRewindSchedule,
} from '../../hooks/programming_controls/useSlideSchedule.ts';

// dayjs.extend(duration);

Expand All @@ -71,6 +76,9 @@ export function ChannelProgrammingConfig() {
const removeDuplicatePrograms = useRemoveDuplicates();
const restrictHours = useRestrictHours();

const fastForward = useFastForwardSchedule();
const rewind = useRewindSchedule();

const startTime = channel ? dayjs(channel.startTime) : dayjs();
const endTime = startTime.add(channel?.duration ?? 0, 'milliseconds');

Expand Down Expand Up @@ -229,6 +237,24 @@ export function ChannelProgrammingConfig() {
Restrict Hours
</Button>
</Grid2>
<Grid2 xs={3}>
<Button
variant="contained"
onClick={() => fastForward(60 * 1000)}
startIcon={<FastForward />}
>
Fast Forward
</Button>
</Grid2>
<Grid2 xs={3}>
<Button
variant="contained"
onClick={() => rewind(60 * 1000)}
startIcon={<FastRewind />}
>
Rewind
</Button>
</Grid2>
</Grid2>
</AccordionDetails>
</Accordion>
Expand Down
23 changes: 23 additions & 0 deletions web2/src/hooks/programming_controls/useSlideSchedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { setChannelStartTime } from '../../store/channelEditor/actions.ts';
import useStore from '../../store/index.ts';
import { materializedProgramListSelector } from '../../store/selectors.ts';

const useSlide = () => {
const channel = useStore(({ channelEditor }) => channelEditor.currentEntity);
const programs = useStore(materializedProgramListSelector);
return (amount: number) => {
if (channel && amount !== 0 && programs.length > 0) {
setChannelStartTime(channel.startTime + amount);
}
};
};

export const useFastForwardSchedule = () => {
const slide = useSlide();
return (amount: number) => slide(amount < 0 ? amount : -amount);
};

export const useRewindSchedule = () => {
const slide = useSlide();
return (amount: number) => slide(Math.abs(amount));
};
7 changes: 7 additions & 0 deletions web2/src/store/channelEditor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export const setCurrentChannel = (
}
});

export const changeChannelStartTime = (newStartTime: number) =>
useStore.setState(({ channelEditor }) => {
if (channelEditor.currentEntity) {
channelEditor.currentEntity.startTime = newStartTime;
}
});

export const setCurrentChannelProgramming = (
programming: CondensedChannelProgramming,
) =>
Expand Down

0 comments on commit fb6e336

Please sign in to comment.