Skip to content

Commit 3e1ecb0

Browse files
committed
fixes
2 parents 1eea08c + f8ab844 commit 3e1ecb0

20 files changed

Lines changed: 3777 additions & 3217 deletions

apps/web/app/page.tsx

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"use client";
22
import { MainHomeLayout } from "@repo/web-ui/layout";
3-
import React, { useState } from "react";
3+
import React, { useCallback, Suspense } from "react";
4+
import { useSearchParams, useRouter } from "next/navigation";
45
import "./page.module.css";
56
import QuizMarkdownEditor from "../components/markdown-editor";
67
import ChatgptEditor from "../components/chatgpt-editor";
7-
import TwitterEditor from "../components/twitter-editor";
8+
import XEditor from "../components/x-editor";
89

910
import GradientEditor from "../components/gradient-editor";
1011
import { CardSizeProvider } from "@repo/ui/context/CardSizeContext";
@@ -18,29 +19,45 @@ const tabs = [
1819
key: "chatgpt",
1920
label: "ChatGPT Card",
2021
},
21-
// {
22-
// key: "gradient",
23-
// label: "Gradient Card",
24-
// },
2522
{
26-
key: "twitter",
27-
label: "Twitter Card",
23+
key: "gradient",
24+
label: "Gradient Card",
25+
},
26+
{
27+
key: "x",
28+
label: "X Card",
2829
},
2930

3031
];
3132

32-
export default function Home() {
33-
const [tab, setTab] = useState("markdown");
33+
function HomeContent() {
34+
const searchParams = useSearchParams();
35+
const router = useRouter();
36+
37+
const currentTab = searchParams.get("t") || "markdown";
38+
39+
const setTab = useCallback((newTab: string) => {
40+
const params = new URLSearchParams(searchParams.toString());
41+
params.set("t", newTab);
42+
router.push(`?${params.toString()}`);
43+
}, [searchParams, router]);
3444

3545
return (
36-
<MainHomeLayout tab={tab} tabs={tabs} setTab={setTab}>
46+
<MainHomeLayout tab={currentTab} tabs={tabs} setTab={setTab}>
3747
<CardSizeProvider>
38-
{tab === "markdown" ? <QuizMarkdownEditor /> : null}
39-
{tab === "chatgpt" ? <ChatgptEditor /> : null}
40-
{/* {tab === "gradient" ? <GradientEditor /> : null} */}
41-
{tab === "twitter" ? <TwitterEditor /> : null}
42-
48+
{currentTab === "markdown" ? <QuizMarkdownEditor /> : null}
49+
{currentTab === "chatgpt" ? <ChatgptEditor /> : null}
50+
{currentTab === "gradient" ? <GradientEditor /> : null}
51+
{currentTab === "x" ? <XEditor /> : null}
4352
</CardSizeProvider>
4453
</MainHomeLayout>
4554
);
46-
}
55+
}
56+
57+
export default function Home() {
58+
return (
59+
<Suspense fallback={<div>Loading...</div>}>
60+
<HomeContent />
61+
</Suspense>
62+
);
63+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"use client";
2+
import { Slider } from "../ui/slider";
3+
import { Input } from "../ui/input";
4+
import { Textarea } from "../ui/textarea";
5+
import { cn } from "../../lib/cn";
6+
7+
function SliderBox({
8+
keyName,
9+
value,
10+
label,
11+
min,
12+
max,
13+
unit,
14+
widthWrapper = false,
15+
formatValue = false,
16+
setStateValue,
17+
}: {
18+
keyName: string;
19+
value: number;
20+
label: string;
21+
min: number;
22+
max: number;
23+
unit?: string;
24+
formatValue?: boolean;
25+
widthWrapper?: boolean;
26+
setStateValue: (name: string, value: any) => void;
27+
}) {
28+
const comp = (
29+
<>
30+
<label className="block mb-2">
31+
{label || <span>{keyName}</span>}:{" "}
32+
{formatValue ? (
33+
<span>{new Intl.NumberFormat().format(value)}</span>
34+
) : (
35+
value
36+
)}
37+
{unit && <span className="">{unit}</span>}
38+
</label>
39+
<Slider
40+
min={min}
41+
max={max}
42+
name={keyName}
43+
value={[value]}
44+
onValueChange={(val) => setStateValue(keyName, val)}
45+
className="w-full"
46+
/>
47+
</>
48+
);
49+
50+
if (widthWrapper) {
51+
return <WithWrapper>{comp}</WithWrapper>;
52+
}
53+
return comp;
54+
}
55+
56+
function DrawInput({
57+
keyName,
58+
value,
59+
placeholder,
60+
label,
61+
onChange: setStateValue,
62+
isTextArea = false,
63+
type = "text",
64+
className = "",
65+
}: {
66+
keyName: string;
67+
value: string;
68+
placeholder?: string;
69+
label?: React.ReactNode;
70+
onChange: (name: string, value: any) => void;
71+
isTextArea?: boolean;
72+
type?: string;
73+
className?: string;
74+
}) {
75+
return (
76+
<div className={cn("mb-4", className)}>
77+
<label className="block">{label || <span>{keyName}</span>}:</label>
78+
{isTextArea ? (
79+
<Textarea
80+
value={value}
81+
onChange={(e) => setStateValue(keyName, e.target.value)}
82+
className="w-full px-2 border rounded-md"
83+
placeholder={placeholder}
84+
/>
85+
) : (
86+
<Input
87+
type={type}
88+
value={value}
89+
onChange={(e) => setStateValue(keyName, e.target.value)}
90+
className="w-full px-2 border rounded-md"
91+
placeholder={placeholder}
92+
/>
93+
)}
94+
</div>
95+
);
96+
}
97+
98+
function WithWrapper({ children }: { children: React.ReactNode }) {
99+
return (
100+
<div className="flex flex-col mt-4 border p-2 rounded-md">{children}</div>
101+
);
102+
}
103+
104+
function CheckBox({
105+
keyName,
106+
value,
107+
label,
108+
setStateValue,
109+
widthWrapper = false,
110+
}: {
111+
keyName: string;
112+
value: boolean;
113+
label: string;
114+
widthWrapper?: boolean;
115+
setStateValue: (name: string, value: any) => void;
116+
}) {
117+
const component = (
118+
<label className="flex items-center">
119+
<input
120+
type="checkbox"
121+
checked={value}
122+
name={keyName}
123+
onChange={(e) => setStateValue(keyName, e.target.checked)}
124+
className="mr-2"
125+
/>
126+
{label || <span>{keyName}</span>}
127+
</label>
128+
);
129+
130+
if (widthWrapper) {
131+
return <WithWrapper>{component}</WithWrapper>;
132+
}
133+
return component;
134+
}
135+
136+
export { SliderBox, DrawInput, CheckBox };

0 commit comments

Comments
 (0)