+3
-1
@@ -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",
|
||||
|
||||
Generated
+54
@@ -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: {}
|
||||
|
||||
@@ -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
|
||||
/>
|
||||
<Outlet />
|
||||
<Provider store={jotaiStore}>
|
||||
<Outlet />
|
||||
</Provider>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<div className="px-2" onClick={() => setActiveEntry(null)}>
|
||||
<div className="mb-5 ml-9">
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<HTMLDivElement>(null)
|
||||
|
||||
const [active, setActive] = useState(0)
|
||||
|
||||
@@ -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(
|
||||
[
|
||||
|
||||
@@ -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 (
|
||||
<div className={className}>
|
||||
|
||||
@@ -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<MainLayoutContextType>()
|
||||
|
||||
export const MainLayoutOutlet = (ctxValue: MainLayoutContextType) => (
|
||||
<Outlet context={ctxValue} />
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
import { createStore } from "jotai"
|
||||
|
||||
export const jotaiStore = createStore()
|
||||
@@ -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() {
|
||||
<div
|
||||
className={cn(
|
||||
"h-full shrink-0 overflow-y-auto border-r pt-10",
|
||||
activeList && wideMode.has(activeList.view) ?
|
||||
"flex-1" :
|
||||
"w-[340px]",
|
||||
activeList && wideMode.has(activeList.view) ? "flex-1" : "w-[340px]",
|
||||
)}
|
||||
>
|
||||
<EntryColumn />
|
||||
|
||||
@@ -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 (
|
||||
<div className="flex h-full">
|
||||
<div className="w-64 shrink-0 border-r bg-native pt-10">
|
||||
<FeedColumn />
|
||||
</div>
|
||||
<MainLayoutOutlet
|
||||
{...{
|
||||
activeList,
|
||||
activeEntry,
|
||||
setActiveList,
|
||||
setActiveEntry,
|
||||
}}
|
||||
/>
|
||||
|
||||
<Outlet />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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<ActiveList>({
|
||||
level: "view",
|
||||
id: 0,
|
||||
name: "Articles",
|
||||
view: 0,
|
||||
})
|
||||
const [activeEntry, setActiveEntry] = useState<ActiveEntry>(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 (
|
||||
<MainLayoutOutlet
|
||||
{...{
|
||||
activeList,
|
||||
activeEntry,
|
||||
setActiveEntry,
|
||||
setActiveList,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
@@ -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<FeedStoreActions> }
|
||||
export const useFeedStore = create<FeedStore>((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)
|
||||
@@ -0,0 +1 @@
|
||||
export * from './feed';
|
||||
Reference in New Issue
Block a user