Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist some frontend preferences in localStorage #4559

Merged
merged 13 commits into from
Feb 6, 2024
25 changes: 15 additions & 10 deletions frontend/src/components/activity/ScheduleEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Displays a single scheduleEntry
toolbar
back
:loaded="!scheduleEntry()._meta.loading && !activity.camp()._meta.loading"
:max-width="isLocalPaperDisplaySize ? '944px' : ''"
:max-width="isPaperDisplaySize ? '944px' : ''"
>
<template #title>
<v-toolbar-title class="font-weight-bold">
Expand Down Expand Up @@ -93,7 +93,7 @@ Displays a single scheduleEntry
<template v-else>{{ $tc('global.button.back') }}</template>
</v-btn>

<TogglePaperSize :value="isPaperDisplaySize" @input="toggleDisplaySize" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this functionality? This prevents a layout jump when you toggle the displaySize, because it changes the responsiveLayout to be papersize before the animation takes place.

Copy link
Member Author

@carlobeltrame carlobeltrame Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove the previous local storage implementation, which was done in the composable useDisplaySize.js. When doing this, I overlooked the nextTick and local copy of the state in there. But I am mostly convinced it does not make any perceivable difference. If it does, can you tell me which one of these screencasts comes from dev (with nextTick) and which one comes from my local instance (without nextTick)?

Blind Test A.webm
Blind Test B.webm

However, previously the paper size display of the responsive layout was broken in this PR. I fixed this now in 82f2a9c.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, shouldn't this be a computed and not a function in 82f2a9c?
Maybe this was required with the initial local value variant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the computed when I switched from the composition API paradigms back to the options API way for this feature.
What advantages do you expect from using a composition API computed here over a simple function like we do for the other provided values? I did try passing down the plain value, but that isn't reactive. The Vue 3 docs explicitly recommend using a computed for this case, but it seemed inconsistent with our other provides, and I didn't want to touch all other provides. But if you insist on using computed for just this one provide, I can change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the implementation. I just hope that it won't break at random :D

<TogglePaperSize v-model="isPaperDisplaySize" />
<!-- hamburger menu -->
<v-menu v-if="!layoutMode" offset-y>
<template #activator="{ on, attrs }">
Expand Down Expand Up @@ -240,24 +240,21 @@ Displays a single scheduleEntry
</template>

<script>
import { computed } from 'vue'
import { sortBy } from 'lodash'
import ContentCard from '@/components/layout/ContentCard.vue'
import ApiTextField from '@/components/form/api/ApiTextField.vue'
import RootNode from '@/components/activity/RootNode.vue'
import ActivityResponsibles from '@/components/activity/ActivityResponsibles.vue'
import { dateHelperUTCFormatted } from '@/mixins/dateHelperUTCFormatted.js'
import { campRoleMixin } from '@/mixins/campRoleMixin'
import { periodRoute, scheduleEntryRoute } from '@/router.js'
import router from '@/router.js'
import router, { periodRoute, scheduleEntryRoute } from '@/router.js'
import DownloadNuxtPdf from '@/components/print/print-nuxt/DownloadNuxtPdfListItem.vue'
import DownloadClientPdf from '@/components/print/print-client/DownloadClientPdfListItem.vue'
import { errorToMultiLineToast } from '@/components/toast/toasts'
import CategoryChip from '@/components/generic/CategoryChip.vue'
import CopyActivityInfoDialog from '@/components/activity/CopyActivityInfoDialog.vue'
import DialogEntityDelete from '@/components/dialog/DialogEntityDelete.vue'
import TogglePaperSize from '@/components/activity/TogglePaperSize.vue'
import { useDisplaySize } from '@/components/activity/useDisplaySize.js'

export default {
name: 'ScheduleEntry',
Expand All @@ -279,7 +276,7 @@ export default {
preferredContentTypes: () => this.preferredContentTypes,
allContentNodes: () => this.contentNodes,
camp: () => this.camp,
isPaperDisplaySize: computed(() => this.isPaperDisplaySize),
isPaperDisplaySize: () => this.isPaperDisplaySize,
}
},
props: {
Expand All @@ -288,9 +285,6 @@ export default {
required: true,
},
},
setup() {
return useDisplaySize()
},
data() {
return {
layoutMode: false,
Expand Down Expand Up @@ -348,6 +342,17 @@ export default {
],
}
},
isPaperDisplaySize: {
get() {
return this.$store.getters.getPaperDisplaySize(this.camp._meta.self)
},
set(value) {
this.$store.commit('setPaperDisplaySize', {
campUri: this.camp._meta.self,
paperDisplaySize: value,
})
},
},
},

// reload data every time user navigates to Activity view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
},
isDefaultVariant() {
return (
!this.isPaperDisplaySize &&
!this.isPaperDisplaySize() &&
this.clientWidth >= ASIDE_CONTENT_WIDTH + MAIN_CONTENT_WIDTH + GAP
)
},
Expand Down
29 changes: 0 additions & 29 deletions frontend/src/components/activity/useDisplaySize.js

This file was deleted.

71 changes: 61 additions & 10 deletions frontend/src/components/print/PrintConfigurator.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-skeleton-loader v-if="camp()._meta.loading" type="article" />
<div v-else>
<PagesOverview v-model="cnf.contents">
<PagesOverview v-model="cnf.contents" @input="onChange">
<PagesConfig
v-for="(content, idx) in cnf.contents"
:key="idx"
Expand All @@ -11,12 +11,13 @@
contentComponents[content.type].design.multiple ||
content.options?.periods?.length > 1
"
@remove="cnf.contents.splice(idx, 1)"
@remove="removeContent(idx)"
>
<component
:is="contentComponents[content.type]"
v-model="content.options"
:value="content.options"
:camp="camp()"
@input="onChange"
/>
</PagesConfig>

Expand All @@ -36,7 +37,7 @@
v-for="(component, idx) in contentComponents"
:key="idx"
@click="
cnf.contents.push({
addContent({
type: idx,
options: component.defaultOptions(),
})
Expand Down Expand Up @@ -108,6 +109,8 @@ import PagesConfig from './configurator/PagesConfig.vue'
import DownloadNuxtPdfButton from '@/components/print/print-nuxt/DownloadNuxtPdfButton.vue'
import DownloadClientPdfButton from '@/components/print/print-client/DownloadClientPdfButton.vue'
import { getEnv } from '@/environment.js'
import cloneDeep from 'lodash/cloneDeep'
import VueI18n from '../../plugins/i18n/index.js'

export default {
name: 'PrintConfigurator',
Expand Down Expand Up @@ -142,19 +145,25 @@ export default {
Activity: ActivityConfig,
Toc: TocConfig,
},
cnf: {
language: '',
documentName: this.camp().name,
camp: this.camp()._meta.self,
contents: this.defaultContents(),
},
previewTab: null,
}
},
computed: {
lang() {
return this.$store.state.lang.language
},
cnf() {
return this.repairConfig(
cloneDeep(
this.$store.getters.getLastPrintConfig(this.camp()._meta.self, {
language: this.lang,
documentName: this.camp().name,
camp: this.camp()._meta.self,
contents: this.defaultContents(),
})
)
)
},
isDev() {
return getEnv().FEATURE_DEVELOPER ?? false
},
Expand All @@ -176,6 +185,12 @@ export default {
})
},
methods: {
resetConfig() {
this.$store.commit('setLastPrintConfig', {
campUri: this.camp()._meta.self,
printConfig: undefined,
})
},
defaultContents() {
const contents = [
{
Expand Down Expand Up @@ -217,6 +232,42 @@ export default {

return contents
},
addContent(content) {
this.cnf.contents.push(content)
this.onChange()
},
removeContent(idx) {
this.cnf.contents.splice(idx, 1)
this.onChange()
},
onChange() {
this.$nextTick(() => {
this.$store.commit('setLastPrintConfig', {
campUri: this.camp()._meta.self,
printConfig: cloneDeep(this.cnf),
})
})
},
repairConfig(config) {
if (!config) config = {}
if (!(config.language in VueI18n.availableLocales)) config.language = 'en'
if (!config.documentName) config.documentName = this.camp().name
if (config.camp !== this.camp()._meta.self) config.camp = this.camp()._meta.self
if (typeof config.contents?.map !== 'function') {
config.contents = this.defaultContents()
}
config.contents = config.contents
.map((content) => {
if (!content.type) return null
const component = this.contentComponents[content.type]
if (!component) return null
if (typeof component.repairConfig !== 'function') return content
return component.repairConfig(content, this.camp())
})
.filter((component) => component)

return config
},
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/print/config/ActivityConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:items="scheduleEntries"
:label="$tc('components.print.config.activityConfig.activity')"
:filled="false"
@input="$emit('input')"
/>
<v-skeleton-loader v-else type="image" height="56" />
</div>
Expand Down
38 changes: 28 additions & 10 deletions frontend/src/components/print/config/PicassoConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@
:items="periods"
multiple
:filled="false"
@input="$emit('input')"
/>
<e-select
v-model="options.orientation"
:label="$tc('components.print.config.picassoConfig.orientation')"
:items="orientations"
:filled="false"
@input="$emit('input')"
/>
</div>
</template>

<script>
import cloneDeep from 'lodash/cloneDeep'

const ORIENTATIONS = [
{
value: 'L',
text: 'Landscape',
},
{
value: 'P',
text: 'Portrait',
},
]

export default {
name: 'PicassoConfig',
props: {
Expand All @@ -25,16 +40,7 @@ export default {
},
data() {
return {
orientations: [
{
value: 'L',
text: 'Landscape',
},
{
value: 'P',
text: 'Portrait',
},
],
orientations: cloneDeep(ORIENTATIONS),
}
},
computed: {
Expand Down Expand Up @@ -62,5 +68,17 @@ export default {
design: {
multiple: false,
},
repairConfig(config, camp) {
if (!config.options) config.options = {}
if (!config.options.periods) config.options.periods = []
const knownPeriods = camp.periods().items.map((p) => p._meta.self)
config.options.periods = config.options.periods.filter((period) => {
return knownPeriods.includes(period)
})
if (!(config.options.orientation in ORIENTATIONS.map((o) => o.value))) {
config.options.orientation = 'L'
}
return config
},
}
</script>
12 changes: 12 additions & 0 deletions frontend/src/components/print/config/ProgramConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
:label="$tc('components.print.config.programConfig.periods')"
multiple
:filled="false"
@input="$emit('input')"
/>
<e-checkbox
v-model="options.dayOverview"
:label="$tc('components.print.config.programConfig.dayOverview')"
@input="$emit('input')"
/>
</div>
</template>
Expand Down Expand Up @@ -46,5 +48,15 @@ export default {
design: {
multiple: true,
},
repairConfig(config, camp) {
if (!config.options) config.options = {}
if (!config.options.periods) config.options.periods = []
const knownPeriods = camp.periods().items.map((p) => p._meta.self)
config.options.periods = config.options.periods.filter((period) => {
return knownPeriods.includes(period)
})
if (typeof config.options.dayOverview !== 'boolean') config.options.dayOverview = true
return config
},
}
</script>
10 changes: 10 additions & 0 deletions frontend/src/components/print/config/StoryConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:label="$tc('components.print.config.storyConfig.periods')"
multiple
:filled="false"
@input="$emit('input')"
/>
</div>
</template>
Expand Down Expand Up @@ -44,5 +45,14 @@ export default {
design: {
multiple: false,
},
repairConfig(config, camp) {
if (!config.options) config.options = {}
if (!config.options.periods) config.options.periods = []
const knownPeriods = camp.periods().items.map((p) => p._meta.self)
config.options.periods = config.options.periods.filter((period) => {
return knownPeriods.includes(period)
})
return config
},
}
</script>
Loading
Loading