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

GBS-33 | feat: kmenu integration #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
78 changes: 77 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"axios": "^1.5.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"kmenu": "^2.0.0",
"lucide-react": "^0.376.0",
"next": "^13.5.6",
"next-auth": "^4.23.2",
Expand Down
54 changes: 52 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "@/styles/variables/kmenu.css";
import "kmenu/dist/cmdk.css";
import "./globals.css";

import type { Metadata } from "next";
Expand Down
11 changes: 10 additions & 1 deletion src/app/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"use client";
import { MenuProvider } from "kmenu";

import CommandPalette from "@/components/layout/header/command-palette";
import AuthProvider from "@/providers/auth-provider";
import ReactQueryProvider from "@/providers/react-query-provider";

Expand All @@ -8,7 +12,12 @@ interface Properties {
export default function Providers({ children }: Properties): JSX.Element {
return (
<AuthProvider>
<ReactQueryProvider>{children}</ReactQueryProvider>
<MenuProvider>
<ReactQueryProvider>
{children}
<CommandPalette />
</ReactQueryProvider>
</MenuProvider>
</AuthProvider>
);
}
101 changes: 101 additions & 0 deletions src/components/layout/header/command-palette.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"use client";
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
import {
type Command,
CommandMenu,
CommandWrapper,
type InnerCommand,
useCommands,
useKmenu,
} from "kmenu";
import { Github, Instagram, Search, Twitter, Youtube } from "lucide-react";
import { type FC, useState } from "react";

import { defaultPostsConstants } from "../../../constants/post.constants.ts";

const CommandPalette: FC = () => {
const [postSearchResults, setPostSearchResults] = useState<InnerCommand[]>(
[],
);
const { setOpen, open } = useKmenu();

const getPostsWithQuery = (query?: string): InnerCommand[] => {

const filteredPosts = defaultPostsConstants.filter(
(defaultPostsConstant) =>
defaultPostsConstant.header
.toLowerCase()
.includes(query?.toLowerCase() ?? "") ||
defaultPostsConstant.content
.toLowerCase()
.includes(query?.toLowerCase() ?? ""),
);
const commands = filteredPosts.map((post) => ({
icon: <Search />,
text: post.header,
perform: () => {
// handleSearch(post.header);
},
Comment on lines +37 to +38
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implement the perform action for posts

The perform function within the posts commands is currently empty. Without an implementation, selecting a post will have no effect.

Implement the perform function to handle the desired action, such as navigating to the post:

      perform: () => {
-        // handleSearch(post.header);
+        handleNavigateToPost(post.id);
      },

Ensure that handleNavigateToPost is defined and correctly navigates to the selected post.

Committable suggestion was skipped due to low confidence.

}));
setPostSearchResults(commands);
return commands;
};

const main: Command[] = [
{
category: "Search",
commands: [
{
icon: <Search />,
text: "Search",
perform: () => {
setOpen(2);
},
},
],
},
{
category: "Social",
commands: [
{
icon: <Twitter />,
text: "Twitter",
perform: () => window.open('https://x.com/gelecekbilimde', '_blank'),
},
{
icon: <Instagram />,
text: "Instagram",
perform: () => window.open('https://www.instagram.com/gelecekbilimde/', '_blank'),
},
{
icon: <Youtube />,
text: "Youtube",
perform: () => window.open('https://www.youtube.com/gelecekbilimde', '_blank'),
},
],
},
];

const posts: Command[] = [
{
category: "Posts",
commands: postSearchResults,
},
];

const [mainCommands] = useCommands(main);
const [postsCommands] = useCommands(posts);

return (
<CommandWrapper>
<CommandMenu commands={mainCommands} crumbs={["Home"]} index={open} />
<CommandMenu
commands={postsCommands}
crumbs={["Home", "Posts"]}
index={2}
/>
</CommandWrapper>
);
};

export default CommandPalette;
1 change: 1 addition & 0 deletions src/components/layout/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import "react-modern-drawer/dist/index.css";

import { useKmenu } from "kmenu";
import { MenuIcon, SearchIcon } from "lucide-react";
import Image from "next/image";
import Link from "next/link";
Expand Down
Loading