Skip to content

Commit a162b3b

Browse files
committed
feat(wide-mode): support esc to return back
Signed-off-by: Innei <i@innei.in>
1 parent 7ef5dfc commit a162b3b

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

apps/renderer/src/lib/error-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const toastFetchError = (
7878
className: cn(
7979
"relative z-[1] float-end -mt-1",
8080
"border-transparent bg-theme-background text-theme-foreground opacity-60 transition-opacity",
81-
"hover:bg-theme-button-hover hover:opacity-100 focus:border-theme-foreground/80",
81+
"hover:bg-theme-button-hover hover:opacity-100 focus:border-theme-foreground/20",
8282
),
8383
key: "copy",
8484
value: _reason,

apps/renderer/src/modules/feed-column/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export function FeedColumn({ children, className }: PropsWithChildren<{ classNam
155155
{views.map((item, index) => (
156156
<ActionButton
157157
key={item.name}
158-
// TODO: fix this type error
159158
tooltip={t(item.name)}
160159
shortcut={`${index + 1}`}
161160
className={cn(

apps/renderer/src/modules/feed-column/list.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,24 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
234234
)
235235
}
236236

237+
const LIST = [
238+
{ icon: "i-mgc-sort-ascending-cute-re", by: "count", order: "asc" },
239+
{ icon: "i-mgc-sort-descending-cute-re", by: "count", order: "desc" },
240+
241+
{
242+
icon: "i-mgc-az-sort-descending-letters-cute-re",
243+
by: "alphabetical",
244+
order: "asc",
245+
},
246+
{
247+
icon: "i-mgc-az-sort-ascending-letters-cute-re",
248+
by: "alphabetical",
249+
order: "desc",
250+
},
251+
] as const
237252
const SortButton = () => {
238253
const { by, order } = useFeedListSort()
239254
const { t } = useTranslation()
240-
const LIST = [
241-
{ icon: "i-mgc-sort-ascending-cute-re", by: "count", order: "asc" },
242-
{ icon: "i-mgc-sort-descending-cute-re", by: "count", order: "desc" },
243-
244-
{
245-
icon: "i-mgc-az-sort-descending-letters-cute-re",
246-
by: "alphabetical",
247-
order: "asc",
248-
},
249-
{
250-
icon: "i-mgc-az-sort-ascending-letters-cute-re",
251-
by: "alphabetical",
252-
order: "desc",
253-
},
254-
] as const
255255

256256
const [open, setOpen] = useState(false)
257257

apps/renderer/src/pages/(main)/(layer)/feeds/[feedId]/[entryId]/index.tsx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { AnimatePresence } from "framer-motion"
1+
import { useWheel } from "@use-gesture/react"
2+
import { AnimatePresence, easeOut } from "framer-motion"
3+
import { useRef } from "react"
4+
import { useHotkeys } from "react-hotkeys-hook"
25
import { useParams } from "react-router-dom"
36

47
import { useUISettingKey } from "~/atoms/settings/ui"
58
import { useFeedColumnShow, useFeedColumnTempShow } from "~/atoms/sidebar"
69
import { m } from "~/components/common/Motion"
710
import { ActionButton } from "~/components/ui/button"
8-
import { ROUTE_ENTRY_PENDING, views } from "~/constants"
11+
import { HotKeyScopeMap, ROUTE_ENTRY_PENDING, views } from "~/constants"
912
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
1013
import { useRouteView } from "~/hooks/biz/useRouteParams"
1114
import { cn } from "~/lib/utils"
@@ -19,22 +22,52 @@ export const Component = () => {
1922

2023
const settingWideMode = useUISettingKey("wideMode")
2124
const realEntryId = entryId === ROUTE_ENTRY_PENDING ? "" : entryId
22-
const disable = views[view].wideMode || (settingWideMode && !realEntryId)
25+
const inEntryContentWideMode = !(views[view].wideMode || (settingWideMode && !realEntryId))
2326
const wideMode = settingWideMode && realEntryId
2427
const feedColumnTempShow = useFeedColumnTempShow()
2528
const feedColumnShow = useFeedColumnShow()
2629
const shouldHeaderPaddingLeft = feedColumnTempShow && !feedColumnShow && settingWideMode
2730

31+
useHotkeys(
32+
"Escape",
33+
() => {
34+
if (inEntryContentWideMode) {
35+
navigate({ entryId: null })
36+
}
37+
},
38+
{
39+
enabled: inEntryContentWideMode,
40+
scopes: HotKeyScopeMap.Home,
41+
preventDefault: true,
42+
},
43+
)
44+
const carouselRef = useRef<HTMLDivElement>(null)
45+
46+
useWheel(
47+
({ delta: [dex] }) => {
48+
if (dex < -50) {
49+
navigate({ entryId: null })
50+
}
51+
},
52+
{
53+
enabled: inEntryContentWideMode,
54+
target: carouselRef,
55+
eventOptions: { capture: true },
56+
axis: "x",
57+
},
58+
)
59+
2860
return (
2961
<AnimatePresence>
3062
<AppLayoutGridContainerProvider>
3163
<AnimatePresence>
32-
{!disable && (
64+
{inEntryContentWideMode && (
3365
<m.div
66+
ref={carouselRef}
3467
// slide up
3568
initial={{ opacity: 0, y: 100 }}
3669
animate={{ opacity: 1, y: 0 }}
37-
exit={{ opacity: 0, y: 100 }}
70+
exit={{ opacity: 0, y: 100, transition: { duration: 0.2, ease: easeOut } }}
3871
transition={{ duration: 0.2, type: "spring" }}
3972
className={cn(
4073
"flex min-w-0 flex-1 flex-col",
@@ -54,12 +87,13 @@ export const Component = () => {
5487
<i className="i-mgc-close-cute-re size-5" />
5588
</ActionButton>
5689
)}
90+
5791
<EntryContent
5892
entryId={realEntryId}
5993
classNames={{
6094
header: shouldHeaderPaddingLeft
61-
? "ml-[calc(theme(width.feed-col)+theme(width.12))]"
62-
: "ml-12",
95+
? "ml-[calc(theme(width.feed-col)+theme(width.8))]"
96+
: "ml-8",
6397
}}
6498
/>
6599
</m.div>

0 commit comments

Comments
 (0)