Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ import LeftSidebar from './components/LeftSidebar/LeftSidebar.vue'
import RightSidebar from './components/RightSidebar/RightSidebar.vue'
import DefaultPageError from './views/DefaultPageError.vue'

import { initialActionCode, ACTION_CODES } from './helpers/ActionMapping'
import LogoLibreSign from '../img/logo-gray.svg'

const route = useRoute()
const loading = ref(false)

const isRoot = computed(() => route.path === '/')
const isSignExternalPage = computed(() => route.path.startsWith('/p/'))
const isDoNothingError = computed(() => (route.params?.action as number | undefined) === 2000)
const isDoNothingError = computed(() => initialActionCode.value === ACTION_CODES.DO_NOTHING)
const showLeftSidebar = computed(() => !route.matched.some(record => record.meta?.hideLeftSidebar === true))
</script>

Expand Down
10 changes: 10 additions & 0 deletions src/helpers/ActionMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { ref } from '@vue/reactivity'

interface ActionCodes {
REDIRECT: number
CREATE_ACCOUNT: number
Expand Down Expand Up @@ -53,6 +55,14 @@ export const ACTION_CODE_TO_ROUTE: Readonly<ActionCodeToRoute> = Object.freeze({
[ACTION_CODES.INCOMPLETE_SETUP]: 'Incomplete',
})

/**
* Shared reactive ref for the initial action code injected by the server
* (#initial-state-libresign-action). Written once by router.ts beforeEach,
* read by App.vue. Lives here (not in router.ts) to avoid App.vue triggering
* the router module's side effects (createRouter, generateUrl) on import.
*/
export const initialActionCode = ref(0)

export const REQUIREMENT_TO_MODAL: Readonly<RequirementToModal> = Object.freeze({
identificationDocuments: 'uploadDocuments',
emailCode: 'emailToken',
Expand Down
3 changes: 2 additions & 1 deletion src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createRouter, createWebHistory, type Router, type RouteRecordRaw } from
import { loadState } from '@nextcloud/initial-state'
import { getRootUrl, generateUrl } from '@nextcloud/router'

import { initialActionCode } from '../helpers/ActionMapping'
import { isExternal } from '../helpers/isExternal'
import { selectAction } from '../helpers/SelectAction'

Expand Down Expand Up @@ -212,7 +213,7 @@ router.beforeEach((to, from, next) => {
let action
if (actionElement) {
const actionValue = loadState('libresign', 'action', 0)
to.params.action = String(actionValue)
initialActionCode.value = actionValue
action = selectAction(actionValue, to, from)
document.querySelector('#initial-state-libresign-action')?.remove()
}
Expand Down
9 changes: 5 additions & 4 deletions src/tests/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'

import { initialActionCode, ACTION_CODES } from '../helpers/ActionMapping'

type RouteState = {
path: string
name: string | undefined
Expand Down Expand Up @@ -56,6 +58,7 @@ describe('App', () => {
routeState.name = 'fileslist'
routeState.params = {}
routeState.matched = []
initialActionCode.value = 0
})

it('shows left sidebar on regular internal routes', () => {
Expand Down Expand Up @@ -182,8 +185,8 @@ describe('App', () => {
expect(wrapper.find('.nc-content').classes()).not.toContain('sign-external-page')
})

it('shows DefaultPageError when action param is 2000', () => {
routeState.params = { action: 2000 }
it('shows DefaultPageError when initial action code is DO_NOTHING (2000)', () => {
initialActionCode.value = ACTION_CODES.DO_NOTHING

const wrapper = mount(App, {
global: {
Expand All @@ -203,8 +206,6 @@ describe('App', () => {
})

it('does not show DefaultPageError on normal routes', () => {
routeState.params = {}

const wrapper = mount(App, {
global: {
stubs: {
Expand Down
Loading