-
Notifications
You must be signed in to change notification settings - Fork 2
Add local likes & history to cloud after signing in #242
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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'; | ||||||||||||||
import { get } from 'svelte/store'; | ||||||||||||||
|
||||||||||||||
export function signInSnackbar() { | ||||||||||||||
const url = new URL(window.location.href); | ||||||||||||||
|
@@ -14,5 +17,7 @@ export function signInSnackbar() { | |||||||||||||
}); | ||||||||||||||
url.searchParams.delete('snackbar'); | ||||||||||||||
window.history.replaceState(null, '', url.toString()); | ||||||||||||||
get(likesStore).forEach(addCloudLike); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: cast/src/lib/features/like-episode/model/like.ts Lines 13 to 18 in bd8fc73
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Technically, we could have another There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||||
get(listeningHistory).forEach(addToCloudListeningHistory); | ||||||||||||||
} | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as LikeButton } from './ui/like-button.svelte'; | ||
export { likesStore, toggleLike } from './model/like'; | ||
export { populateLikes } from './model/populate-likes'; | ||
export { addCloudLike } from './api/favourites-table'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { addToListeningHistory, listeningHistory } from './model/store'; | ||
export { populateListeningHistory } from './model/populate-listening-history'; | ||
export { addToCloudListeningHistory } from './api/history-table'; |
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.
issue: FSD, cross-imports of features
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.
Same as #241 (comment)