Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add a basic local storage wrapper

Manav Rathi9c5873140379
diff --git a/packages/ui/i18n.ts b/packages/ui/i18n.ts
index 7900a3a7b8..32174c6960 100644
--- a/packages/ui/i18n.ts
+++ b/packages/ui/i18n.ts
@@ -25,7 +25,7 @@ export const supportedLocales = [
"es-ES" /* Spanish */,
] as const;
-/** The type of {@link supportedLocale}s. */
+/** The type of {@link supportedLocales}. */
export type SupportedLocale = (typeof supportedLocales)[number];
/**
diff --git a/packages/utils/local-storage.ts b/packages/utils/local-storage.ts
new file mode 100644
index 0000000000..b32377f585
--- /dev/null
+++ b/packages/utils/local-storage.ts
@@ -0,0 +1,33 @@
+/**
+ * Keys corresponding to the values that we save in local storage.
+ *
+ * The type of each of the these keys is {@link LSKey}.
+ *
+ * Note: [Local Storage]
+ *
+ * Data in the local storage is persisted even after the user closes the tab (or
+ * the browser itself). This is in contrast with session storage, where the data
+ * is cleared when the browser tab is closed.
+ *
+ * The data in local storage is tied to the Document's origin (scheme + host).
+ */
+export const lsKeys = ["locale"] as const;
+
+/** The type of {@link lsKeys}. */
+export type LSKey = (typeof lsKeys)[number];
+
+/**
+ * Read a previously saved string value from local storage
+ */
+export const getLSString = (key: LSKey) => {
+ const value = localStorage.getItem(key);
+ if (value === null) return undefined;
+ return value;
+};
+
+/**
+ * Save a string value in local storage
+ */
+export const setLSString = (key: LSKey, value: string) => {
+ localStorage.setItem(key, value);
+};