From 4f17ea61cbb11a72712a1ea8c98904a1cc513e41 Mon Sep 17 00:00:00 2001
From: Mohamed Bassem <me@mbassem.com>
Date: Sun, 14 Apr 2024 00:51:56 +0300
Subject: feature(web): Allow changing the bookmark grid layout (#98)

---
 apps/web/lib/userLocalSettings/bookmarksLayout.tsx | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 apps/web/lib/userLocalSettings/bookmarksLayout.tsx

(limited to 'apps/web/lib/userLocalSettings/bookmarksLayout.tsx')

diff --git a/apps/web/lib/userLocalSettings/bookmarksLayout.tsx b/apps/web/lib/userLocalSettings/bookmarksLayout.tsx
new file mode 100644
index 00000000..424046b9
--- /dev/null
+++ b/apps/web/lib/userLocalSettings/bookmarksLayout.tsx
@@ -0,0 +1,37 @@
+"use client";
+
+import type { z } from "zod";
+import { createContext, useContext } from "react";
+
+import type { BookmarksLayoutTypes, zUserLocalSettings } from "./types";
+
+const defaultLayout: BookmarksLayoutTypes = "masonry";
+
+export const UserLocalSettingsCtx = createContext<
+  z.infer<typeof zUserLocalSettings>
+>({
+  bookmarkGridLayout: defaultLayout,
+});
+
+function useUserLocalSettings() {
+  return useContext(UserLocalSettingsCtx);
+}
+
+export function useBookmarkLayout() {
+  const settings = useUserLocalSettings();
+  return settings.bookmarkGridLayout;
+}
+
+export function bookmarkLayoutSwitch<T>(
+  layout: BookmarksLayoutTypes,
+  data: Record<BookmarksLayoutTypes, T>,
+) {
+  return data[layout];
+}
+
+export function useBookmarkLayoutSwitch<T>(
+  data: Record<BookmarksLayoutTypes, T>,
+) {
+  const layout = useBookmarkLayout();
+  return data[layout];
+}
-- 
cgit v1.2.3-70-g09d2

