[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Add local likes & history to cloud after signing in #242

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aabounegm
Copy link
Owner

Closes #235

@github-actions github-actions bot requested a review from alkaitagi May 8, 2022 17:18
@cloudflare-pages
Copy link
cloudflare-pages bot commented May 8, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f3eeb8c
Status: ✅  Deploy successful!
Preview URL: https://cbdffeaf.cast-iu.pages.dev

View logs

@codecov-commenter
Copy link

Codecov Report

Merging #242 (405d2aa) into main (a9c9149) will decrease coverage by 0.18%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #242      +/-   ##
==========================================
- Coverage   60.74%   60.56%   -0.19%     
==========================================
  Files          75       75              
  Lines         670      672       +2     
  Branches      200      200              
==========================================
  Hits          407      407              
- Misses        250      252       +2     
  Partials       13       13              
Impacted Files Coverage Δ
...ib/features/authenticate/model/sign-in-snackbar.ts 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9c9149...405d2aa. Read the comment docs.

@@ -1,5 +1,8 @@
import { snackbar } from '$lib/shared/ui/snackbar';
import { supabaseClient } from '$lib/shared/api';
import { likesStore, addCloudLike } from '$lib/features/like-episode';
import { listeningHistory, addToCloudListeningHistory } from '$lib/features/listening-history';
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: FSD, cross-imports of features

Copy link
Owner Author

Choose a reason for hiding this comment

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

Same as #241 (comment)

@@ -14,5 +17,7 @@ export function signInSnackbar() {
});
url.searchParams.delete('snackbar');
window.history.replaceState(null, '', url.toString());
get(likesStore).forEach(addCloudLike);
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: why did you decide to do it here, of all the places?)

suggestion: the same as in that other PR, let's do it here:

user.subscribe(async ($user) => {
if ($user) {
const ids = await fetchLikes();
likesStore.set(ids ?? []);
}
});

Copy link
Owner Author

Choose a reason for hiding this comment

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

Because I didn't want to add the like to Supabase every time the user loads the page (I'm not sure if there are any uniqueness constraints set in the backend). This seemed like the only function where I guarantee the user has just signed in after being logged out before and having added some episode to the favorites.
I agree it's not the best solution, especially that it only works if the user signed in through the snackbar that appears after liking an episode unauthenticated, but I also couldn't think of another quick solution that doesn't involve querying the backend likes/history and diffing the data.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are uniqueness constraints on the data, so uploading a duplicate like/history won't really change anything except for the created_at timestamp, which we don't use anyway, except for ordering.

Technically, we could have another derived store that tracks the previous value of the user store, and expose to the public yet another derived store that provides access to them both, however, that is slightly janky, so proceed at will

Copy link
Owner Author

Choose a reason for hiding this comment

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

Still, I would prefer not to depend on constraints in the backend, especially that the function name literally says "add". It's better to validate the data on the client side first and consider the backend validation as a safety measure

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, then diffing on the client it is. Shouldn't be too expensive/hard

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upload likes and listening history upon connecting to the internet
3 participants