-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 5caf521.
- Loading branch information
Showing
10 changed files
with
287 additions
and
520 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,15 @@ | ||
import { type Ref, ref } from 'vue'; | ||
import { type Filter } from '@/types/filter/Filter.ts'; | ||
import { watchDebounced } from '@vueuse/core'; | ||
import { useRoute, useRouter } from 'vue-router'; | ||
|
||
export interface FilterState { | ||
filter: Ref<Filter>; | ||
onFilter: (callback: () => Promise<void>) => void; | ||
} | ||
|
||
export function useFilter(initial: Filter): FilterState { | ||
/* State */ | ||
const filter = ref<Filter>(initial); | ||
const { query } = useRoute(); | ||
const { push } = useRouter(); | ||
|
||
/** | ||
* On filter callback | ||
* | ||
* @param callback | ||
*/ | ||
function onFilter(callback: () => Promise<void>) { | ||
watchDebounced( | ||
filter, | ||
async () => { | ||
await push({ | ||
query: { | ||
...query, | ||
...filter.value | ||
}, | ||
}); | ||
|
||
await callback(); | ||
}, | ||
{ debounce: 500, immediate: true, deep: true }, | ||
); | ||
} | ||
|
||
return { | ||
filter, onFilter | ||
filter, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,10 @@ | ||
import { LocationQuery } from 'vue-router'; | ||
|
||
export type CourseFilter = { | ||
faculties: string[]; | ||
years: string[]; | ||
} & Filter; | ||
export const COURSE_FILTER = { | ||
search: '', | ||
faculties: [], | ||
years: [], | ||
}; | ||
|
||
export interface Filter { | ||
search: string; | ||
[key: string]: string|string[]; | ||
} | ||
|
||
/** | ||
* Get the course filters from the query. | ||
* | ||
* @param query | ||
*/ | ||
export function getCourseFilters(query: LocationQuery): CourseFilter { | ||
const filters: CourseFilter = { | ||
search: query.search?.toString() || '', | ||
faculties: [], | ||
years: [], | ||
}; | ||
|
||
if (query.faculties) { | ||
filters.faculties = getQueryList(query.faculties as string|string[]); | ||
} | ||
|
||
if (query.years) { | ||
filters.years = getQueryList(query.years as string|string[]); | ||
} | ||
|
||
return filters; | ||
} | ||
|
||
/** | ||
* Get the query list. | ||
* | ||
* @param query | ||
*/ | ||
function getQueryList(query: string | string[] | undefined): string[] { | ||
if (query === undefined) return []; | ||
|
||
if (Array.isArray(query)) { | ||
return query; | ||
} | ||
|
||
return [query?.toString()]; | ||
[key: string]: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.