-
Notifications
You must be signed in to change notification settings - Fork 197
/
SidebarLeft.vue
311 lines (295 loc) · 7.16 KB
/
SidebarLeft.vue
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<template>
<aside
@mouseover="
sidebar.collapsed = false;
setContentScrollable();
"
@mouseleave="
sidebar.collapsed = true;
setContentScrollable();
"
class="absolute z-10 flex-col hidden h-full transition-all duration-500 border-r bg-light-distinct dark:bg-dark-distinct md:flex border-light-section-div dark:border-dark-section-div elem-shadow-sm"
:class="{
'w-56': !sidebar.collapsed || sidebar.collapsedSwitch == false,
'w-16': sidebar.collapsed && sidebar.collapsedSwitch == true,
}"
>
<SidebarLeftHeader @toggle-pressed="setContentScrollable()" />
<div
ref="content"
class="h-full overflow-x-hidden"
:class="{
'-mr-[0.55rem]': contentScrollable,
}"
>
<SearchBar class="mt-1" location="sidebar" />
<SidebarLeftMainSectionSelectors class="mt-2" />
<SidebarLeftIndex
v-if="
sidebarType === SidebarType.ORGANIZATION_PAGE ||
sidebarType === SidebarType.EVENT_PAGE
"
class="my-3"
:name="placeholderName"
:sidebarType="sidebarType"
:logoUrl="placeholderLogo"
/>
<SidebarLeftFilters
v-else
:class="{
'mx-3 py-4': !sidebar.collapsed || sidebar.collapsedSwitch == false,
'mx-2 py-3': sidebar.collapsed && sidebar.collapsedSwitch == true,
}"
:filters="getFiltersByPageType"
/>
</div>
<SidebarLeftFooter />
</aside>
</template>
<script setup lang="ts">
import { SidebarType } from "~/types/sidebar-type";
defineProps<{
name?: string;
}>();
const sidebar = useSidebar();
const route = useRoute();
const { locale } = useI18n();
function currentRoutePathIncludes(path: string): boolean {
const { locale } = useI18n();
return route.path.includes(locale.value + path);
}
function isCurrentRoutePathSubpageOf(path: string) {
return (
route.path.length >
(route.path.split(locale.value + path, 1) + locale.value + path).length +
1 &&
route.path.split(locale.value + path).pop() !== "search" &&
route.path.split(locale.value + path).pop() !== "search/"
);
}
const pathToSidebarTypeMap = [
{ path: "/search", type: SidebarType.SEARCH },
{ path: "/home", type: SidebarType.HOME },
{
path: "/organizations",
type: isCurrentRoutePathSubpageOf("/organizations/")
? SidebarType.ORGANIZATION_PAGE
: SidebarType.FILTER_ORGANIZATIONS,
},
{
path: "/events",
type: isCurrentRoutePathSubpageOf("/events/")
? SidebarType.EVENT_PAGE
: SidebarType.FILTER_EVENTS,
},
];
const sidebarType =
pathToSidebarTypeMap.find((item) => currentRoutePathIncludes(item.path))
?.type || SidebarType.MISC;
// TODO: Use real name of organization / event when available from backend.
const placeholderName = route.path.split("/").at(-2)?.replaceAll("-", " ");
const placeholderLogo = "/images/tech-from-below.svg";
const filters = {
daysAhead: {
sidebarType: [SidebarType.FILTER_EVENTS],
title: "Days ahead",
name: "daysAhead",
type: "radio",
style: "btn",
allowCustomValue: true,
items: [
{
label: "1",
value: "1",
},
{
label: "7",
value: "7",
},
{
label: "30",
value: "30",
},
],
},
eventType: {
sidebarType: [SidebarType.FILTER_EVENTS],
title: "Event type",
name: "eventType",
type: "checkbox",
style: "btn",
items: [
{
label: "Learn",
value: "learn",
customColor: "learn-blue",
},
{
label: "Action",
value: "action",
customColor: "action-red",
},
],
},
locationType: {
sidebarType: [SidebarType.FILTER_EVENTS],
title: "Location",
name: "locationType",
type: "checkbox",
style: "btn",
searchInput: true,
items: [
{
label: "In person",
value: "in-person",
},
{
label: "Online",
value: "online",
},
],
},
eventLocationSearch: {
sidebarType: [SidebarType.FILTER_EVENTS],
title: "",
name: "eventLocationSearch",
type: "search",
placeholder: "components.sidebar-left.location-search-placeholder",
},
locationSearch: {
sidebarType: [SidebarType.FILTER_ORGANIZATIONS, SidebarType.SEARCH],
title: "Location",
name: "locationSearch",
type: "search",
placeholder: "components.sidebar-left.location-search-placeholder",
},
organizationSearch: {
sidebarType: [SidebarType.FILTER_EVENTS],
title: "Organization",
name: "organizationSearch",
type: "search",
placeholder: "components.sidebar-left.orgs-search-placeholder",
},
topic: {
sidebarType: [
SidebarType.FILTER_EVENTS,
SidebarType.FILTER_ORGANIZATIONS,
SidebarType.FILTER_RESOURCES,
SidebarType.SEARCH,
],
title: "Topic",
type: "checkbox",
name: "topic",
style: "simple",
expandable: true,
items: [
{
label: "Environment",
value: "environment",
},
{
label: "Housing",
value: "housing",
},
{
label: "Refugees",
value: "refugees",
},
{
label: "LGBTQIA+",
value: "lgbtqia+",
},
{
label: "Racial Justice",
value: "racial justice",
},
{
label: "Women's Rights",
value: "women's rights",
},
{
label: "Children's Rights",
value: "children's rights",
},
{
label: "Elder Rights",
value: "elder rights",
},
{
label: "Animal Rights",
value: "animal rights",
},
{
label: "Labor Rights",
value: "labor rights",
},
{
label: "Education",
value: "education",
},
{
label: "Democracy",
value: "democracy",
},
{
label: "Health",
value: "health",
},
{
label: "Privacy",
value: "privacy",
},
{
label: "Peace",
value: "peace",
},
{
label: "Nutrition",
value: "nutrition",
},
{
label: "Accessibility",
value: "accessibility",
},
{
label: "Transparency",
value: "transparency",
},
{
label: "Expression",
value: "expression",
},
{
label: "Emergency Relief",
value: "emergency relief",
},
{
label: "Infrastructure",
value: "infrastructure",
},
],
},
};
const getFiltersByPageType = computed(() => {
for (const filter in filters) {
const f = filters[filter as keyof typeof filters];
if (!f.sidebarType.includes(sidebarType)) {
delete filters[filter as keyof typeof filters];
}
}
return filters;
});
const content = ref();
const contentScrollable = ref(false);
function setContentScrollable(): void {
contentScrollable.value =
content.value.scrollHeight > content.value.clientHeight ? true : false;
}
onMounted(() => {
window.addEventListener("resize", setContentScrollable);
setContentScrollable();
});
onUnmounted(() => {
window.removeEventListener("resize", setContentScrollable);
});
</script>