Skip to content

Commit

Permalink
Use a constant for defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
viown committed Oct 28, 2024
1 parent 37be617 commit acde068
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/apps/stable/features/playback/utils/mediaSegmentSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { UserSettings } from 'scripts/settings/userSettings';
import { MediaSegmentAction } from '../constants/mediaSegmentAction';

const PREFIX = 'segmentTypeAction';
const DEFAULT_ACTIONS: Partial<Record<MediaSegmentType, MediaSegmentAction>> = {
[MediaSegmentType.Intro]: MediaSegmentAction.AskToSkip,
[MediaSegmentType.Outro]: MediaSegmentAction.AskToSkip
};

export const getId = (type: MediaSegmentType) => `${PREFIX}__${type}`;

export function getMediaSegmentAction(userSettings: UserSettings, type: MediaSegmentType): MediaSegmentAction {
const action = userSettings.get(getId(type), false);
let defaultAction = MediaSegmentAction.None;
if (type === MediaSegmentType.Intro || type === MediaSegmentType.Outro) {
defaultAction = MediaSegmentAction.AskToSkip;
}
const defaultAction = DEFAULT_ACTIONS[type] || MediaSegmentAction.None;

return action ? action as MediaSegmentAction : defaultAction;
}

0 comments on commit acde068

Please sign in to comment.