Parsed wrong url params out
This commit is contained in:
@@ -2,6 +2,7 @@ import { computed, type Ref, type ComputedRef, ref } from 'vue'
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { useUrlSearchParams } from '@vueuse/core'
|
import { useUrlSearchParams } from '@vueuse/core'
|
||||||
import type { LeimDate, LeimPeriod, LeimPeriodShort } from '@/models/Date'
|
import type { LeimDate, LeimPeriod, LeimPeriodShort } from '@/models/Date'
|
||||||
|
import { isDigit, isInt, isSignedInt } from '@/utils/Regex'
|
||||||
|
|
||||||
type CalendarViewType = 'month' | 'year' | 'decade' | 'century'
|
type CalendarViewType = 'month' | 'year' | 'decade' | 'century'
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
|
|
||||||
// Get date from URL params
|
// Get date from URL params
|
||||||
const params = useUrlSearchParams('history', {
|
const params = useUrlSearchParams('history', {
|
||||||
removeNullishValues: true
|
write: true
|
||||||
})
|
})
|
||||||
|
|
||||||
// Default date settings (current day)
|
// Default date settings (current day)
|
||||||
@@ -90,13 +91,13 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Assign default values if no params exist in URL
|
// Assign default values if no params exist in URL
|
||||||
if (!params.day) {
|
if (!params.day || typeof params.day === 'object' || !isInt(params.day)) {
|
||||||
params.day = defaultDay.toString()
|
params.day = defaultDay.toString()
|
||||||
}
|
}
|
||||||
if (!params.month) {
|
if (!params.month || typeof params.month === 'object' || !isDigit(params.month)) {
|
||||||
params.month = defaultMonth.toString()
|
params.month = defaultMonth.toString()
|
||||||
}
|
}
|
||||||
if (!params.year) {
|
if (!params.year || typeof params.year === 'object' || !isSignedInt(params.year)) {
|
||||||
params.year = defaultYear.toString()
|
params.year = defaultYear.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
src/utils/Regex.ts
Normal file
29
src/utils/Regex.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Check if the string parses as single digit
|
||||||
|
*
|
||||||
|
* @param str String to test
|
||||||
|
* @returns Result of the test
|
||||||
|
*/
|
||||||
|
export function isDigit(str: string) {
|
||||||
|
return RegExp(/^\d{1}$/g).test(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the string parses as an int
|
||||||
|
*
|
||||||
|
* @param str String to test
|
||||||
|
* @returns Result of the test
|
||||||
|
*/
|
||||||
|
export function isInt(str: string) {
|
||||||
|
return RegExp(/^[0-9]*$/g).test(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the string parses as a signed int (negative or positive)
|
||||||
|
*
|
||||||
|
* @param str String to test
|
||||||
|
* @returns Result of the test
|
||||||
|
*/
|
||||||
|
export function isSignedInt(str: string) {
|
||||||
|
return RegExp(/^[-+]?[0-9]+$/g).test(str)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user