feat: customize toolbar (#2468)

* feat: add customizable toolbar modal

* refactor: extract SortableActionButton component

* refactor: enhance CustomizeToolbar with drag-and-drop reordering and state management

* refactor: update CustomizeToolbar for improved state management

* refactor: enhance drag-and-drop functionality

* feat: add CustomizeToolbarCommand

* chore: update i18n

* feat: extract customizable toolbar actions state

* feat: integrate customizable toolbar order for entry header and more actions

* chore: add @dnd-kit/sortable dependency

* feat: add reset action order functionality

* feat: sync action order

* chore: filter out read action

* chore: add changeset
This commit is contained in:
Whitewater
2025-01-07 12:26:24 +08:00
committed by GitHub
parent e2c9459db8
commit 38fe110754
17 changed files with 391 additions and 32 deletions
@@ -1,10 +1,10 @@
import { useRegisterEntryCommands } from "./commands/entry"
import { useRegisterIntegrationCommands } from "./commands/integration"
import { useRegisterListCommands } from "./commands/list"
import { useRegisterThemeCommands } from "./commands/theme"
import { useRegisterSettingsCommands } from "./commands/settings"
export function useRegisterFollowCommands() {
useRegisterThemeCommands()
useRegisterSettingsCommands()
useRegisterListCommands()
useRegisterEntryCommands()
useRegisterIntegrationCommands()
@@ -31,9 +31,10 @@ export const COMMAND_ID = {
copyUrl: "list:copy-url",
copyId: "list:copy-id",
},
theme: {
toAuto: "follow:change-color-mode-to-auto",
toDark: "follow:change-color-mode-to-dark",
toLight: "follow:change-color-mode-to-light",
settings: {
changeThemeToAuto: "follow:change-color-mode-to-auto",
changeThemeToDark: "follow:change-color-mode-to-dark",
changeThemeToLight: "follow:change-color-mode-to-light",
customizeToolbar: "follow:customize-toolbar",
},
} as const
@@ -2,17 +2,40 @@ import { useThemeAtomValue } from "@follow/hooks"
import { useTranslation } from "react-i18next"
import { useSetTheme } from "~/hooks/common"
import { useShowCustomizeToolbarModal } from "~/modules/customize-toolbar/modal"
import { useRegisterCommandEffect } from "../hooks/use-register-command"
import { COMMAND_ID } from "./id"
export const useRegisterThemeCommands = () => {
export const useRegisterSettingsCommands = () => {
useCustomizeToolbarCommand()
useRegisterThemeCommands()
}
const useCustomizeToolbarCommand = () => {
const [t] = useTranslation("settings")
const showModal = useShowCustomizeToolbarModal()
useRegisterCommandEffect([
{
id: COMMAND_ID.settings.customizeToolbar,
label: t("customizeToolbar.title"),
category: "follow:settings",
icon: <i className="i-mgc-settings-7-cute-re" />,
run() {
showModal()
},
},
])
}
const useRegisterThemeCommands = () => {
const [t] = useTranslation("settings")
const theme = useThemeAtomValue()
const setTheme = useSetTheme()
useRegisterCommandEffect([
{
id: "follow:change-color-mode-to-auto",
id: COMMAND_ID.settings.changeThemeToAuto,
label: `To ${t("appearance.theme.system")}`,
category: "follow:settings",
icon: <i className="i-mgc-settings-7-cute-re" />,
@@ -22,7 +45,7 @@ export const useRegisterThemeCommands = () => {
},
},
{
id: "follow:change-color-mode-to-dark",
id: COMMAND_ID.settings.changeThemeToDark,
label: `To ${t("appearance.theme.dark")}`,
category: "follow:settings",
icon: <i className="i-mingcute-moon-line" />,
@@ -32,7 +55,7 @@ export const useRegisterThemeCommands = () => {
},
},
{
id: "follow:change-color-mode-to-light",
id: COMMAND_ID.settings.changeThemeToLight,
label: `To ${t("appearance.theme.light")}`,
category: "follow:settings",
icon: <i className="i-mingcute-sun-line" />,
@@ -89,6 +89,15 @@ export type EntryCommand =
| ToggleAISummaryCommand
| ToggleAITranslationCommand
// Settings commands
export type CustomizeToolbarCommand = Command<{
id: typeof COMMAND_ID.settings.customizeToolbar
fn: () => void
}>
export type SettingsCommand = CustomizeToolbarCommand
// Integration commands
export type SaveToEagleCommand = Command<{
@@ -129,4 +138,4 @@ export type IntegrationCommand =
| SaveToOutlineCommand
| SaveToReadeckCommand
export type BasicCommand = EntryCommand | IntegrationCommand
export type BasicCommand = EntryCommand | SettingsCommand | IntegrationCommand