mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
Four localStorage keys still spelled upstream's brand — papermark.email,
papermark.name, last_papermark_login, papermark-all-links-collapsed. The first
two hold a visitor's email and name and are what makes an access form
prefill on a return visit, so renaming them naively signs every returning
visitor out of their own convenience.
lib/webstorage.ts already owned web storage, so the rename lives there:
- StorageKey names each key once. Eight call sites used to spell the string
themselves, one of them via a local const, which is why the set had
drifted into three different naming shapes.
- LEGACY_KEYS maps each new key to the name it used to have. getItem falls
back to the old key, copies the value forward and drops the old entry.
Migrating on read means no boot hook to register and no ordering to get
wrong; a key migrates the first time something asks for it, and only
then. setItem and removeItem clear the legacy entry too, so a value
cannot come back from the dead.
Six of those call sites were reaching for window.localStorage directly and
so skipped the wrapper's try/catch. They now go through it, which is what it
is for — a viewer opening a link in a third-party context with storage
blocked was throwing rather than degrading.
Co-authored-by: Hanzo Dev <[email protected]>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { cn } from "@/lib/utils";
|
|
import { StorageKey, localStorage } from "@/lib/webstorage";
|
|
|
|
type LoginType = "passkey" | "google" | "credentials" | "linkedin";
|
|
|
|
export function useLastUsed() {
|
|
const [lastUsed, setLastUsed] = useState<LoginType>();
|
|
|
|
useEffect(() => {
|
|
const storedValue = localStorage.getItem(StorageKey.lastLogin);
|
|
if (storedValue) {
|
|
setLastUsed(storedValue as LoginType);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (lastUsed) {
|
|
localStorage.setItem(StorageKey.lastLogin, lastUsed);
|
|
} else {
|
|
localStorage.removeItem(StorageKey.lastLogin);
|
|
}
|
|
}, [lastUsed]);
|
|
|
|
return [lastUsed, setLastUsed] as const;
|
|
}
|
|
|
|
export const LastUsed = ({ className }: { className?: string | undefined }) => {
|
|
return (
|
|
<div className="absolute right-2 top-1/2 w-fit -translate-y-1/2 sm:right-[-50px]">
|
|
<div
|
|
className={cn(
|
|
"relative z-[999] rounded-md bg-input px-2 py-1 text-xs text-foreground",
|
|
className,
|
|
)}
|
|
>
|
|
Last used
|
|
<div className="absolute -left-1 top-1/2 hidden h-0 w-0 -translate-y-1/2 border-b-4 border-l-0 border-r-4 border-t-4 border-transparent border-r-input sm:block" />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|