Skip to content

Commit

Permalink
theme fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jongwony committed Nov 4, 2024
1 parent cb3fd59 commit c251704
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
26 changes: 18 additions & 8 deletions src/app/form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import Image from "next/image"

interface TemplateProps {
templates: {id: string, name: string, path: string, src: string, dark: string, light: string}[];
initialTheme?: "light" | "dark";
onThemeChange: (theme: "light" | "dark") => void;
onThemeChange: (theme: string) => void;
onTemplateChange: (template: string) => void;
}

export default function ChooseTemplate({ templates, initialTheme, onThemeChange, onTemplateChange }: TemplateProps) {
export default function ChooseTemplate({ templates, onThemeChange, onTemplateChange }: TemplateProps) {
const [currentTemplate, setCurrentTemplate] = useState(0);
const [dragStart, setDragStart] = useState(0);
const [currentTheme, setCurrentTheme] = useState<"light" | "dark">(initialTheme || "dark");
const [currentTheme, setCurrentTheme] = useState('dark');
const [direction, setDirection] = useState(1); // 방향 상태 유지

useEffect(() => {
onTemplateChange(templates[currentTemplate].id);
onThemeChange(currentTheme);
}, [currentTemplate]);

const handleThemeChange = (theme: "light" | "dark") => {
const handleThemeChange = (theme: string) => {
setCurrentTheme(theme)
onThemeChange(theme)
}
Expand Down Expand Up @@ -130,8 +130,8 @@ export default function ChooseTemplate({ templates, initialTheme, onThemeChange,
</button>
</div>

{(templates[currentTemplate].src === '') &&
<div className="flex justify-center items-center gap-4">
{(templates[currentTemplate].src === '') ? (
<div className="flex justify-center items-center gap-4">
<button
type="button"
onClick={() => handleThemeChange("light")}
Expand All @@ -146,7 +146,17 @@ export default function ChooseTemplate({ templates, initialTheme, onThemeChange,
}`}
aria-label="Dark theme"
/>
</div>}
</div>
) : (
<div className="flex justify-center items-center gap-4">
<button
type="button"
className={`w-8 h-8 rounded-full border-2 bg-black transition-all bg-gradient-to-tr from-yellow-500 via-pink-500 to-blue-500 border-blue-500 scale-110"
}`}
aria-label="Special theme"
/>
</div>
)}
</div>
)
}
7 changes: 4 additions & 3 deletions src/app/form/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Insta1Form {
bio?: string;
code: string;
email: string;
theme?: "light" | "dark";
theme: string;
}

export interface InstaSpecialForm {
Expand All @@ -17,6 +17,7 @@ export interface InstaSpecialForm {
bio?: string;
code: string;
email: string;
theme: string;
}

export interface Linkedin1Form {
Expand All @@ -28,7 +29,7 @@ export interface Linkedin1Form {
joinDate?: string;
code: string;
email: string;
theme?: "light" | "dark";
theme: string;
}

export interface Linkedin2Form {
Expand All @@ -39,7 +40,7 @@ export interface Linkedin2Form {
company?: string;
code: string;
email: string;
theme?: "light" | "dark";
theme: string;
}

export type FormDataTypes = Insta1Form | InstaSpecialForm | Linkedin1Form | Linkedin2Form;
3 changes: 1 addition & 2 deletions src/app/form/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const FormPage = (): React.ReactElement => {
const [isButtonDisabled, setIsButtonDisabled] = useState(true);

const validateForm = useCallback(() => {
return formData.email !== '' && formData.code !== '';
return formData.email !== '';
}, [formData]);

useEffect(() => {
Expand Down Expand Up @@ -126,7 +126,6 @@ const FormPage = (): React.ReactElement => {
<form onSubmit={sendFormData} className="grid grid-cols-1 md:grid-cols-2 gap-8 max-w-4xl">
<ChooseTemplate
templates={templates}
initialTheme={"dark"}
onThemeChange={theme => setFormData(prevData => ({ ...prevData, theme }))}
onTemplateChange={(template) => {
setFormData(prevData => ({ ...prevData, template }));
Expand Down

0 comments on commit c251704

Please sign in to comment.