feat: per-admin localStorage namespacing with migration

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-23 09:42:07 -04:00
parent 9f60c6983d
commit a4d74baf51
3 changed files with 54 additions and 11 deletions

View File

@@ -4,9 +4,10 @@ import { useAuth } from '../context/AuthContext';
import { useToast } from '../components/Toast';
import api from '../api/axios';
import { formatLocalDate, isSunday } from '../utils/dateUtils';
import { prefixKey } from '../utils/adminPrefs';
function History() {
const { isAuthenticated } = useAuth();
const { isAuthenticated, adminName } = useAuth();
const { error, success } = useToast();
const navigate = useNavigate();
@@ -15,8 +16,8 @@ function History() {
const [totalCount, setTotalCount] = useState(0);
const [closingSession, setClosingSession] = useState(null);
const [filter, setFilter] = useState(() => localStorage.getItem('history-filter') || 'default');
const [limit, setLimit] = useState(() => localStorage.getItem('history-show-limit') || '5');
const [filter, setFilter] = useState(() => localStorage.getItem(prefixKey(adminName, 'history-filter')) || 'default');
const [limit, setLimit] = useState(() => localStorage.getItem(prefixKey(adminName, 'history-show-limit')) || '5');
const [selectMode, setSelectMode] = useState(false);
const [selectedIds, setSelectedIds] = useState(new Set());
@@ -50,15 +51,24 @@ function History() {
return () => clearInterval(interval);
}, [loadSessions]);
useEffect(() => {
if (adminName) {
const savedFilter = localStorage.getItem(prefixKey(adminName, 'history-filter'));
const savedLimit = localStorage.getItem(prefixKey(adminName, 'history-show-limit'));
if (savedFilter) setFilter(savedFilter);
if (savedLimit) setLimit(savedLimit);
}
}, [adminName]);
const handleFilterChange = (newFilter) => {
setFilter(newFilter);
localStorage.setItem('history-filter', newFilter);
localStorage.setItem(prefixKey(adminName, 'history-filter'), newFilter);
setSelectedIds(new Set());
};
const handleLimitChange = (newLimit) => {
setLimit(newLimit);
localStorage.setItem('history-show-limit', newLimit);
localStorage.setItem(prefixKey(adminName, 'history-show-limit'), newLimit);
setSelectedIds(new Set());
};