mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-22 21:45:56 +03:00
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:
parent
64347b4dc5
commit
2442b2ceb4
86
common/filter-utilities.js
Normal file
86
common/filter-utilities.js
Normal 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];
|
||||
};
|
Loading…
Reference in New Issue
Block a user