diff --git a/src/lib/features/authenticate/model/sign-in-snackbar.ts b/src/lib/features/authenticate/model/sign-in-snackbar.ts index aea0da4c..57e4db00 100644 --- a/src/lib/features/authenticate/model/sign-in-snackbar.ts +++ b/src/lib/features/authenticate/model/sign-in-snackbar.ts @@ -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); + get(listeningHistory).forEach(addToCloudListeningHistory); } } diff --git a/src/lib/features/authenticate/model/specs/sign-in.spec.ts b/src/lib/features/authenticate/model/specs/sign-in.spec.ts index 71dcb86c..9a7e6683 100644 --- a/src/lib/features/authenticate/model/specs/sign-in.spec.ts +++ b/src/lib/features/authenticate/model/specs/sign-in.spec.ts @@ -1,6 +1,7 @@ import { supabaseClient } from '$lib/shared/api'; import { signIn } from '../..'; +jest.mock('$app/env', () => ({ browser: false }), { virtual: true }); jest.mock('$lib/shared/api', () => ({ ...jest.requireActual('$lib/shared/api'), supabaseClient: { diff --git a/src/lib/features/authenticate/model/specs/sign-out.spec.ts b/src/lib/features/authenticate/model/specs/sign-out.spec.ts index 8beb7e0c..0318dcfc 100644 --- a/src/lib/features/authenticate/model/specs/sign-out.spec.ts +++ b/src/lib/features/authenticate/model/specs/sign-out.spec.ts @@ -1,6 +1,7 @@ import { supabaseClient } from '$lib/shared/api'; import { signOut } from '../..'; +jest.mock('$app/env', () => ({ browser: false }), { virtual: true }); jest.mock('$lib/shared/api', () => ({ ...jest.requireActual('$lib/shared/api'), supabaseClient: { diff --git a/src/lib/features/authenticate/model/specs/track-auth-status.spec.ts b/src/lib/features/authenticate/model/specs/track-auth-status.spec.ts index d90bbeb6..1d154a8c 100644 --- a/src/lib/features/authenticate/model/specs/track-auth-status.spec.ts +++ b/src/lib/features/authenticate/model/specs/track-auth-status.spec.ts @@ -4,6 +4,7 @@ import { user } from '$lib/entities/user'; import { supabaseClient } from '$lib/shared/api'; import { trackAuthStatus } from '../..'; +jest.mock('$app/env', () => ({ browser: false }), { virtual: true }); jest.mock('$lib/shared/api', () => ({ ...jest.requireActual('$lib/shared/api'), supabaseClient: { @@ -19,6 +20,7 @@ jest.mock('$lib/shared/api', () => ({ jest.mock('$lib/entities/user', () => ({ user: { set: jest.fn().mockName('user.set() from $lib/entities/user'), + subscribe: jest.fn().mockName('user.subscribe() from $lib/entities/user'), }, })); diff --git a/src/lib/features/like-episode/index.ts b/src/lib/features/like-episode/index.ts index 2aca74a3..c8fab91d 100644 --- a/src/lib/features/like-episode/index.ts +++ b/src/lib/features/like-episode/index.ts @@ -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'; diff --git a/src/lib/features/listening-history/api/fetch-history.ts b/src/lib/features/listening-history/api/fetch-history.ts index 8869adf5..829dc7ee 100644 --- a/src/lib/features/listening-history/api/fetch-history.ts +++ b/src/lib/features/listening-history/api/fetch-history.ts @@ -1,8 +1,9 @@ import { supabaseClient } from '$lib/shared/api'; +import type { SBHistoryEntry } from '$lib/shared/api/adapters'; export async function fetchHistory() { const hist = await supabaseClient - .from('history') + .from('history') .select('podcast_id') .order('created_at', { ascending: false }); return hist.data?.map((e) => e.podcast_id); diff --git a/src/lib/features/listening-history/index.ts b/src/lib/features/listening-history/index.ts index d0cd9178..ac2b6167 100644 --- a/src/lib/features/listening-history/index.ts +++ b/src/lib/features/listening-history/index.ts @@ -1,2 +1,3 @@ export { addToListeningHistory, listeningHistory } from './model/store'; export { populateListeningHistory } from './model/populate-listening-history'; +export { addToCloudListeningHistory } from './api/history-table'; diff --git a/src/lib/shared/api/adapters.ts b/src/lib/shared/api/adapters.ts index 0a3b4ecc..f3818543 100644 --- a/src/lib/shared/api/adapters.ts +++ b/src/lib/shared/api/adapters.ts @@ -39,6 +39,7 @@ export interface SBHistoryEntry { id: number; podcast_id: SBPodcast['id']; user_id: string; + created_at: string; } export const transformEpisodeRequest = (episode: SBEpisode): Episode | null => {