-
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.
- Loading branch information
Showing
16 changed files
with
199 additions
and
84 deletions.
There are no files selected for viewing
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { type Ref, ref } from 'vue'; | ||
import { type Filter } from '@/types/filter/Filter.ts'; | ||
|
||
export interface FilterState { | ||
filter: Ref<Filter>; | ||
} | ||
|
||
export function useFilter(initial: Filter): FilterState { | ||
/* State */ | ||
const filter = ref<Filter>(initial); | ||
|
||
return { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { computed, type Ref, ref, watch } from 'vue'; | ||
import { type LocationQuery, useRoute, useRouter } from 'vue-router'; | ||
|
||
export interface PaginatorState { | ||
page: Ref<number>; | ||
pageSize: Ref<number>; | ||
first: Ref<number>; | ||
paginate: (newFirst: number) => Promise<void>; | ||
} | ||
|
||
export function usePaginator( | ||
initialPage: number = 1, | ||
initialPageSize: number = 20, | ||
): PaginatorState { | ||
/* Composables */ | ||
const { query } = useRoute(); | ||
const { push } = useRouter(); | ||
|
||
/* State */ | ||
const page = ref<number>(initialPage); | ||
const pageSize = ref<number>(initialPageSize); | ||
|
||
/* Watchers */ | ||
watch( | ||
() => query, | ||
(query: LocationQuery) => { | ||
if (query.page !== undefined) { | ||
page.value = parseInt(query.page as string); | ||
} | ||
|
||
if (query.pageSize !== undefined) { | ||
pageSize.value = parseInt(query.pageSize as string); | ||
} | ||
}, | ||
{ immediate: true }, | ||
); | ||
|
||
/* Computed */ | ||
const first = computed({ | ||
get: () => (page.value - 1) * pageSize.value, | ||
set: (value: number) => | ||
(page.value = Math.floor(value / pageSize.value) + 1), | ||
}); | ||
|
||
/** | ||
* Paginate using a new first item index. | ||
* | ||
* @param newFirst | ||
*/ | ||
async function paginate(newFirst: number): Promise<void> { | ||
first.value = newFirst; | ||
|
||
await push({ | ||
query: { | ||
page: page.value, | ||
pageSize: pageSize.value, | ||
}, | ||
}); | ||
} | ||
|
||
return { | ||
page, | ||
pageSize, | ||
first, | ||
paginate, | ||
}; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
frontend/src/composables/axios.ts → frontend/src/config/axios.ts
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
File renamed without changes.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const COURSE_FILTER = { | ||
search: '', | ||
faculties: [], | ||
years: [], | ||
}; | ||
|
||
export interface Filter { | ||
search: string; | ||
[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface PaginatorResponse<T> { | ||
count: number; | ||
next: string | null; | ||
previous: string | null; | ||
results: T[]; | ||
} |
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.