diff --git a/src/components/CommandMenu/CommandMenu.tsx b/src/components/CommandMenu/CommandMenu.tsx index 910f5df92..4d4895578 100644 --- a/src/components/CommandMenu/CommandMenu.tsx +++ b/src/components/CommandMenu/CommandMenu.tsx @@ -1,22 +1,48 @@ import { useEffect, useRef, useState } from 'preact/hooks'; +import BestPracticesIcon from '../../icons/best-practices.svg'; +import HomeIcon from '../../icons/home.svg'; +import UserIcon from '../../icons/user.svg'; +import RoadmapIcon from '../../icons/roadmap.svg'; +import GuideIcon from '../../icons/guide.svg'; +import VideoIcon from '../../icons/video.svg'; import { httpGet } from '../../lib/http'; import { useKeydown } from '../../hooks/use-keydown'; +import { isLoggedIn } from '../../lib/jwt'; type PageType = { url: string; title: string; group: string; + icon?: string; + isProtected?: boolean; }; const defaultPages: PageType[] = [ - { url: '/', title: 'Home', group: 'Pages' }, - { url: '/settings/update-profile', title: 'Account', group: 'Pages' }, - { url: '/roadmaps', title: 'Roadmaps', group: 'Pages' }, - { url: '/best-practices', title: 'Best Practices', group: 'Pages' }, - { url: '/guides', title: 'Guides', group: 'Pages' }, - { url: '/videos', title: 'Videos', group: 'Pages' }, + { url: '/', title: 'Home', group: 'Pages', icon: HomeIcon }, + { + url: '/settings/update-profile', + title: 'Account', + group: 'Pages', + icon: UserIcon, + isProtected: true, + }, + { url: '/roadmaps', title: 'Roadmaps', group: 'Pages', icon: RoadmapIcon }, + { + url: '/best-practices', + title: 'Best Practices', + group: 'Pages', + icon: BestPracticesIcon, + }, + { url: '/guides', title: 'Guides', group: 'Pages', icon: GuideIcon }, + { url: '/videos', title: 'Videos', group: 'Pages', icon: VideoIcon }, ]; +function shouldShowPage(page: PageType) { + const isUser = isLoggedIn(); + + return !page.isProtected || isUser; +} + export function CommandMenu() { const inputRef = useRef(null); const [isActive, setIsActive] = useState(false); @@ -41,20 +67,19 @@ export function CommandMenu() { if (allPages.length > 0) { return allPages; } - const { error, response } = await httpGet(`/pages.json`); if (!response) { - return defaultPages; + return defaultPages.filter(shouldShowPage); } - setAllPages([...defaultPages, ...response]); + setAllPages([...defaultPages, ...response].filter(shouldShowPage)); return response; } useEffect(() => { if (!searchedText) { - setSearchResults(defaultPages); + setSearchResults(defaultPages.filter(shouldShowPage)); return; } @@ -87,7 +112,7 @@ export function CommandMenu() { type="text" value={searchedText} className="w-full rounded-t-md border-b p-4 text-sm focus:bg-gray-50 focus:outline-0" - placeholder="Search anywhere .." + placeholder="Search roadmaps, guides or pages .." autocomplete="off" onInput={(e) => { const value = (e.target as HTMLInputElement).value.trim(); @@ -133,17 +158,20 @@ export function CommandMenu() {
)} setActiveCounter(counter)} href={page.url} > - {searchedText && ( + {!page.icon && ( {page.group} )} - {!searchedText && ( - ICON + {page.icon && ( + )} {page.title} diff --git a/src/icons/best-practices.svg b/src/icons/best-practices.svg new file mode 100644 index 000000000..f458219bf --- /dev/null +++ b/src/icons/best-practices.svg @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/src/icons/guide.svg b/src/icons/guide.svg new file mode 100644 index 000000000..4a7ec8fb0 --- /dev/null +++ b/src/icons/guide.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/home.svg b/src/icons/home.svg new file mode 100644 index 000000000..4cf85cc7e --- /dev/null +++ b/src/icons/home.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/roadmap.svg b/src/icons/roadmap.svg new file mode 100644 index 000000000..0bb7c2436 --- /dev/null +++ b/src/icons/roadmap.svg @@ -0,0 +1 @@ + diff --git a/src/icons/user.svg b/src/icons/user.svg new file mode 100644 index 000000000..71a53b88f --- /dev/null +++ b/src/icons/user.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/video.svg b/src/icons/video.svg new file mode 100644 index 000000000..0de6fd04c --- /dev/null +++ b/src/icons/video.svg @@ -0,0 +1,3 @@ + + +