1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Use a constant for defaults

This commit is contained in:
viown 2024-10-28 17:36:10 +03:00
parent 37be617523
commit acde0685b5

View file

@ -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;
}