Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: new command abstractions in follow #1566

Merged
merged 15 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: replace entry actions with command buttons in entry header
  • Loading branch information
lawvs committed Nov 18, 2024
commit 35a29f1a008bb73ec5bf9bb1904232e5aff50ae3
63 changes: 32 additions & 31 deletions apps/renderer/src/modules/entry-content/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FeedViewType, views } from "@follow/constants"
import type { CombinedEntryModel, MediaModel } from "@follow/models/types"
import { IN_ELECTRON } from "@follow/shared/constants"
import { cn } from "@follow/utils/utils"
import { Slot } from "@radix-ui/react-slot"
import { noop } from "foxact/noop"
import { AnimatePresence, m } from "framer-motion"
import { memo, useMemo, useState } from "react"
Expand All @@ -19,19 +18,42 @@ import {
import { useUISettingKey } from "~/atoms/settings/ui"
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
import { shortcuts } from "~/constants/shortcuts"
import { useEntryActions, useEntryReadabilityToggle } from "~/hooks/biz/useEntryActions"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { useEntryReadabilityToggle } from "~/hooks/biz/useEntryActions"
import { tipcClient } from "~/lib/client"
import { parseHtml } from "~/lib/parse-html"
import { filterSmallMedia } from "~/lib/utils"
import type { FlatEntryModel } from "~/store/entry"
import { useEntry } from "~/store/entry/hooks"
import { useFeedById } from "~/store/feed"

import { CommandIdButton } from "../command/command-button"
import { COMMAND_ID } from "../command/commands/id"
import { ImageGallery } from "./actions/picture-gallery"
import { useEntryContentScrollToTop, useEntryTitleMeta } from "./atoms"
import { EntryReadHistory } from "./components/EntryReadHistory"

const entryActions = [
COMMAND_ID.integration.saveToEagle,
COMMAND_ID.integration.saveToReadwise,
COMMAND_ID.integration.saveToInstapaper,
COMMAND_ID.integration.saveToOmnivore,
COMMAND_ID.integration.saveToObsidian,
COMMAND_ID.integration.saveToOutline,

COMMAND_ID.entry.Tip,
COMMAND_ID.entry.star,
COMMAND_ID.entry.unstar,
COMMAND_ID.entry.delete,
COMMAND_ID.entry.copyLink,
// COMMAND_ID.entry.copyTitle,
// COMMAND_ID.entry.openInBrowser,
COMMAND_ID.entry.viewSourceContent,
COMMAND_ID.entry.viewEntryContent,
COMMAND_ID.entry.share,
COMMAND_ID.entry.read,
COMMAND_ID.entry.unread,
]

function EntryHeaderImpl({
view,
entryId,
Expand All @@ -44,15 +66,6 @@ function EntryHeaderImpl({
compact?: boolean
}) {
const entry = useEntry(entryId)

const listId = useRouteParamsSelector((s) => s.listId)
const { items } = useEntryActions({
view,
entry,
type: "toolbar",
inList: !!listId,
})

const entryTitleMeta = useEntryTitleMeta()
const isAtTop = useEntryContentScrollToTop()

Expand Down Expand Up @@ -110,25 +123,13 @@ function EntryHeaderImpl({
{!compact && <ElectronAdditionActions view={view} entry={entry} key={entry.entries.id} />}

<SpecialActions id={entry.entries.id} />
{items
.filter((item) => !item.hide)
.map((item) => (
<ActionButton
disabled={item.disabled}
icon={
item.icon ? (
<Slot className="size-4">{item.icon}</Slot>
) : (
<i className={item.className} />
)
}
active={item.active}
shortcut={item.shortcut}
onClick={item.onClick}
tooltip={item.name}
key={item.name}
/>
))}
{entryActions.map((cmdId) => (
<CommandIdButton
key={cmdId}
commandId={cmdId}
context={{ entryId: entry.entries.id, feedId: entry.feedId }}
/>
))}
</div>
</div>
</div>
Expand Down