Recent sheets per user
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { selectedSheet, currentStep } from '$lib/stores';
|
||||
import type { SheetInfoType } from '$lib/stores';
|
||||
import { searchSheets, ensureToken } from '$lib/google';
|
||||
import { searchSheets, ensureToken, userEmail } from '$lib/google';
|
||||
import { hashString } from '$lib/utils';
|
||||
import { onMount } from 'svelte';
|
||||
import Navigator from './subcomponents/Navigator.svelte';
|
||||
|
||||
@@ -12,7 +13,13 @@
|
||||
let hasSearched = $state(false);
|
||||
let recentSheets = $state<any[]>([]);
|
||||
|
||||
const RECENT_SHEETS_KEY = 'recentSheets';
|
||||
async function getRecentSheetsKey() {
|
||||
const email = $userEmail;
|
||||
if (email) {
|
||||
return `recentSheets_${await hashString(email)}`;
|
||||
}
|
||||
return 'recentSheets_anonymous';
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
ensureToken();
|
||||
@@ -37,16 +44,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadRecentSheets() {
|
||||
async function loadRecentSheets() {
|
||||
try {
|
||||
const saved = localStorage.getItem(RECENT_SHEETS_KEY);
|
||||
const key = await getRecentSheetsKey();
|
||||
const saved = localStorage.getItem(key);
|
||||
if (saved) {
|
||||
recentSheets = JSON.parse(saved);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error loading recent sheets:', err);
|
||||
// If there's an error, clear the stored value
|
||||
localStorage.removeItem(RECENT_SHEETS_KEY);
|
||||
const key = await getRecentSheetsKey();
|
||||
localStorage.removeItem(key);
|
||||
recentSheets = [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user