-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: reduce the number of API requests when changing route #14666
Conversation
We probably should use the rune syntax for these since store syntax will be deprecated in the future iirc |
Yup, this should be some global state :) |
bd4a3b9
to
c042f71
Compare
@alextran1502 I don't think stores will be deprecated @danieldietzler What's the svelte way for global state (classes, functions...)? I didn't find any example in Immich codebase. |
#14662 could be a good inspiration? |
Stores are indeed not deprecated. In this situation you can just replace We do have to be careful about persisting state globally, because a user could log in with a different account. Data can also become stale after a certain period. This PR also fixes #14509 |
c042f71
to
fa5ec6c
Compare
The |
fa5ec6c
to
e86198a
Compare
Indeed! |
e86198a
to
aabe2ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me
@@ -4,13 +4,19 @@ | |||
import { getAllAlbums, type AlbumResponseDto } from '@immich/sdk'; | |||
import { handleError } from '$lib/utils/handle-error'; | |||
import { t } from 'svelte-i18n'; | |||
import { userInteraction } from '$lib/stores/user.svelte'; | |||
|
|||
let albums: AlbumResponseDto[] = $state([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could completely drop this variable and replace it with the global userInteraction.recentAlbums
state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean dropping let albums: AlbumResponseDto[] = $state([]);
in favor of using only userInteraction.recentAlbums
? If so, you have to wrap the each section in a {#if userInteraction.recentAlbums}
because userInteraction.recentAlbums
can be undefined. What do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be undefined? You'd still set it in onMount
if it's undefined, and onMount
finishes before it actually mounts, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is my svelte knowledge lacking here? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, technically it can't be undefined, but Svelte isn't smart enough to figure that out. It only uses the type definition
interface UserInteractions {
recentAlbums?: AlbumResponseDto[];
versions?: ServerVersionHistoryResponseDto[];
aboutInfo?: ServerAboutResponseDto;
serverInfo?: ServerStorageResponseDto;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha. Then I'd prefer keeping that extra variable as well
b15f4a5
to
cc27ea5
Compare
cc27ea5
to
7cf07fe
Compare
…p#14666) * fix: reduce the number of API requests when changing route * fix: reset `userInteraction` after sign out
Reduce the number of API requests when changing route by storing the already stored value to a store. (maybe there's a better way with svelte 5?)
Example with navigating from
/photos
to/utilities