fix(app): harden account and workflow state
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useMemo, useState } from "react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import {
|
||||
Button,
|
||||
@@ -15,6 +15,7 @@ import BookmarkBorderIcon from "@mui/icons-material/BookmarkBorder";
|
||||
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
|
||||
|
||||
import { useI18n } from "../i18n/I18nProvider";
|
||||
import { AUTH_USER_CHANGED_EVENT, getUserScopedStorageKey } from "../auth";
|
||||
|
||||
export type SavedViewParams = {
|
||||
q?: string;
|
||||
@@ -22,6 +23,7 @@ export type SavedViewParams = {
|
||||
companyId?: number;
|
||||
location?: string;
|
||||
needsFollowUp?: boolean;
|
||||
readiness?: "needs-work" | "interview";
|
||||
};
|
||||
|
||||
type SavedView = {
|
||||
@@ -35,7 +37,7 @@ const KEY = "jt_saved_views_v1";
|
||||
|
||||
function loadViews(): SavedView[] {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(KEY);
|
||||
const raw = window.localStorage.getItem(getUserScopedStorageKey(KEY));
|
||||
if (!raw) return [];
|
||||
const v = JSON.parse(raw);
|
||||
if (!Array.isArray(v)) return [];
|
||||
@@ -46,7 +48,7 @@ function loadViews(): SavedView[] {
|
||||
}
|
||||
|
||||
function saveViews(views: SavedView[]) {
|
||||
window.localStorage.setItem(KEY, JSON.stringify(views));
|
||||
window.localStorage.setItem(getUserScopedStorageKey(KEY), JSON.stringify(views));
|
||||
}
|
||||
|
||||
export default function SavedViewsMenu({
|
||||
@@ -61,6 +63,16 @@ export default function SavedViewsMenu({
|
||||
const [name, setName] = useState("");
|
||||
const [views, setViews] = useState<SavedView[]>(() => loadViews());
|
||||
|
||||
useEffect(() => {
|
||||
const reloadForAccount = () => {
|
||||
setViews(loadViews());
|
||||
setName("");
|
||||
setAnchor(null);
|
||||
};
|
||||
window.addEventListener(AUTH_USER_CHANGED_EVENT, reloadForAccount);
|
||||
return () => window.removeEventListener(AUTH_USER_CHANGED_EVENT, reloadForAccount);
|
||||
}, []);
|
||||
|
||||
const hasAny = views.length > 0;
|
||||
|
||||
const canSave = useMemo(() => name.trim().length > 0, [name]);
|
||||
|
||||
Reference in New Issue
Block a user