chore: remove account and memo

This commit is contained in:
Aslam H
2024-11-09 15:12:26 +07:00
parent b8336d50e6
commit fe5f3ac1b9
3 changed files with 54 additions and 49 deletions

View File

@@ -1,5 +1,4 @@
import { icons } from "lucide-react"
import { LaAccount } from "@/lib/schema"
import { HTMLLikeElement } from "@/lib/utils"
import { useCommandActions } from "~/hooks/actions/use-command-actions"
@@ -44,7 +43,6 @@ const createNavigationItem = (
export const createCommandGroups = (
actions: ReturnType<typeof useCommandActions>,
me: LaAccount,
): Record<string, CommandGroupType> => ({
home: [
{
@@ -97,7 +95,7 @@ export const createCommandGroups = (
icon: "Plus",
value: "Create New Page...",
label: "Create New Page...",
action: () => actions.createNewPage(me),
action: () => actions.createNewPage(),
},
],
},

View File

@@ -10,26 +10,31 @@ export interface CommandItemProps extends Omit<CommandItemType, "action"> {
handleAction: (action: CommandAction, payload?: any) => void
}
const HTMLLikeRenderer: React.FC<{ content: HTMLLikeElement | string }> =
React.memo(({ content }) => {
return (
<span className="line-clamp-1">{renderHTMLLikeElement(content)}</span>
)
})
const HTMLLikeRenderer: React.FC<{ content: HTMLLikeElement | string }> = ({
content,
}) => {
return <span className="line-clamp-1">{renderHTMLLikeElement(content)}</span>
}
HTMLLikeRenderer.displayName = "HTMLLikeRenderer"
export const CommandItem: React.FC<CommandItemProps> = React.memo(
({ icon, label, action, payload, shortcut, handleAction, ...item }) => (
<Command.Item
value={`${item.id}-${item.value}`}
onSelect={() => handleAction(action, payload)}
>
{icon && <LaIcon name={icon} />}
<HTMLLikeRenderer content={label} />
{shortcut && <CommandShortcut>{shortcut}</CommandShortcut>}
</Command.Item>
),
export const CommandItem: React.FC<CommandItemProps> = ({
icon,
label,
action,
payload,
shortcut,
handleAction,
...item
}) => (
<Command.Item
value={`${item.id}-${item.value}`}
onSelect={() => handleAction(action, payload)}
>
{icon && <LaIcon name={icon} />}
<HTMLLikeRenderer content={label} />
{shortcut && <CommandShortcut>{shortcut}</CommandShortcut>}
</Command.Item>
)
CommandItem.displayName = "CommandItem"
@@ -41,33 +46,36 @@ export interface CommandGroupProps {
isLastGroup: boolean
}
export const CommandGroup: React.FC<CommandGroupProps> = React.memo(
({ heading, items, handleAction, isLastGroup }) => {
return (
<>
{heading ? (
<Command.Group heading={heading}>
{items.map((item, index) => (
<CommandItem
key={`${heading}-${item.label}-${index}`}
{...item}
handleAction={handleAction}
/>
))}
</Command.Group>
) : (
items.map((item, index) => (
export const CommandGroup: React.FC<CommandGroupProps> = ({
heading,
items,
handleAction,
isLastGroup,
}) => {
return (
<>
{heading ? (
<Command.Group heading={heading}>
{items.map((item, index) => (
<CommandItem
key={`item-${item.label}-${index}`}
key={`${heading}-${item.label}-${index}`}
{...item}
handleAction={handleAction}
/>
))
)}
{!isLastGroup && <CommandSeparator className="my-1.5" />}
</>
)
},
)
))}
</Command.Group>
) : (
items.map((item, index) => (
<CommandItem
key={`item-${item.label}-${index}`}
{...item}
handleAction={handleAction}
/>
))
)}
{!isLastGroup && <CommandSeparator className="my-1.5" />}
</>
)
}
CommandGroup.displayName = "CommandGroup"

View File

@@ -32,17 +32,16 @@ export function CommandPalette() {
}
export function RealCommandPalette() {
const { me } = useAccount({ root: { personalLinks: [], personalPages: [] } })
const { me } = useAccount({
root: { personalLinks: [{}], personalPages: [{}] },
})
const dialogRef = React.useRef<HTMLDivElement | null>(null)
const [inputValue, setInputValue] = React.useState("")
const [activePage, setActivePage] = React.useState("home")
const [open, setOpen] = useAtom(commandPaletteOpenAtom)
const actions = useCommandActions()
const commandGroups = React.useMemo(
() => me && createCommandGroups(actions, me),
[actions, me],
)
const commandGroups = createCommandGroups(actions)
const bounce = React.useCallback(() => {
if (dialogRef.current) {