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

Conversation

carlobeltrame
Copy link
Member

@carlobeltrame carlobeltrame commented Jan 27, 2024

Persists the editMode (locked/unlocked) state of the picasso and the story overview as well as the last used print config into localStorage. All preferences are stored on a per-camp basis, and naturally being stored in localStorage, they do not carry over across different browsers, devices or even user accounts.

This PR is a proposition / prototype. We haven't formally discussed how to solve this, although both parts of the feature have been requested by multiple independent users. I'll be happy to incorporate any feedback or downsize this if needed etc.. Just wanted to get the discussion started.

Btw: Nuxt Print Preview throws a lot of console errors at the moment when running locally, probably since the move to nuxt 3. I didn't touch (nor cause) these problems.

We have to be aware that this feature makes local testing a little more difficult: It will lead to divergence between our dev environments if one person always has different preferences than another person (e.g. someone never tests print with a title page because they have their favourite print preset in their favourite testing camp). But on feature branch deployments, we always start with a clean slate.

@carlobeltrame carlobeltrame added the deploy! Creates a feature branch deployment for this PR label Jan 27, 2024
Copy link

github-actions bot commented Jan 27, 2024

Feature branch deployment currently inactive.

If the PR is still open, you can add the deploy! label to this PR to trigger a feature branch deployment.

Copy link
Member

@manuelmeister manuelmeister left a comment

Choose a reason for hiding this comment

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

Nice idea with the store. Would the paper size also be such a candidate?

@carlobeltrame
Copy link
Member Author

Nice idea with the store. Would the paper size also be such a candidate?

Ah yes, of course, good idea!

Copy link
Contributor

@BacLuc BacLuc left a comment

Choose a reason for hiding this comment

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

Code looks good. I did not test it yet

frontend/src/components/print/config/PicassoConfig.vue Outdated Show resolved Hide resolved
@carlobeltrame carlobeltrame marked this pull request as draft January 29, 2024 10:32
Copy link
Member Author

@carlobeltrame carlobeltrame left a comment

Choose a reason for hiding this comment

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

I added paper size as another per-camp preference.

However I think it would be good to implement tests for the whole thing. Will tackle this if I get general approval for the localStorage + Vuex approach.

@carlobeltrame carlobeltrame added the Meeting Discuss Am nächsten Core-Meeting besprechen label Jan 29, 2024
Copy link
Member

@pmattmann pmattmann left a comment

Choose a reason for hiding this comment

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

I like it

frontend/src/views/category/Category.vue Outdated Show resolved Hide resolved
@manuelmeister
Copy link
Member

Core Meeting Decision

  • Add reset button to print configurator
  • Maybe separate independent localstorage keys? We are not absolutely sure if the additional implementation work is justified
  • Add frontend tests

@manuelmeister manuelmeister removed the Meeting Discuss Am nächsten Core-Meeting besprechen label Jan 31, 2024
@carlobeltrame carlobeltrame marked this pull request as ready for review February 4, 2024 00:16
Copy link
Member

@manuelmeister manuelmeister left a comment

Choose a reason for hiding this comment

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

Please don't discard the visual jump prevention. On dev, story and safety concept do not jump after the animation, but move in to place just before the animation starts:

Bildschirmaufnahme.2024-02-04.um.15.14.06.mp4

@@ -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

const [, uri, identifier] = key.match(
new RegExp(`^${LOCAL_STORAGE_PREFIX}(.*):(.*)$`)
)
values[uri] = values[uri] || {}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
values[uri] = values[uri] || {}
values[uri] ||= {}

Copy link
Member

@manuelmeister manuelmeister left a comment

Choose a reason for hiding this comment

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

Thanks for the work

@@ -3,7 +3,7 @@ import Vue from 'vue'
const LOCAL_STORAGE_PREFIX = 'preferences:'

export function loadFromLocalStorage(localStorage = window.localStorage) {
let values = {}
const values = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@carlobeltrame carlobeltrame added this pull request to the merge queue Feb 6, 2024
@carlobeltrame carlobeltrame removed this pull request from the merge queue due to a manual request Feb 6, 2024
@carlobeltrame carlobeltrame added this pull request to the merge queue Feb 6, 2024
Copy link
Contributor

@BacLuc BacLuc left a comment

Choose a reason for hiding this comment

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

Thank you very much

let store = {}

return {
getStore: () => store,
Copy link
Contributor

Choose a reason for hiding this comment

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

minor:
It is a stupid api design from the w3c/javascript spec that the store is exposed.
But if you implement the clear like it is now,
the store returned by getStore is not cleared by the clear function.

I don't know if it is like this in the specification or if it is intended.

Copy link
Member Author

Choose a reason for hiding this comment

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

getStore isn't in the ecmascript spec I think, I added this for debugging. It isn't needed anymore, I will remove it.

it('loads saved picasso edit mode true', async () => {
// given
const state = loadFromLocalStorage({
'preferences:/camps/1a2b3c4d:picassoEditMode': 'true',
Copy link
Contributor

Choose a reason for hiding this comment

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

minor:
the prefix could be extracted into a constant to simplify changing it
the camp iri could also be a constant, that you see from afar if two different constants point to the same camp or not.

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 kind of like the explicit-ness of the test this way, and I think a search and replace would work well if we change the prefix. But it is a matter of taste. I will replace the camp URI with a constant, but since template literals can't directly be used as keys in JS objects it will look like this:

const state = loadFromLocalStorage({
  [`preferences:${CAMP_URI}:picassoEditMode`]: 'true',
})

Copy link
Contributor

Choose a reason for hiding this comment

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

as you like, it is a minor taste related issue

@carlobeltrame carlobeltrame removed this pull request from the merge queue due to a manual request Feb 6, 2024
@carlobeltrame carlobeltrame added this pull request to the merge queue Feb 6, 2024
Merged via the queue into ecamp:devel with commit 3671e01 Feb 6, 2024
32 checks passed
This was referenced Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy! Creates a feature branch deployment for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants