Skip to content

Commit 214df9b

Browse files
committed
Revert "fix: code organisation and rendering (#58)"
This reverts commit 348b267.
1 parent a1bccea commit 214df9b

File tree

6 files changed

+96
-105
lines changed

6 files changed

+96
-105
lines changed

src/components/Playground/Playground.tsx

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,76 @@
11
'use client';
22

33
import Image from 'next/image';
4+
import { Dice1, Dice3, Dice5, Info } from 'lucide-react';
5+
6+
// Components
7+
import Shell from '@/components/Shell/Shell';
48
import SearchBox from '@/components/Search/SearchBox';
5-
import { TerminalUI } from './TerminalUI';
69

710
// utils
11+
import { formatTime } from '@/shared/utils/commonUtils';
12+
import { usePlayground } from './hooks/usePlayground';
813

914
export default function Playground() {
15+
const { decreaseCommandsLeft, search, timeLeft, commandsLeft, setSearch } =
16+
usePlayground();
17+
1018
return (
1119
<div className="container mx-auto flex flex-col flex-grow min-h-screen bg-white text-gray-900">
12-
<Header />
20+
<header className="navbar flex items-center justify-between py-5">
21+
<div className="flex items-center">
22+
<Image
23+
src="/images/dicedb-logo-light.png"
24+
width={110}
25+
height={110}
26+
priority={true}
27+
alt="DiceDB logo"
28+
className="object-contain"
29+
unoptimized
30+
/>
31+
<h2 className="font-light text-2xl ml-2">PlayGround</h2>
32+
</div>
33+
</header>
1334

1435
<main className="flex flex-col lg:flex-row gap-10 flex-grow overflow-hidden px-4">
1536
<div className="w-full lg:w-7/12 flex flex-col">
16-
<TerminalUI />
37+
<div className="bg-gray-900 rounded-lg">
38+
<div className="bg-gray-900 px-4 py-4 flex items-center rounded-lg">
39+
<div className="flex space-x-2">
40+
<Dice5 className="w-4 h-4 bg-red-500" />
41+
<Dice1 className="w-4 h-4 bg-yellow-500" />
42+
<Dice3 className="w-4 h-4 bg-green-500" />
43+
</div>
44+
</div>
45+
<div className="h-64 md:h-[30rem] bg-gray-100 rounded-lg overflow-hidden shadow-md">
46+
<Shell decreaseCommandsLeft={decreaseCommandsLeft} />
47+
</div>
48+
</div>
49+
50+
<div className="flex flex-col">
51+
<div className="flex flex-row justify-between text-gray-900 mt-4">
52+
<div className="flex justify-between border border-gray-400 text-sm bg-transparent p-3 rounded-lg">
53+
<span>Cleanup in : {formatTime(timeLeft)} mins</span>
54+
</div>
55+
<div className="flex justify-between border border-gray-400 text-sm bg-transparent p-3 rounded-lg">
56+
<span>Commands left: {commandsLeft}</span>
57+
</div>
58+
</div>
59+
<div className="flex flex-row items-start mt-5">
60+
<Info className="w-4 h-4 text-gray-500 mr-1" />
61+
<p className="text-sm text-gray-500">
62+
DiceDB instance is shared across all users.
63+
</p>
64+
</div>
65+
</div>
1766
</div>
67+
1868
<div className="w-full lg:w-5/12 flex flex-col">
1969
<div className="flex-grow border border-gray-400 bg-gray-100 p-4 rounded-lg shadow-md mb-4">
20-
<SearchBox />
70+
<SearchBox search={search} setSearch={setSearch} />
2171
</div>
2272
</div>
2373
</main>
2474
</div>
2575
);
2676
}
27-
28-
function Header() {
29-
return (
30-
<header className="navbar flex items-center justify-between py-5">
31-
<div className="flex items-center">
32-
<Image
33-
src="/images/dicedb-logo-light.png"
34-
width={110}
35-
height={110}
36-
priority={true}
37-
alt="DiceDB logo"
38-
className="object-contain"
39-
unoptimized
40-
/>
41-
<h2 className="font-light text-2xl ml-2">PlayGround</h2>
42-
</div>
43-
</header>
44-
);
45-
}

src/components/Playground/TerminalUI.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useState, useEffect } from 'react';
2+
3+
export const usePlayground = () => {
4+
const [search, setSearch] = useState('');
5+
const [timeLeft, setTimeLeft] = useState<number>(15 * 60);
6+
const [commandsLeft, setCommandsLeft] = useState<number>(1000);
7+
8+
useEffect(() => {
9+
const timer = setInterval(() => {
10+
setTimeLeft((prev) => (prev > 0 ? prev - 1 : 0));
11+
}, 1000);
12+
13+
return () => clearInterval(timer);
14+
}, []);
15+
16+
const decreaseCommandsLeft = () => {
17+
setCommandsLeft((prev) => (prev > 0 ? prev - 1 : 0));
18+
};
19+
20+
return {
21+
decreaseCommandsLeft,
22+
search,
23+
timeLeft,
24+
commandsLeft,
25+
setSearch,
26+
setTimeLeft,
27+
setCommandsLeft,
28+
};
29+
};

src/components/Search/SearchBox.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
'use client';
22

3-
import { useMemo, useState } from 'react';
3+
import { SetStateAction, Dispatch } from 'react';
44
import { Search } from 'lucide-react';
55
import { DiceCmds, DiceCmdMeta } from '@/data/command';
66
import CommandPage from './command';
77
import NotFoundPage from './NotFoundPage';
88

9-
export default function SearchBox() {
10-
const [search, setSearch] = useState('');
11-
const filteredCommands = useMemo(
12-
() =>
13-
Object.values(DiceCmds).filter((cmd: DiceCmdMeta) =>
14-
cmd.title.toLowerCase().includes(search.toLowerCase()),
15-
),
16-
[search],
9+
interface SearchBoxProps {
10+
search: string;
11+
setSearch: Dispatch<SetStateAction<string>>;
12+
}
13+
14+
export default function SearchBox({ search, setSearch }: SearchBoxProps) {
15+
const filteredCommands = Object.values(DiceCmds).filter((cmd: DiceCmdMeta) =>
16+
cmd.title.toLowerCase().includes(search.toLowerCase()),
1717
);
1818

1919
return (

src/components/Search/command.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client';
2-
31
import { Clipboard } from 'lucide-react';
42
import { DiceCmdMeta } from '@/data/command';
53
import { useState } from 'react';
@@ -16,11 +14,11 @@ export default function CommandPage({
1614
onCopy,
1715
}: CommandPageProps) {
1816
const [isCopied, setIsCopied] = useState(false);
17+
setIsCopied(true);
18+
setTimeout(() => {
19+
setIsCopied(false);
20+
}, 1000);
1921
const handleCopy = () => {
20-
setIsCopied(true);
21-
setTimeout(() => {
22-
setIsCopied(false);
23-
}, 1000);
2422
navigator.clipboard.writeText(syntax).then(() => {
2523
if (onCopy) {
2624
onCopy();

src/shared/hooks/useTimer.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)