Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 1x 19x 19x 19x 4x 4x 4x 19x 2x 16x 1x 1x 19x 1x 3x 3x 3x 1x 3x 1x 5x 5x 5x 5x 9x 9x 4x 4x 9x 4x 5x 2x 5x | import { toCompactDateString } from './date';
import { parseDateFromYYYYMMDD } from './calendar';
/**
* localStorage key used by astro-themes for theme preference (must be preserved on logout).
*/
export const THEME_STORAGE_KEY = 'theme';
/**
* localStorage key for the most recently applied feedback date range, so it
* survives a page refresh instead of resetting to the loaded week.
*/
export const FEEDBACK_RANGE_STORAGE_KEY = 'feedback-applied-range';
export interface PersistedFeedbackRange {
from: Date;
to: Date;
}
/** Persist the most recently applied feedback date range. Caller handles errors. */
export const saveFeedbackRange = (range: PersistedFeedbackRange) => {
localStorage.setItem(
FEEDBACK_RANGE_STORAGE_KEY,
JSON.stringify({
from: toCompactDateString(range.from),
to: toCompactDateString(range.to),
}),
);
};
/** Read the persisted feedback range, or null when missing/invalid/unavailable. */
export const loadFeedbackRange = (): PersistedFeedbackRange | null => {
try {
const raw = localStorage.getItem(FEEDBACK_RANGE_STORAGE_KEY);
if (!raw) return null;
const { from, to } = JSON.parse(raw) as { from?: string; to?: string };
const fromDate = parseDateFromYYYYMMDD(from);
const toDate = parseDateFromYYYYMMDD(to);
if (!fromDate || !toDate) return null;
return { from: fromDate, to: toDate };
} catch {
return null;
}
};
/** Clear the entire localStorage. Logs errors if unavailable. */
export const clearLocalStorage = () => {
try {
localStorage.clear();
} catch {
// localStorage may be unavailable
}
};
/**
* Clear localStorage but preserve given keys (e.g. theme preference so dark mode is retained after logout).
*/
export const clearLocalStorageExcept = (keysToPreserve: string[]) => {
try {
const preserve = new Set(keysToPreserve);
const keysToRemove: string[] = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key && !preserve.has(key)) {
keysToRemove.push(key);
}
}
keysToRemove.forEach((key) => localStorage.removeItem(key));
} catch {
// localStorage may be unavailable
}
};
|