mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-30 08:25:58 -05:00
fix: guard null access in composables (#951)
This commit is contained in:
committed by
GitHub
parent
640645642b
commit
78fa5742c3
@@ -3,13 +3,16 @@ import ProjectService from '@/services/project'
|
|||||||
import type {IProject} from '@/modelTypes/IProject'
|
import type {IProject} from '@/modelTypes/IProject'
|
||||||
import {getBlobFromBlurHash} from '@/helpers/getBlobFromBlurHash'
|
import {getBlobFromBlurHash} from '@/helpers/getBlobFromBlurHash'
|
||||||
|
|
||||||
export function useProjectBackground(project: MaybeRefOrGetter<IProject>) {
|
export function useProjectBackground(project: MaybeRefOrGetter<IProject | null>) {
|
||||||
const background = ref<string | null>(null)
|
const background = ref<string | null>(null)
|
||||||
const backgroundLoading = ref(false)
|
const backgroundLoading = ref(false)
|
||||||
const blurHashUrl = ref('')
|
const blurHashUrl = ref('')
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [toValue(project).id, toValue(project)?.backgroundBlurHash] as [IProject['id'], IProject['backgroundBlurHash']],
|
() => [
|
||||||
|
toValue(project)?.id ?? null,
|
||||||
|
toValue(project)?.backgroundBlurHash ?? null,
|
||||||
|
] as [IProject['id'] | null, IProject['backgroundBlurHash'] | null],
|
||||||
async ([projectId, blurHash], oldValue) => {
|
async ([projectId, blurHash], oldValue) => {
|
||||||
const projectValue = toValue(project)
|
const projectValue = toValue(project)
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export function useRenewTokenOnFocus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nowInSeconds = new Date().getTime() / MILLISECONDS_A_SECOND
|
const nowInSeconds = new Date().getTime() / MILLISECONDS_A_SECOND
|
||||||
const expiresIn = userInfo.value !== null
|
const expiresIn = userInfo.value
|
||||||
? userInfo.value.exp - nowInSeconds
|
? userInfo.value.exp - nowInSeconds
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {useProjectStore} from '@/stores/projects'
|
|||||||
export function useRouteWithModal() {
|
export function useRouteWithModal() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const backdropView = computed(() => route.fullPath && window.history.state.backdropView)
|
const backdropView = computed(() => route.fullPath ? window.history.state.backdropView : undefined)
|
||||||
const baseStore = useBaseStore()
|
const baseStore = useBaseStore()
|
||||||
const projectStore = useProjectStore()
|
const projectStore = useProjectStore()
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ export function useRouteWithModal() {
|
|||||||
currentModal.value = h(component, routeProps)
|
currentModal.value = h(component, routeProps)
|
||||||
})
|
})
|
||||||
|
|
||||||
const historyState = computed(() => route.fullPath && window.history.state)
|
const historyState = computed(() => route.fullPath ? window.history.state : undefined)
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
|
|
||||||
@@ -63,7 +63,9 @@ export function useRouteWithModal() {
|
|||||||
// we need to reflect that change in the route when they close the task modal.
|
// we need to reflect that change in the route when they close the task modal.
|
||||||
// The last route is only available as resolved string, therefore we need to use a regex for matching here
|
// The last route is only available as resolved string, therefore we need to use a regex for matching here
|
||||||
const routeMatch = new RegExp('\\/projects\\/\\d+\\/(\\d+)', 'g')
|
const routeMatch = new RegExp('\\/projects\\/\\d+\\/(\\d+)', 'g')
|
||||||
const match = routeMatch.exec(historyState.value.back)
|
const match = historyState.value?.back
|
||||||
|
? routeMatch.exec(historyState.value.back)
|
||||||
|
: null
|
||||||
if (match !== null && baseStore.currentProject) {
|
if (match !== null && baseStore.currentProject) {
|
||||||
let viewId: string | number = match[1]
|
let viewId: string | number = match[1]
|
||||||
|
|
||||||
@@ -86,7 +88,9 @@ export function useRouteWithModal() {
|
|||||||
router.back()
|
router.back()
|
||||||
} else {
|
} else {
|
||||||
const backdropRoute = historyState.value?.backdropView && router.resolve(historyState.value.backdropView)
|
const backdropRoute = historyState.value?.backdropView && router.resolve(historyState.value.backdropView)
|
||||||
router.push(backdropRoute)
|
if (backdropRoute) {
|
||||||
|
router.push(backdropRoute)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user