From 097e6dd4a5833898c6fc039530b2f021d0af9da3 Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 6 Oct 2024 18:15:28 +0800 Subject: [PATCH] refactor: entry content gird container Signed-off-by: Innei --- .../src/components/ui/button/index.tsx | 6 +- apps/renderer/src/components/ui/kbd/Kbd.tsx | 3 + .../entry-column/layouts/EntryListHeader.tsx | 4 +- .../components/EntryReadHistory.tsx | 9 +- .../src/modules/entry-content/index.tsx | 5 +- .../feeds/[feedId]/[entryId]/index.tsx | 133 +++++++++++------- icons/mgc/layout_4_cute_re.svg | 1 + locales/app/en.json | 2 +- locales/app/zh-CN.json | 2 +- 9 files changed, 103 insertions(+), 62 deletions(-) create mode 100644 icons/mgc/layout_4_cute_re.svg diff --git a/apps/renderer/src/components/ui/button/index.tsx b/apps/renderer/src/components/ui/button/index.tsx index 1b59b4338..3c053e102 100644 --- a/apps/renderer/src/components/ui/button/index.tsx +++ b/apps/renderer/src/components/ui/button/index.tsx @@ -26,6 +26,7 @@ interface ActionButtonProps { active?: boolean disabled?: boolean shortcut?: string + disableTriggerShortcut?: boolean } export const ActionButton = React.forwardRef< @@ -43,6 +44,7 @@ export const ActionButton = React.forwardRef< active, shortcut, disabled, + disableTriggerShortcut, ...rest }, ref, @@ -78,7 +80,9 @@ export const ActionButton = React.forwardRef< ) return ( <> - {shortcut && buttonRef.current?.click()} />} + {shortcut && !disableTriggerShortcut && ( + buttonRef.current?.click()} /> + )} {tooltip ? ( {Trigger} diff --git a/apps/renderer/src/components/ui/kbd/Kbd.tsx b/apps/renderer/src/components/ui/kbd/Kbd.tsx index a2026c75c..d09750550 100644 --- a/apps/renderer/src/components/ui/kbd/Kbd.tsx +++ b/apps/renderer/src/components/ui/kbd/Kbd.tsx @@ -18,18 +18,21 @@ const SpecialKeys = { ctrl: "Ctrl", alt: "Alt", shift: "Shift", + escape: "Esc", }, macOS: { meta: "⌘", ctrl: "⌃", alt: "⌥", shift: "⇧", + escape: "⎋", }, Linux: { meta: "Super", ctrl: "Ctrl", alt: "Alt", shift: "Shift", + escape: "Escape", }, } // @ts-ignore diff --git a/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx b/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx index 2cdb1c338..5544eb85c 100644 --- a/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx +++ b/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx @@ -257,9 +257,7 @@ const WideModeButton = () => { : t("entry_list_header.switch_to_normalmode") } > - + ) diff --git a/apps/renderer/src/modules/entry-content/components/EntryReadHistory.tsx b/apps/renderer/src/modules/entry-content/components/EntryReadHistory.tsx index 81539c79f..d83672df5 100644 --- a/apps/renderer/src/modules/entry-content/components/EntryReadHistory.tsx +++ b/apps/renderer/src/modules/entry-content/components/EntryReadHistory.tsx @@ -22,6 +22,11 @@ import { useUserById } from "~/store/user" import { usePresentUserProfileModal } from "../../profile/hooks" +const getLimit = (width: number): number => { + if (width > 900) return 15 + if (width > 600) return 10 + return 5 +} export const EntryReadHistory: Component<{ entryId: string }> = ({ entryId }) => { const me = useWhoami() const entryHistory = useEntryReadHistory(entryId) @@ -33,7 +38,7 @@ export const EntryReadHistory: Component<{ entryId: string }> = ({ entryId }) => const appGirdContainerWidth = useAppLayoutGridContainerWidth() - const LIMIT = appGirdContainerWidth > 600 ? 10 : 5 + const LIMIT = getLimit(appGirdContainerWidth) if (!entryHistory) return null if (!me) return null @@ -56,7 +61,7 @@ export const EntryReadHistory: Component<{ entryId: string }> = ({ entryId }) => type="button" style={{ right: `${LIMIT * 8}px`, - zIndex: 11, + zIndex: LIMIT + 1, }} className="no-drag-region relative flex size-7 items-center justify-center rounded-full border border-border bg-muted ring-2 ring-background" > diff --git a/apps/renderer/src/modules/entry-content/index.tsx b/apps/renderer/src/modules/entry-content/index.tsx index 6206f0050..169da3f1b 100644 --- a/apps/renderer/src/modules/entry-content/index.tsx +++ b/apps/renderer/src/modules/entry-content/index.tsx @@ -67,9 +67,12 @@ export const EntryContent = ({ }) => { const title = useFeedHeaderTitle() const { feedId, view } = useRouteParams() - + const enableEntryWideMode = useUISettingKey("wideMode") useTitle(title) if (!entryId) { + if (enableEntryWideMode) { + return null + } return ( { const settingWideMode = useUISettingKey("wideMode") const realEntryId = entryId === ROUTE_ENTRY_PENDING ? "" : entryId - const inEntryContentWideMode = !(views[view].wideMode || (settingWideMode && !realEntryId)) - const wideMode = settingWideMode && realEntryId + const showEntryContent = !(views[view].wideMode || (settingWideMode && !realEntryId)) + const wideMode = !!(settingWideMode && realEntryId) const feedColumnTempShow = useFeedColumnTempShow() const feedColumnShow = useFeedColumnShow() const shouldHeaderPaddingLeft = feedColumnTempShow && !feedColumnShow && settingWideMode @@ -31,18 +32,68 @@ export const Component = () => { useHotkeys( "Escape", () => { - if (inEntryContentWideMode) { + if (settingWideMode) { navigate({ entryId: null }) } }, { - enabled: inEntryContentWideMode, + enabled: showEntryContent, scopes: HotKeyScopeMap.Home, preventDefault: true, }, ) - const carouselRef = useRef(null) + if (!showEntryContent) { + return null + } + + return ( + + + + {wideMode && ( + // Close button + navigate({ entryId: null })} + > + + + )} + + + + + + ) +} + +const EntryGridContainer: FC< + PropsWithChildren<{ + showEntryContent: boolean + wideMode: boolean + }> +> = ({ children, showEntryContent, wideMode }) => { + const [containerRef, setContainerRef] = useState() + + const navigate = useNavigateEntry() useWheel( ({ delta: [dex] }) => { if (dex < -50) { @@ -50,56 +101,32 @@ export const Component = () => { } }, { - enabled: inEntryContentWideMode, - target: carouselRef, + enabled: showEntryContent && wideMode, + target: containerRef!, eventOptions: { capture: true }, axis: "x", }, ) - return ( - - - - {inEntryContentWideMode && ( - - {wideMode && ( - navigate({ entryId: null })} - > - - - )} - - - - )} - - - - ) + if (wideMode) { + return ( + + {children} + + ) + } else { + return ( +
+ {children} +
+ ) + } } diff --git a/icons/mgc/layout_4_cute_re.svg b/icons/mgc/layout_4_cute_re.svg new file mode 100644 index 000000000..98fd3185d --- /dev/null +++ b/icons/mgc/layout_4_cute_re.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/locales/app/en.json b/locales/app/en.json index dd5f50e87..dfe3ec562 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -99,7 +99,7 @@ "entry_list_header.show_unread_only": "Show unread Only", "entry_list_header.switch_to_grid": "Switch to Grid", "entry_list_header.switch_to_masonry": "Switch to Masonry", - "entry_list_header.switch_to_normalmode": "Switch to Normal Mode", + "entry_list_header.switch_to_normalmode": "Switch to Double Column Mode", "entry_list_header.switch_to_widemode": "Switch to Wide Mode", "entry_list_header.unread": "unread", "feed_claim_modal.choose_verification_method": "There are three ways to choose from, you can choose one of them to verify.", diff --git a/locales/app/zh-CN.json b/locales/app/zh-CN.json index 94b3facf0..b40b68f12 100644 --- a/locales/app/zh-CN.json +++ b/locales/app/zh-CN.json @@ -99,7 +99,7 @@ "entry_list_header.show_unread_only": "仅显示未读", "entry_list_header.switch_to_grid": "切换到网格", "entry_list_header.switch_to_masonry": "切换到瀑布流", - "entry_list_header.switch_to_normalmode": "切换到正常模式", + "entry_list_header.switch_to_normalmode": "切换到双列模式", "entry_list_header.switch_to_widemode": "切换到宽屏模式", "entry_list_header.unread": "未读", "feed_claim_modal.choose_verification_method": "提供三种认证方式,选择其中一种继续:",