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(CommandMenu): Modularize and update prop name #492

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 21 additions & 12 deletions src/components/CommandMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@ import { useHotkeys } from 'react-hotkeys-hook';
import type { CollectionEntry } from 'astro:content';
type PostsType = CollectionEntry<'posts'>[];

type CommandMenuProps = {
buttonStyles?: string;
posts?: PostsType;
const SettingsGroup = () => {
const { toggleTheme } = useThemeToggle();
return (
<CommandGroup heading="Settings">
<CommandItem onSelect={toggleTheme}>
<ThemeIcon />
<span className="ml-2">Toggle theme</span>
<CommandShortcut>T</CommandShortcut>
</CommandItem>
</CommandGroup>
);
};

export function CommandMenu({ buttonStyles, posts }: CommandMenuProps) {
export function CommandMenu({
buttonStyles,
sortedPosts,
}: {
buttonStyles?: string;
sortedPosts?: PostsType;
}) {
const [open, setOpen] = React.useState(false);
const { toggleTheme } = useThemeToggle();

Expand Down Expand Up @@ -88,8 +102,8 @@ export function CommandMenu({ buttonStyles, posts }: CommandMenuProps) {
))}
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Blog Posts">
{posts?.map((post) => (
<CommandGroup heading="Blog posts">
{sortedPosts?.map((post) => (
<CommandItem
slot="blogPosts"
key={post.data.title}
Expand All @@ -109,12 +123,7 @@ export function CommandMenu({ buttonStyles, posts }: CommandMenuProps) {
))}
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem onSelect={toggleTheme}>
<ThemeIcon />
<span className="ml-2">Toggle theme</span>
</CommandItem>
</CommandGroup>
<SettingsGroup />
</CommandList>
</CommandDialog>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { isActiveLink } from '@utils/isActiveLink';
</span>
</nav>
<span class="flex items-center gap-2">
<CommandMenu client:load posts={sortedBlogPosts} />
<CommandMenu client:load sortedPosts={sortedBlogPosts} />
<AccentColorSelector client:load />
<SideMenu client:load />
<ModeToggle client:load />
Expand Down