Skip to content

Commit b59c2e3

Browse files
authored
Merge pull request #44 from pheralb/next
🛠️ Add cmd+k to input search + fixed get /folders source code
2 parents ecd57cf + c31c3f6 commit b59c2e3

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

website/app/components/card/copyIcon.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ const CopyIconActions = ({ itemName, isFolder, ItemIcon }: CopyIconProps) => {
5252
const handleCopySource = async () => {
5353
setLoading(true);
5454
const itemNameLower = itemName.charAt(0).toLowerCase() + itemName.slice(1);
55-
const jsonUrl = `${appConfig.registryUrl}${itemNameLower}.json`;
55+
const jsonUrl = !isFolder
56+
? `${appConfig.registryUrl}${itemNameLower}.json`
57+
: `${appConfig.registryUrl}folders/${itemNameLower}.json`;
5658

5759
try {
5860
const response = await axios.get(jsonUrl);

website/app/components/navbar/search.tsx

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { useSearchParams } from "react-router";
22

33
import { Input } from "@/ui/input";
44
import { searchParamKey } from "@/data/searchParams";
5+
import { useEffect, useRef, useState, type ChangeEvent } from "react";
6+
import { CommandIcon } from "lucide-react";
57

68
interface iSearchProps {
79
className?: string;
@@ -11,8 +13,23 @@ interface iSearchProps {
1113
const Search = (props: iSearchProps) => {
1214
const [searchParams, setSearchParams] = useSearchParams();
1315
const search = searchParams.get(searchParamKey) ?? "";
16+
const [isFocused, setIsFocused] = useState<boolean>(false);
17+
const inputRef = useRef<HTMLInputElement>(null);
1418

15-
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
19+
useEffect(() => {
20+
const down = (e: KeyboardEvent) => {
21+
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
22+
e.preventDefault();
23+
if (inputRef.current) {
24+
inputRef.current.focus();
25+
}
26+
}
27+
};
28+
document.addEventListener("keydown", down);
29+
return () => document.removeEventListener("keydown", down);
30+
}, []);
31+
32+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
1633
const newSearchParams = new URLSearchParams(searchParams);
1734
if (!e.target.value) {
1835
newSearchParams.delete(searchParamKey);
@@ -23,15 +40,26 @@ const Search = (props: iSearchProps) => {
2340
};
2441

2542
return (
26-
<Input
27-
className={props.className}
28-
type="search"
29-
name={searchParamKey}
30-
placeholder={props.placeholder}
31-
defaultValue={search}
32-
autoComplete="off"
33-
onChange={(e) => handleChange(e)}
34-
/>
43+
<div className="relative">
44+
<Input
45+
ref={inputRef}
46+
className={props.className}
47+
type="search"
48+
name={searchParamKey}
49+
placeholder={props.placeholder}
50+
defaultValue={search}
51+
autoComplete="off"
52+
onChange={(e) => handleChange(e)}
53+
onFocus={() => setIsFocused(true)}
54+
onBlur={() => setIsFocused(false)}
55+
/>
56+
{!isFocused && !search && (
57+
<kbd className="pointer-events-none absolute right-2 top-1/2 flex -translate-y-1/2 items-center gap-1 rounded bg-zinc-200 p-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400">
58+
<CommandIcon size={14} />
59+
<span>K</span>
60+
</kbd>
61+
)}
62+
</div>
3563
);
3664
};
3765

website/app/components/notFound.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { buttonVariants } from "@/ui/button";
22
import { containerClasses } from "@/ui/container";
3-
import { BoxIcon } from "lucide-react";
3+
import { BoxIcon, FolderSearchIcon } from "lucide-react";
44
import { cn } from "@/utils";
55
import { Link } from "react-router";
66

@@ -33,7 +33,10 @@ const NotFound = (props: NotFoundProps) => {
3333
variant: "outline",
3434
})}
3535
>
36-
Show all {props.isFolder ? "folders icons" : "files icons"}
36+
<FolderSearchIcon size={18} strokeWidth={1.5} />
37+
<span>
38+
Show all {props.isFolder ? "folders icons" : "files icons"}
39+
</span>
3740
</Link>
3841
</div>
3942
</div>

website/app/root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import { themeSessionResolver } from "./sessions.server";
3939
import clsx from "clsx";
4040

41+
4142
// Links:
4243
export const links: LinksFunction = () => [
4344
{ rel: "stylesheet", href: tailwind },

0 commit comments

Comments
 (0)