This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
filters.ts
104 lines (98 loc) · 2.77 KB
/
filters.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { kebab } from 'case'
import { ALL_MEDIA, AUDIO, IMAGE, VIDEO } from '~/constants/media'
import { ACTIVE_LICENSES } from '~/constants/license'
import { deepFreeze } from '~/utils/deep-freeze'
import type { SearchType } from '~/constants/media'
import type { FilterCategory, FilterItem } from '~/store/types'
/**
* List of filters available for each search type. The order of the keys
* is the same as in the filter checklist display (sidebar or modal).
*/
export const mediaFilterKeys = deepFreeze<Record<SearchType, FilterCategory[]>>(
{
[IMAGE]: [
'licenseTypes',
'licenses',
'imageCategories',
'imageExtensions',
'aspectRatios',
'sizes',
'imageProviders',
'searchBy',
'mature',
],
[AUDIO]: [
'licenseTypes',
'licenses',
'audioCategories',
'audioExtensions',
'durations',
'audioProviders',
'searchBy',
'mature',
],
[VIDEO]: [],
[ALL_MEDIA]: ['licenseTypes', 'licenses', 'searchBy', 'mature'],
}
)
/**
* A list of filters that are only used for the specific content type.
* This is used to clear filters from other content types when changing the content type.
*/
export const mediaUniqueFilterKeys = deepFreeze<
Record<SearchType, FilterCategory[]>
>({
all: [],
image: [
'imageCategories',
'imageExtensions',
'aspectRatios',
'sizes',
'imageProviders',
],
audio: ['audioCategories', 'audioExtensions', 'durations', 'audioProviders'],
video: [],
})
const filterCodesPerCategory = deepFreeze<Record<FilterCategory, string[]>>({
licenses: ACTIVE_LICENSES,
licenseTypes: ['commercial', 'modification'],
audioCategories: ['music', 'sound', 'podcast'],
imageCategories: ['photograph', 'illustration', 'digitized_artwork'],
audioExtensions: ['mp3', 'ogg', 'flac'],
imageExtensions: ['jpg', 'png', 'gif', 'svg'],
aspectRatios: ['tall', 'wide', 'square'],
durations: ['short', 'medium', 'long'],
sizes: ['small', 'medium', 'large'],
audioProviders: [],
imageProviders: [],
searchBy: ['creator'],
mature: ['mature'],
})
/**
* Converts the filterCodesPerCategory object into the format that's used by the filter store.
* Name is used as the i18n $t key.
* ```
* {
* "audioCategories": [
* {
* "code": "music",
* "name": "filters.audioCategories.music",
* "checked": false
* }, ...
* ],
* }
*```
*/
export const initFilters = () =>
Object.entries(filterCodesPerCategory).reduce(
(acc, [filterType, filters]) => ({
...acc,
[filterType]: filters.map((item) => ({
code: item,
name: `filters.${kebab(filterType)}.${item}`,
checked: false,
})),
}),
{} as Record<FilterCategory, FilterItem>
)
export const filterData = deepFreeze(initFilters())