This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
import { readIdentity, writeIdentity } from '../utils/identity'
|
||||
import { readIdentity, writeIdentity } from '../utils/identity';
|
||||
|
||||
export function useIdentity() {
|
||||
const name = useState<string | null>('identity-name', () => null)
|
||||
const loaded = useState('identity-loaded', () => false)
|
||||
const name = useState<string | null>('identity-name', () => null);
|
||||
const loaded = useState('identity-loaded', () => false);
|
||||
|
||||
if (import.meta.client && !loaded.value) {
|
||||
const identity = readIdentity(window.localStorage)
|
||||
name.value = identity?.name ?? null
|
||||
loaded.value = true
|
||||
const identity = readIdentity(window.localStorage);
|
||||
name.value = identity?.name ?? null;
|
||||
loaded.value = true;
|
||||
}
|
||||
|
||||
function setName(newName: string) {
|
||||
const trimmed = newName.trim()
|
||||
if (!trimmed) return
|
||||
name.value = trimmed
|
||||
if (import.meta.client) writeIdentity(window.localStorage, { name: trimmed })
|
||||
const trimmed = newName.trim();
|
||||
if (!trimmed) return;
|
||||
name.value = trimmed;
|
||||
if (import.meta.client)
|
||||
writeIdentity(window.localStorage, { name: trimmed });
|
||||
}
|
||||
|
||||
return { name, setName }
|
||||
return { name, setName };
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { readCachedPaymentLink, writeCachedPaymentLink } from '../utils/paymentLinkCache'
|
||||
import {
|
||||
readCachedPaymentLink,
|
||||
writeCachedPaymentLink,
|
||||
} from '../utils/paymentLinkCache';
|
||||
|
||||
export function usePaymentLinkCache() {
|
||||
const lastLink = useState<string | null>('payment-link-cache', () => null)
|
||||
const lastLink = useState<string | null>('payment-link-cache', () => null);
|
||||
|
||||
if (import.meta.client && lastLink.value === null) {
|
||||
lastLink.value = readCachedPaymentLink(window.localStorage)
|
||||
lastLink.value = readCachedPaymentLink(window.localStorage);
|
||||
}
|
||||
|
||||
function rememberLink(link: string) {
|
||||
if (!import.meta.client || !link) return
|
||||
lastLink.value = link
|
||||
writeCachedPaymentLink(window.localStorage, link)
|
||||
if (!import.meta.client || !link) return;
|
||||
lastLink.value = link;
|
||||
writeCachedPaymentLink(window.localStorage, link);
|
||||
}
|
||||
|
||||
return { lastLink, rememberLink }
|
||||
return { lastLink, rememberLink };
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import { readVisitedPots, recordVisitedPot, type VisitedPot } from '../utils/visitedPots'
|
||||
import {
|
||||
readVisitedPots,
|
||||
recordVisitedPot,
|
||||
type VisitedPot,
|
||||
} from '../utils/visitedPots';
|
||||
|
||||
export function useVisitedPots() {
|
||||
const stored = useState<VisitedPot[] | null>('visited-pots', () => null)
|
||||
const stored = useState<VisitedPot[] | null>('visited-pots', () => null);
|
||||
|
||||
if (import.meta.client && stored.value === null) {
|
||||
stored.value = readVisitedPots(window.localStorage)
|
||||
stored.value = readVisitedPots(window.localStorage);
|
||||
}
|
||||
|
||||
const pots = computed(() => stored.value ?? [])
|
||||
const pots = computed(() => stored.value ?? []);
|
||||
|
||||
function recordVisit(pot: Omit<VisitedPot, 'visitedAt'>) {
|
||||
if (!import.meta.client) return
|
||||
stored.value = recordVisitedPot(window.localStorage, pot)
|
||||
if (!import.meta.client) return;
|
||||
stored.value = recordVisitedPot(window.localStorage, pot);
|
||||
}
|
||||
|
||||
return { pots, recordVisit }
|
||||
return { pots, recordVisit };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user