feat(filter-utilities):

add relationship between filter views, types, and subviews. For now, we have two views, Initial and Browser. each has its own filters, and the browser view has subviews (saved, history…)

add filter handlers (will be passed to web workers
This commit is contained in:
Aminejv 2021-09-24 18:01:14 +01:00
parent 64347b4dc5
commit 2442b2ceb4

View File

@ -0,0 +1,86 @@
import {
isImageType,
isVideoType,
isAudioType,
isDocument,
isTwitterLink,
isYoutubeLink,
isTwitchLink,
isGithubLink,
isInstagramLink,
} from "~/common/validations";
export const FILTER_VIEWS_IDS = {
initial: "initial",
browser: "browser",
};
export const FILTER_SUBVIEWS_IDS = {
browser: { saved: "saved" },
};
export const FILTER_TYPES = {
[FILTER_VIEWS_IDS.initial]: {
filters: {
initial: "library",
library: "library",
images: "images",
videos: "videos",
audios: "audios",
documents: "documents",
},
},
[FILTER_VIEWS_IDS.browser]: {
filters: { all: "all", initial: "all" },
subviews: {
[FILTER_SUBVIEWS_IDS.browser.saved]: {
filters: {
initial: "all",
all: "all",
twitter: "twitter",
youtube: "youtube",
twitch: "twitch",
github: "github",
instagram: "instagram",
},
},
},
},
};
const FILTERING_HANDLERS = {
[FILTER_VIEWS_IDS.initial]: {
filters: {
library: (object) => object,
images: (object) => isImageType(object.data.type),
videos: (object) => isVideoType(object.data.type),
audios: (object) => isAudioType(object.data.type),
documents: (object) => isDocument(object.filename, object.data.type),
},
},
[FILTER_VIEWS_IDS.browser]: {
filters: { all: (object) => object.isLink },
subviews: {
[FILTER_SUBVIEWS_IDS.browser.saved]: {
filters: {
all: (object) => object.isLink,
twitter: isTwitterLink,
youtube: isYoutubeLink,
twitch: isTwitchLink,
github: isGithubLink,
instagram: isInstagramLink,
},
},
},
},
};
export const getViewData = (view) => {
return FILTER_TYPES[view];
};
export const getFilterHandler = ({ view, subview, type }) => {
const nextView = FILTERING_HANDLERS[view];
if (subview) return nextView.subviews[subview].filters[type];
return nextView.filters[type];
};