-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support zen mode sidebar entry timeline selector
Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
10 changed files
with
153 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 13 additions & 10 deletions
23
apps/renderer/src/components/ui/modal/components/close.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
apps/renderer/src/modules/entry-column/hooks/useEntryIdListSnap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { atom, useAtomValue, useSetAtom } from "jotai" | ||
import { useEffect, useMemo, useState } from "react" | ||
|
||
/** | ||
* This is a global atom to store the current entry column's entry id list snapshot. | ||
* It used to get current entry id list(keep sorted) in other components. | ||
*/ | ||
const globalEntryIdListSnapAtom = atom<string[]>([]) | ||
export const useSnapEntryIdList = (ids: string[]) => { | ||
const set = useSetAtom(globalEntryIdListSnapAtom) | ||
useEffect(() => { | ||
set(ids) | ||
}, [ids, set]) | ||
} | ||
|
||
export const useGetEntryIdInRange = (id: string, range: [number, number]) => { | ||
const snap = useAtomValue(globalEntryIdListSnapAtom) | ||
const [stableRange] = useState(range) | ||
return useMemo(() => { | ||
const index = snap.indexOf(id) | ||
|
||
return snap.slice( | ||
Math.max(0, index - stableRange[0]), | ||
Math.min(snap.length, index + stableRange[1]), | ||
) | ||
}, [id, snap, stableRange]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
apps/renderer/src/modules/entry-content/components/EntryTimelineSidebar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/EllipsisWithTooltip.js" | ||
import { cn } from "@follow/utils/utils" | ||
import type { Target, TargetAndTransition } from "framer-motion" | ||
import { m } from "framer-motion" | ||
|
||
import { useIsZenMode } from "~/atoms/settings/ui" | ||
import { useAsRead } from "~/hooks/biz/useAsRead" | ||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry" | ||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams" | ||
import { useGetEntryIdInRange } from "~/modules/entry-column/hooks/useEntryIdListSnap" | ||
import { useEntry } from "~/store/entry" | ||
|
||
export const EntryTimelineSidebar = ({ entryId }: { entryId: string }) => { | ||
const isZenMode = useIsZenMode() | ||
|
||
if (!isZenMode) { | ||
return null | ||
} | ||
|
||
return <Timeline entryId={entryId} /> | ||
} | ||
|
||
const Timeline = ({ entryId }: { entryId: string }) => { | ||
const entryIds = useGetEntryIdInRange(entryId, [5, 5]) | ||
|
||
return ( | ||
<m.div | ||
className="absolute left-8 top-28 z-10 @lg:max-w-0 @6xl:max-w-[200px] @7xl:max-w-[200px] @[90rem]:max-w-[250px]" | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1, transition: { delay: 0.5 } }} | ||
> | ||
{entryIds.map((id) => ( | ||
<TimelineItem key={id} id={id} /> | ||
))} | ||
</m.div> | ||
) | ||
} | ||
|
||
const initialButton: Target = { | ||
opacity: 0.0001, | ||
} | ||
const animateButton: TargetAndTransition = { | ||
opacity: 1, | ||
} | ||
|
||
const TimelineItem = ({ id }: { id: string }) => { | ||
const entry = useEntry(id, (e) => ({ | ||
title: e.entries.title, | ||
read: e.read, | ||
})) | ||
const asRead = useAsRead(entry!) | ||
const navigate = useNavigateEntry() | ||
|
||
const isActive = useRouteParamsSelector((r) => r.entryId === id) | ||
|
||
return ( | ||
<m.button | ||
layoutId={`timeline-${id}`} | ||
initial={initialButton} | ||
animate={animateButton} | ||
className={"relative block min-w-0 max-w-full cursor-pointer text-xs leading-loose"} | ||
type="button" | ||
onClick={() => navigate({ entryId: id })} | ||
> | ||
{!asRead && ( | ||
<span className="absolute -left-4 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent opacity-50" /> | ||
)} | ||
<EllipsisHorizontalTextWithTooltip | ||
className={cn( | ||
"truncate transition-[opacity,font-weight] duration-200", | ||
isActive ? "font-medium opacity-100" : "opacity-60 hover:opacity-80", | ||
)} | ||
> | ||
{entry?.title} | ||
</EllipsisHorizontalTextWithTooltip> | ||
</m.button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters