@@ -11,29 +11,6 @@ import AppHeader from '../components/AppHeader.vue';
1111const route = useRoute ();
1212const { cases, industryOptions, fieldOfInterestOptions } = usePortfolio ();
1313
14- // const industryOptions = ref<string[]>([]);
15- // const fieldOfInterestOptions = ref<string[]>([]);
16- //
17- // const createOptions = (rawOptions: string[]): string[] =>
18- // Array.from(new Set(rawOptions)).sort();
19- //
20- // watchEffect(() => {
21- // if (cases.value?.length && cases.value?.length > 0) {
22- // const { industries, fieldsOfInterest } = cases.value.reduce<
23- // Pick<CaseItem, 'industries' | 'fieldsOfInterest'>
24- // >(
25- // (acc, item) => ({
26- // industries: [...acc.industries, ...item.industries],
27- // fieldsOfInterest: [...acc.fieldsOfInterest, ...item.fieldsOfInterest],
28- // }),
29- // { industries: [], fieldsOfInterest: [] }
30- // );
31- //
32- // industryOptions.value = createOptions(industries);
33- // fieldOfInterestOptions.value = createOptions(fieldsOfInterest);
34- // }
35- // });
36-
3714// TODO fix: setting initial filter values is broken when reloading the URL
3815const queryFilters = computed (() => {
3916 if (! route .query .filter ) {
@@ -56,20 +33,38 @@ const fieldsOfInterestFilter = ref<string[]>(
5633);
5734
5835const filteredCases = computed (() => {
59- const filters = [... industriesFilter .value , ... fieldsOfInterestFilter .value ];
60-
61- if (filters .length === 0 ) {
36+ if (
37+ industriesFilter .value .length === 0 &&
38+ fieldsOfInterestFilter .value .length === 0
39+ ) {
6240 return cases .value ;
6341 }
6442
65- return cases .value ?.reduce <CaseItem []>((acc , item ) => {
66- return [... item .industries , ... item .fieldsOfInterest ].some ((filter ) =>
67- filters .includes (filter )
68- )
69- ? [... acc , item ]
70- : acc ;
71- }, []);
43+ const industryCases = industriesFilter .value .length
44+ ? cases .value ?.reduce <CaseItem []>((acc , item ) => {
45+ return [... item .industries ].some ((filter ) =>
46+ industriesFilter .value .includes (filter )
47+ )
48+ ? [... acc , item ]
49+ : acc ;
50+ }, [])
51+ : cases .value ;
52+
53+ return fieldsOfInterestFilter .value .length
54+ ? industryCases ?.reduce <CaseItem []>((acc , item ) => {
55+ return [... item .fieldsOfInterest ].some ((filter ) =>
56+ fieldsOfInterestFilter .value .includes (filter )
57+ )
58+ ? [... acc , item ]
59+ : acc ;
60+ }, [])
61+ : industryCases ;
7262});
63+
64+ const resetFilters = () => {
65+ industriesFilter .value = [];
66+ fieldsOfInterestFilter .value = [];
67+ };
7368 </script >
7469
7570<template >
@@ -96,7 +91,18 @@ const filteredCases = computed(() => {
9691 />
9792 </div >
9893 </div >
99- <ul class =" case-list" >
94+ <p v-if =" !filteredCases?.length" >
95+ There are no cases for this filtering.
96+ <a
97+ class =" link"
98+ @click =" resetFilters"
99+ >Reset filters</a
100+ >
101+ </p >
102+ <ul
103+ v-else
104+ class =" case-list"
105+ >
100106 <li
101107 v-for =" item in filteredCases"
102108 class =" case-list__item"
0 commit comments