diff --git a/package.json b/package.json
index 429cffa48..0ebd9fe48 100644
--- a/package.json
+++ b/package.json
@@ -54,6 +54,7 @@
"electron-updater": "^6.1.7",
"framer-motion": "11.2.6",
"hast-util-to-jsx-runtime": "2.3.0",
+ "jotai": "2.8.1",
"lethargy": "1.0.9",
"lucide-react": "0.379.0",
"ofetch": "1.3.4",
@@ -69,7 +70,8 @@
"unified": "11.0.4",
"unist-util-visit": "5.0.0",
"vfile": "6.0.1",
- "zod": "3.23.8"
+ "zod": "3.23.8",
+ "zustand": "4.5.2"
},
"devDependencies": {
"@egoist/tailwindcss-icons": "1.8.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 867a179a2..285eccfc5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -101,6 +101,9 @@ importers:
hast-util-to-jsx-runtime:
specifier: 2.3.0
version: 2.3.0
+ jotai:
+ specifier: 2.8.1
+ version: 2.8.1(@types/react@18.3.3)(react@18.3.1)
lethargy:
specifier: 1.0.9
version: 1.0.9
@@ -149,6 +152,9 @@ importers:
zod:
specifier: 3.23.8
version: 3.23.8
+ zustand:
+ specifier: 4.5.2
+ version: 4.5.2(@types/react@18.3.3)(react@18.3.1)
devDependencies:
'@egoist/tailwindcss-icons':
specifier: 1.8.0
@@ -3433,6 +3439,18 @@ packages:
jose@5.3.0:
resolution: {integrity: sha512-IChe9AtAE79ru084ow8jzkN2lNrG3Ntfiv65Cvj9uOCE2m5LNsdHG+9EbxWxAoWRF9TgDOqLN5jm08++owDVRg==}
+ jotai@2.8.1:
+ resolution: {integrity: sha512-Gmk5Y3yJL/vN5S0rQ6AaWpXH5Q+HBGHThMHXfylVzXGVuO8YxPRtZf8Y9XYvl+h7ZMQXoHNdFi37vNsJFsiszQ==}
+ engines: {node: '>=12.20.0'}
+ peerDependencies:
+ '@types/react': '>=17.0.0'
+ react: '>=17.0.0'
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ react:
+ optional: true
+
js-tokens@4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
@@ -4809,6 +4827,11 @@ packages:
'@types/react':
optional: true
+ use-sync-external-store@1.2.0:
+ resolution: {integrity: sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==}
+ peerDependencies:
+ react: ^16.8.0 || ^17.0.0 || ^18.0.0
+
utf8-byte-length@1.0.4:
resolution: {integrity: sha512-4+wkEYLBbWxqTahEsWrhxepcoVOJ+1z5PGIjPZxRkytcdSUaNjIjBM7Xn8E+pdSuV7SzvWovBFA54FO0JSoqhA==}
@@ -4964,6 +4987,21 @@ packages:
zod@3.23.8:
resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==}
+ zustand@4.5.2:
+ resolution: {integrity: sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==}
+ engines: {node: '>=12.7.0'}
+ peerDependencies:
+ '@types/react': '>=16.8'
+ immer: '>=9.0.6'
+ react: '>=16.8'
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ immer:
+ optional: true
+ react:
+ optional: true
+
zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
@@ -8833,6 +8871,11 @@ snapshots:
jose@5.3.0: {}
+ jotai@2.8.1(@types/react@18.3.3)(react@18.3.1):
+ optionalDependencies:
+ '@types/react': 18.3.3
+ react: 18.3.1
+
js-tokens@4.0.0: {}
js-yaml@4.1.0:
@@ -10385,6 +10428,10 @@ snapshots:
optionalDependencies:
'@types/react': 18.3.3
+ use-sync-external-store@1.2.0(react@18.3.1):
+ dependencies:
+ react: 18.3.1
+
utf8-byte-length@1.0.4: {}
util-deprecate@1.0.2: {}
@@ -10517,4 +10564,11 @@ snapshots:
zod@3.23.8: {}
+ zustand@4.5.2(@types/react@18.3.3)(react@18.3.1):
+ dependencies:
+ use-sync-external-store: 1.2.0(react@18.3.1)
+ optionalDependencies:
+ '@types/react': 18.3.3
+ react: 18.3.1
+
zwitch@2.0.4: {}
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index f010577ce..3007ad242 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -1,5 +1,8 @@
+import { Provider } from "jotai"
import { Outlet } from "react-router-dom"
+import { jotaiStore } from "./lib/jotai"
+
function App() {
return (
<>
@@ -7,7 +10,9 @@ function App() {
className="drag-region absolute inset-x-0 top-0 h-10 shrink-0"
aria-hidden
/>
-
+
+
+
>
)
}
diff --git a/src/renderer/src/components/entry-column/index.tsx b/src/renderer/src/components/entry-column/index.tsx
index 9a784a5a3..41cc35133 100644
--- a/src/renderer/src/components/entry-column/index.tsx
+++ b/src/renderer/src/components/entry-column/index.tsx
@@ -1,6 +1,6 @@
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
-import { useEntries } from "@renderer/queries/entries"
import { cn } from "@renderer/lib/utils"
+import { useEntries } from "@renderer/queries/entries"
+import { feedActions, useFeedStore } from "@renderer/store"
import { m } from "framer-motion"
import { ArticleItem } from "./article-item"
@@ -13,7 +13,7 @@ import { VideoItem } from "./video-item"
const gridMode = new Set([2, 3])
export function EntryColumn() {
- const { activeList, setActiveEntry } = useMainLayoutContext()
+ const activeList = useFeedStore((state) => state.activeList)
const entries = useEntries({
level: activeList?.level,
id: activeList?.id,
@@ -46,7 +46,7 @@ export function EntryColumn() {
Item = ArticleItem
}
}
-
+ const { setActiveEntry } = feedActions
return (
setActiveEntry(null)}>
diff --git a/src/renderer/src/components/entry-column/item-wrapper.tsx b/src/renderer/src/components/entry-column/item-wrapper.tsx
index 07d54f803..83d10525a 100644
--- a/src/renderer/src/components/entry-column/item-wrapper.tsx
+++ b/src/renderer/src/components/entry-column/item-wrapper.tsx
@@ -1,8 +1,8 @@
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
import { useEntryActions } from "@renderer/hooks/useEntryActions"
import { showNativeMenu } from "@renderer/lib/native-menu"
import type { EntriesResponse } from "@renderer/lib/types"
import { cn } from "@renderer/lib/utils"
+import { feedActions, useFeedStore } from "@renderer/store"
export function EntryItemWrapper({
entry,
@@ -18,7 +18,9 @@ export function EntryItemWrapper({
entry,
})
- const { activeEntry, setActiveEntry } = useMainLayoutContext()
+ const activeEntry = useFeedStore(
+ (state) => state.activeEntry,
+ )
if (!entry?.url || view === undefined) return children
return (
@@ -30,7 +32,7 @@ export function EntryItemWrapper({
)}
onClick={(e) => {
e.stopPropagation()
- setActiveEntry(entry.id)
+ feedActions.setActiveEntry(entry.id)
}}
onDoubleClick={() => window.open(entry.url, "_blank")}
onContextMenu={(e) => {
diff --git a/src/renderer/src/components/feed-column/category.tsx b/src/renderer/src/components/feed-column/category.tsx
index bf9719fb0..274599610 100644
--- a/src/renderer/src/components/feed-column/category.tsx
+++ b/src/renderer/src/components/feed-column/category.tsx
@@ -3,13 +3,13 @@ import {
CollapsibleTrigger,
} from "@renderer/components/ui/collapsible"
import { Dialog } from "@renderer/components/ui/dialog"
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
import { client } from "@renderer/lib/client"
import { levels } from "@renderer/lib/constants"
import { showNativeMenu } from "@renderer/lib/native-menu"
import { cn } from "@renderer/lib/utils"
import { apiFetch } from "@renderer/queries/api-fetch"
import type { Response as SubscriptionsResponse } from "@renderer/queries/subscriptions"
+import { feedActions, useFeedActiveList } from "@renderer/store"
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { AnimatePresence, m } from "framer-motion"
import { useEffect, useState } from "react"
@@ -17,6 +17,8 @@ import { useEffect, useState } from "react"
import { CategoryRenameDialog } from "./category-rename-dialog"
import { FeedItem } from "./item"
+const { setActiveList } = feedActions
+
export function FeedCategory({
data,
view,
@@ -26,7 +28,7 @@ export function FeedCategory({
view?: number
expansion: boolean
}) {
- const { activeList, setActiveList } = useMainLayoutContext()
+ const activeList = useFeedActiveList()
const [open, setOpen] = useState(!data.name)
const [dialogOpen, setDialogOpen] = useState(false)
diff --git a/src/renderer/src/components/feed-column/index.tsx b/src/renderer/src/components/feed-column/index.tsx
index 68ff33362..51f406903 100644
--- a/src/renderer/src/components/feed-column/index.tsx
+++ b/src/renderer/src/components/feed-column/index.tsx
@@ -6,9 +6,9 @@ import {
TooltipTrigger,
} from "@renderer/components/ui/tooltip"
import { UserButton } from "@renderer/components/user-button"
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
import { levels, views } from "@renderer/lib/constants"
import { clamp, cn } from "@renderer/lib/utils"
+import { feedActions } from "@renderer/store"
import { useWheel } from "@use-gesture/react"
import { m, useSpring } from "framer-motion"
import { Lethargy } from "lethargy"
@@ -20,7 +20,7 @@ import { FeedList } from "./list"
const lethargy = new Lethargy()
export function FeedColumn() {
- const { setActiveList } = useMainLayoutContext()
+ const { setActiveList } = feedActions
const carouselRef = useRef
(null)
const [active, setActive] = useState(0)
diff --git a/src/renderer/src/components/feed-column/item.tsx b/src/renderer/src/components/feed-column/item.tsx
index 207e13bc2..837c3add9 100644
--- a/src/renderer/src/components/feed-column/item.tsx
+++ b/src/renderer/src/components/feed-column/item.tsx
@@ -10,13 +10,13 @@ import {
TooltipTrigger,
} from "@renderer/components/ui/tooltip"
import { useToast } from "@renderer/components/ui/use-toast"
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
import { levels } from "@renderer/lib/constants"
import dayjs from "@renderer/lib/dayjs"
import { showNativeMenu } from "@renderer/lib/native-menu"
import type { SubscriptionResponse } from "@renderer/lib/types"
import { cn } from "@renderer/lib/utils"
import { apiFetch } from "@renderer/queries/api-fetch"
+import { feedActions, useFeedActiveList } from "@renderer/store"
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { useState } from "react"
@@ -30,7 +30,8 @@ export function FeedItem({
className?: string
}) {
const [dialogOpen, setDialogOpen] = useState(false)
- const { activeList, setActiveList } = useMainLayoutContext()
+ const activeList = useFeedActiveList()
+ const { setActiveList } = feedActions
const setFeedActive = (feed: SubscriptionResponse[number]) => {
view !== undefined &&
@@ -107,10 +108,12 @@ export function FeedItem({
e.stopPropagation()
setFeedActive(feed)
}}
- onDoubleClick={() => window.open(
+ onDoubleClick={() => {
+ window.open(
`${import.meta.env.VITE_WEB_URL}/feed/${feed.feedId}`,
"_blank",
- )}
+ )
+ }}
onContextMenu={(e) => {
showNativeMenu(
[
diff --git a/src/renderer/src/components/feed-column/list.tsx b/src/renderer/src/components/feed-column/list.tsx
index 49ae72eb9..27e4f8aa8 100644
--- a/src/renderer/src/components/feed-column/list.tsx
+++ b/src/renderer/src/components/feed-column/list.tsx
@@ -1,7 +1,7 @@
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
import { levels, views } from "@renderer/lib/constants"
import { cn } from "@renderer/lib/utils"
import { useSubscriptions } from "@renderer/queries/subscriptions"
+import { feedActions } from "@renderer/store"
import { useState } from "react"
import { FeedCategory } from "./category"
@@ -17,7 +17,7 @@ export function FeedList({
}) {
const subscriptions = useSubscriptions(view)
const [expansion, setExpansion] = useState(false)
- const { setActiveList } = useMainLayoutContext()
+ const { setActiveList } = feedActions
return (
diff --git a/src/renderer/src/contexts/outlet/main-layout.tsx b/src/renderer/src/contexts/outlet/main-layout.tsx
deleted file mode 100644
index 0f8e0800e..000000000
--- a/src/renderer/src/contexts/outlet/main-layout.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import type { ActiveEntry, ActiveList } from "@renderer/lib/types"
-import { Outlet, useOutletContext } from "react-router-dom"
-
-export interface MainLayoutContextType {
- activeList: ActiveList
- setActiveEntry: (value: ActiveEntry) => void
-
- activeEntry: ActiveEntry
- setActiveList: ((value: ActiveList) => void) | undefined
-}
-
-export const useMainLayoutContext = () =>
- useOutletContext
()
-
-export const MainLayoutOutlet = (ctxValue: MainLayoutContextType) => (
-
-)
diff --git a/src/renderer/src/lib/jotai.ts b/src/renderer/src/lib/jotai.ts
new file mode 100644
index 000000000..8f41ca01d
--- /dev/null
+++ b/src/renderer/src/lib/jotai.ts
@@ -0,0 +1,3 @@
+import { createStore } from "jotai"
+
+export const jotaiStore = createStore()
diff --git a/src/renderer/src/pages/(main)/(context)/index.tsx b/src/renderer/src/pages/(main)/(context)/index.tsx
index f8812ef37..ee04f3109 100644
--- a/src/renderer/src/pages/(main)/(context)/index.tsx
+++ b/src/renderer/src/pages/(main)/(context)/index.tsx
@@ -1,14 +1,24 @@
import { EntryColumn } from "@renderer/components/entry-column"
import { EntryContent } from "@renderer/components/entry-content"
-import { useMainLayoutContext } from "@renderer/contexts/outlet/main-layout"
import { cn } from "@renderer/lib/utils"
+import {
+ feedActions,
+ useFeedStore,
+} from "@renderer/store"
import { AnimatePresence } from "framer-motion"
import { useEffect } from "react"
+import { useShallow } from "zustand/react/shallow"
const wideMode = new Set([1, 2, 3, 4])
export function Component() {
- const { activeList, activeEntry, setActiveEntry } = useMainLayoutContext()
+ const { activeEntry, activeList } = useFeedStore(
+ useShallow((state) => ({
+ activeList: state.activeList,
+ activeEntry: state.activeEntry,
+ })),
+ )
+ const { setActiveEntry } = feedActions
useEffect(() => {
setActiveEntry(null)
}, [activeList])
@@ -18,9 +28,7 @@ export function Component() {
diff --git a/src/renderer/src/pages/(main)/(context)/layout.tsx b/src/renderer/src/pages/(main)/(context)/layout.tsx
index dfb2e4b93..adbda0015 100644
--- a/src/renderer/src/pages/(main)/(context)/layout.tsx
+++ b/src/renderer/src/pages/(main)/(context)/layout.tsx
@@ -1,25 +1,14 @@
import { FeedColumn } from "@renderer/components/feed-column"
-import {
- MainLayoutOutlet,
- useMainLayoutContext,
-} from "@renderer/contexts/outlet/main-layout"
+import { Outlet } from "react-router-dom"
export function Component() {
- const { activeEntry, activeList, setActiveList, setActiveEntry } =
- useMainLayoutContext()
return (
)
}
diff --git a/src/renderer/src/pages/(main)/layout.tsx b/src/renderer/src/pages/(main)/layout.tsx
index a1e0c7b7b..06aad7ac4 100644
--- a/src/renderer/src/pages/(main)/layout.tsx
+++ b/src/renderer/src/pages/(main)/layout.tsx
@@ -1,39 +1,25 @@
import { useSession } from "@hono/auth-js/react"
-import { MainLayoutOutlet } from "@renderer/contexts/outlet/main-layout"
-import type { ActiveEntry, ActiveList } from "@renderer/lib/types"
-import { useEffect, useState } from "react"
-import { useNavigate } from "react-router-dom"
+import { feedActions, useFeedStore } from "@renderer/store"
+import { useEffect } from "react"
+import { Outlet, useNavigate } from "react-router-dom"
export function Component() {
const { status } = useSession()
const navigate = useNavigate()
- const [activeList, setActiveList] = useState
({
- level: "view",
- id: 0,
- name: "Articles",
- view: 0,
- })
- const [activeEntry, setActiveEntry] = useState(null)
+ const preventNavigate = useFeedStore(
+ (state) => state.activeList?.preventNavigate,
+ )
useEffect(() => {
- setActiveEntry(null)
- if (!activeList?.preventNavigate) {
+ feedActions.setActiveEntry(null)
+ if (!preventNavigate) {
navigate("/")
}
- }, [activeList])
+ }, [navigate, preventNavigate])
if (status !== "authenticated") {
return navigate("/login")
}
- return (
-
- )
+ return
}
diff --git a/src/renderer/src/store/feed.ts b/src/renderer/src/store/feed.ts
new file mode 100644
index 000000000..9e77dfca1
--- /dev/null
+++ b/src/renderer/src/store/feed.ts
@@ -0,0 +1,34 @@
+import type { ActiveEntry, ActiveList } from "@renderer/lib/types"
+import { create } from "zustand"
+
+interface FeedStoreActions {
+ setActiveList: ((value: ActiveList) => void) | undefined
+ setActiveEntry: (value: ActiveEntry) => void
+}
+interface FeedStoreState {
+ activeList: ActiveList
+ activeEntry: ActiveEntry
+}
+
+type FeedStore = FeedStoreState & { actions: Readonly }
+export const useFeedStore = create((set) => ({
+ activeList: {
+ level: "view",
+ id: 0,
+ name: "Articles",
+ view: 0,
+ },
+ activeEntry: null,
+
+ // Actions
+
+ actions: {
+ setActiveEntry: (value) => set({ activeEntry: value }),
+ setActiveList: (value) => set({ activeList: value }),
+ },
+}))
+
+export const feedActions = useFeedStore.getState().actions
+
+/** Hooks */
+export const useFeedActiveList = () => useFeedStore((state) => state.activeList)
diff --git a/src/renderer/src/store/index.ts b/src/renderer/src/store/index.ts
new file mode 100644
index 000000000..0b2a3adbd
--- /dev/null
+++ b/src/renderer/src/store/index.ts
@@ -0,0 +1 @@
+export * from './feed';