-
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.
Merge branch 'development' into role-management
- Loading branch information
Showing
10 changed files
with
514 additions
and
284 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,15 +1,43 @@ | ||
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>): void { | ||
watchDebounced( | ||
filter, | ||
async () => { | ||
await push({ | ||
query: { | ||
...query, | ||
...filter.value, | ||
}, | ||
}); | ||
|
||
await callback(); | ||
}, | ||
{ debounce: 500, immediate: true, deep: true }, | ||
); | ||
} | ||
|
||
return { | ||
filter, | ||
onFilter, | ||
}; | ||
} |
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,10 +1,49 @@ | ||
export const COURSE_FILTER = { | ||
search: '', | ||
faculties: [], | ||
years: [], | ||
}; | ||
import { type LocationQuery } from 'vue-router'; | ||
|
||
export type CourseFilter = { | ||
faculties: string[]; | ||
years: string[]; | ||
} & Filter; | ||
|
||
export interface Filter { | ||
search: string; | ||
[key: string]: any; | ||
[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 !== undefined) { | ||
filters.faculties = getQueryList(query.faculties as string | string[]); | ||
} | ||
|
||
if (query.years !== undefined) { | ||
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()]; | ||
} |
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.