Skip to content

Commit e1eb11f

Browse files
committed
fix: context for command palette
1 parent ee84cbb commit e1eb11f

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

src/App.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ContactModal from './components/ContactModal';
88
import GenericModal from './components/GenericModal';
99
import DigitalRain from './components/DigitalRain';
1010
import { AnimationProvider } from './context/AnimationContext'; // Import AnimationProvider
11+
import { CommandPaletteProvider } from './context/CommandPaletteContext';
1112

1213
function App() {
1314
const [isModalOpen, setIsModalOpen] = useState(false);
@@ -42,15 +43,17 @@ function App() {
4243
<DigitalRain isActive={isRainActive} />
4344
<ScrollToTop />
4445
<ToastProvider>
45-
<Layout
46-
toggleModal={toggleModal}
47-
isSearchVisible={isSearchVisible}
48-
toggleSearch={toggleSearch}
49-
openGenericModal={openGenericModal}
50-
toggleDigitalRain={toggleDigitalRain}
51-
>
52-
<AnimatedRoutes />
53-
</Layout>
46+
<CommandPaletteProvider>
47+
<Layout
48+
toggleModal={toggleModal}
49+
isSearchVisible={isSearchVisible}
50+
toggleSearch={toggleSearch}
51+
openGenericModal={openGenericModal}
52+
toggleDigitalRain={toggleDigitalRain}
53+
>
54+
<AnimatedRoutes />
55+
</Layout>
56+
</CommandPaletteProvider>
5457
<ContactModal isOpen={isModalOpen} onClose={toggleModal} />
5558
<GenericModal
5659
isOpen={isGenericModalOpen}

src/components/Layout.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import DndFooter from './dnd/DndFooter';
77
import { useLocation } from 'react-router-dom';
88
import Search from './Search';
99
import CommandPalette from './CommandPalette';
10+
import { useCommandPalette } from '../context/CommandPaletteContext';
1011

1112
import { DndProvider } from '../context/DndContext';
1213

1314
const Layout = ({ children, toggleModal, isSearchVisible, toggleSearch, openGenericModal, toggleDigitalRain }) => {
1415
const [isSidebarOpen, setIsSidebarOpen] = useState(window.innerWidth > 768);
15-
const [isPaletteOpen, setIsPaletteOpen] = useState(false);
16+
const { isPaletteOpen, setIsPaletteOpen } = useCommandPalette();
1617
const location = useLocation();
1718

1819
useEffect(() => {
@@ -22,19 +23,10 @@ const Layout = ({ children, toggleModal, isSearchVisible, toggleSearch, openGene
2223
}
2324
};
2425

25-
const handleKeyDown = (event) => {
26-
if (event.altKey && event.key === 'k') {
27-
event.preventDefault();
28-
setIsPaletteOpen((open) => !open);
29-
}
30-
};
31-
3226
window.addEventListener('resize', handleResize);
33-
window.addEventListener('keydown', handleKeyDown);
3427

3528
return () => {
3629
window.removeEventListener('resize', handleResize);
37-
window.removeEventListener('keydown', handleKeyDown);
3830
};
3931
}, []);
4032

src/components/ProjectCard.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ const ProjectCard = ({ project, size = 1 }) => {
7979
className="flex flex-col flex-grow relative z-10"
8080
>
8181
<h3 className="font-arvo text-xl text-orange-400">{project.title}</h3>
82-
<p className="mt-2 text-gray-400 flex-grow">{project.description}</p>
82+
<hr className="border-gray-700 -mx-6 mb-4 mt-4" />
83+
<p className="text-gray-400 flex-grow">{project.description}</p>
8384
</Link>
8485
{project.link && (
8586
<a
8687
href={project.link}
8788
target="_blank"
8889
rel="noopener noreferrer"
89-
className="mt-4 inline-block text-red-500 hover:text-red-300 transition-colors mt-auto flex items-center relative z-10"
90+
className="text-red-500 hover:text-red-300 transition-colors mt-auto flex items-center relative z-10"
9091
>
9192
View Project <FaExternalLinkAlt className="ml-1" size={12} />
9293
</a>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { createContext, useState, useContext, useEffect } from 'react';
2+
3+
const CommandPaletteContext = createContext();
4+
5+
export const useCommandPalette = () => {
6+
return useContext(CommandPaletteContext);
7+
};
8+
9+
export const CommandPaletteProvider = ({ children }) => {
10+
const [isPaletteOpen, setIsPaletteOpen] = useState(false);
11+
12+
const openPalette = () => setIsPaletteOpen(true);
13+
const closePalette = () => setIsPaletteOpen(false);
14+
const togglePalette = () => setIsPaletteOpen((prev) => !prev);
15+
16+
// Global keyboard shortcut
17+
useEffect(() => {
18+
const handleKeyDown = (event) => {
19+
if (event.altKey && event.key === 'k') {
20+
event.preventDefault();
21+
togglePalette();
22+
}
23+
};
24+
25+
window.addEventListener('keydown', handleKeyDown);
26+
return () => window.removeEventListener('keydown', handleKeyDown);
27+
}, []);
28+
29+
return (
30+
<CommandPaletteContext.Provider value={{ isPaletteOpen, setIsPaletteOpen, openPalette, closePalette, togglePalette }}>
31+
{children}
32+
</CommandPaletteContext.Provider>
33+
);
34+
};

src/pages/CommandsPage.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import React from 'react';
22
import { Link } from 'react-router-dom';
3-
import {
4-
ArrowLeftIcon, TerminalWindowIcon
5-
} from '@phosphor-icons/react';
6-
3+
import { ArrowLeftIcon, TerminalWindowIcon } from '@phosphor-icons/react';
74
import useSeo from '../hooks/useSeo';
8-
5+
import { useCommandPalette } from '../context/CommandPaletteContext';
96
import colors from "../config/colors"; // Import CustomDropdown
107

118
function CommandsPage() {
@@ -29,6 +26,8 @@ function CommandsPage() {
2926
twitterImage: 'https://fezcode.github.io/logo512.png',
3027
});
3128

29+
const { togglePalette } = useCommandPalette();
30+
3231
const cardStyle = {
3332
backgroundColor: colors['app-alpha-10'],
3433
borderColor: colors['app-alpha-50'],
@@ -79,6 +78,13 @@ function CommandsPage() {
7978
<br/>
8079
You can type <code className="text-emerald-300"> COMMAND </code> to see all available commands.
8180
</p>
81+
<button
82+
onClick={togglePalette}
83+
className="border border-gray-200 bg-black/50 hover:bg-gray-50 text-white hover:text-black font-mono py-3 px-4 rounded w-full transition-colors duration-300 flex items-center justify-center gap-2"
84+
>
85+
<TerminalWindowIcon size={24} />
86+
Open Command Palette
87+
</button>
8288
</div>
8389

8490
<h1 className="text-3xl font-arvo font-normal mb-4 text-app"> Available Commands </h1>

0 commit comments

Comments
 (0)