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

Fix: UX Refactor - 3 (#42) and SearchBox Optimization(#53) #54

Open
wants to merge 1 commit into
base: master
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
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Footer from '@/components/Footer/Footer';

export default function Home() {
return (
<main data-testid="main-content">
<main data-testid="main-content" className="pb-8">
<Playground />
<Footer />
</main>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import People from '@mui/icons-material/People';

export default function Footer() {
return (
<footer className="bg-white border-t border-gray-100 py-12">
<footer className="bg-white border-t border-gray-100 py-12 mt-8">
<div className="container mx-auto px-4">
<div className="grid grid-cols-1 md:grid-cols-4 gap-8">
<div>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Shell from '@/components/Shell/Shell';
import SearchBox from '@/components/Search/SearchBox';
import { Dice1, Dice3, Dice5, Info } from 'lucide-react';
import { useMemo } from 'react';

// utils
import { formatTime } from '@/shared/utils/commonUtils';
Expand All @@ -13,9 +14,11 @@ import Image from 'next/image';
import { usePlayground } from './hooks/usePlayground';

export default function Playground() {
const { decreaseCommandsLeft, search, timeLeft, commandsLeft, setSearch } =
const { decreaseCommandsLeft, timeLeft, commandsLeft } =
usePlayground();

const MemoizedSearchBox = useMemo(() => <SearchBox />, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a hack we had to do because we don't have separate components for the 2 sections of playground (The Terminal and the Searchbox).

Can we just create a component for the Left Column of Playground (Terminal + Commands Left etc), and call usePlayground from it? Basically, neither the Searchbox or any of it's parents should care about the time or commandsLeft, these should be state of the sibling for Searchbox.


return (
<div className="container mx-auto flex flex-col flex-grow min-h-screen bg-white text-gray-900">
<header className="navbar flex items-center justify-between py-5">
Expand Down Expand Up @@ -67,7 +70,7 @@ export default function Playground() {

<div className="w-full lg:w-5/12 flex flex-col">
<div className="flex-grow border border-gray-400 bg-gray-100 p-4 rounded-lg shadow-md mb-4">
<SearchBox search={search} setSearch={setSearch} />
{MemoizedSearchBox}
</div>
</div>
</main>
Expand Down
3 changes: 0 additions & 3 deletions src/components/Playground/hooks/usePlayground.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState, useEffect } from 'react';

export const usePlayground = () => {
const [search, setSearch] = useState('');
const [timeLeft, setTimeLeft] = useState<number>(15 * 60);
const [commandsLeft, setCommandsLeft] = useState<number>(1000);

Expand All @@ -19,10 +18,8 @@ export const usePlayground = () => {

return {
decreaseCommandsLeft,
search,
timeLeft,
commandsLeft,
setSearch,
setTimeLeft,
setCommandsLeft,
};
Expand Down
31 changes: 13 additions & 18 deletions src/components/Search/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'use client';

import { SetStateAction, Dispatch } from 'react';
import { useState } from 'react';
import { Search } from 'lucide-react';
import { DiceCmds, DiceCmdMeta } from '@/data/command';
import CommandPage from './command';

interface SearchBoxProps {
search: string;
setSearch: Dispatch<SetStateAction<string>>;
}

export default function SearchBox({ search, setSearch }: SearchBoxProps) {
export default function SearchBox() {
const [search, setSearch] = useState('');
const filteredCommands = Object.values(DiceCmds).filter((cmd: DiceCmdMeta) =>
cmd.title.toLowerCase().includes(search.toLowerCase()),
);
Expand All @@ -24,22 +20,21 @@ export default function SearchBox({ search, setSearch }: SearchBoxProps) {
type="text"
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search commands..."
placeholder="Search commands (e.g., GET, SET, LPUSH, HSET)..."
className="bg-transparent border-none outline-none w-full py-2 text-gray-900 font-assistant"
/>
</div>
</div>
<div className="mt-4 space-y-4 max-h-[500px] lg:max-h-[870px] xl:max-h-[890px] overflow-y-auto">
{search.length > 1 &&
filteredCommands.map((cmdMeta) => (
<CommandPage
key={cmdMeta.title}
title={cmdMeta.title}
syntax={cmdMeta.syntax}
body={cmdMeta.body}
url={cmdMeta.url}
/>
))}
{filteredCommands.map((cmdMeta) => (
<CommandPage
key={cmdMeta.title}
title={cmdMeta.title}
syntax={cmdMeta.syntax}
body={cmdMeta.body}
url={cmdMeta.url}
/>
))}
</div>
</div>
);
Expand Down
Loading