Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
onejuice98 committed Jan 20, 2023
1 parent 9f3d97c commit 1b264bc
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 337 deletions.
158 changes: 12 additions & 146 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,161 +1,27 @@
import React, { useEffect, useRef, useState } from "react";
import { useRecoilValue } from "recoil";
import DDays from "./components/dDay/Ddays";
import SetDday from "./components/dDay/SetDday";
import Today from "./components/dDay/Today";

import Layout from "./components/layout/Layout";
import Profile from "./components/profile/Profile";
import {
dDayListState,
dDayUserInputState,
isSubmitState,
UserInput,
} from "./reocil/dDay";
import Layout from "components/layout/Layout";
import Profile from "components/profile/Profile";
import { dDayUserInputState, UserInput } from "./recoil/dDay";
import Dday from "components/dDay/Dday";
import SetDday from "components/dDay/SetDday";
import Horizon from "components/common/Horizon";
import Skeleton from "components/common/Skeleton";

function App() {
const dDayUserInput = useRecoilValue<UserInput>(dDayUserInputState);
const dDayList = useRecoilValue<UserInput[]>(dDayListState);
const isSubmit = useRecoilValue<boolean>(isSubmitState);
const [open, setOpen] = useState(false);
const handleModal = () => setOpen((prev) => !prev);

const modalRef = useRef<HTMLDivElement>(null);
// recoil 이용해서 얻어낸 엄청난 업적!!!!!!!!!!!!!
// recoil setDday.tsx 에서 얻은 데이터를 어떻게 띄울까 생각했는데 modal 창이 여닫힐때마다 마운트 되게해서 해결!!!
useEffect(() => {}, [dDayUserInput.date]);
console.log(dDayList);
return (
<div>
<Layout>
<Profile />
{open && (
<div className="z-10 absolute top-0 left-0 w-[100vw] h-[100vh] bg-black/[0.75] flex justify-center items-center">
<div className="relative w-[80%] h-[80%] z-10 bg-white opacity-1 rounded-lg flex flex-col justify-between">
<SetDday />
<div className="flex flex-col h-full m-2 justify-start gap-2">
{isSubmit &&
dDayList.map((value, idx) => (
<div
key={idx + 1}
className="w-full h-12 bg-orange-200 rounded-md p-1 shadow-md"
>
{value.dDayName} {value.date}
</div>
))}
</div>
<div className="flex justify-end items-end bg-gray-100 rounded-lg">
<button
className="w-20 h-10 bg-red-500 text-white rounded-md shadow-lg m-4 font-mono font-medium hover:bg-red-700"
onClick={handleModal}
>
나가기
</button>
</div>
</div>
</div>
)}
<hr className="m-4 border-gray-300 sm:mx-auto dark:border-gray-700" />

<Horizon />
<div className="m-4 flex gap-2 justify-between items-center">
<div>
<Today />
<DDays
dDayName={dDayUserInput.dDayName}
date={dDayUserInput.date}
/>
</div>
<Dday dDayName={dDayUserInput.dDayName} date={dDayUserInput.date} />

<button
data-collapse-toggle="navbar-sticky"
type="button"
className="inline-flex items-center p-2 text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600"
aria-controls="navbar-sticky"
aria-expanded="false"
onClick={handleModal}
>
<svg
className="w-4 h-4"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"
clip-rule="evenodd"
></path>
</svg>
</button>
<SetDday />
</div>
<hr className="m-4 border-gray-300 sm:mx-auto dark:border-gray-700" />
<Horizon />
<div className="flex flex-col gap-6 mx-4 my-6">
<div
role="status"
className="max-w-sm p-4 border border-gray-200 rounded shadow md:p-6 dark:border-gray-700"
>
<div className="flex items-center justify-center h-48 mb-4 bg-gray-300 rounded dark:bg-gray-700">
<svg
className="w-12 h-12 text-gray-200 dark:text-gray-600"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 640 512"
>
<path d="M480 80C480 35.82 515.8 0 560 0C604.2 0 640 35.82 640 80C640 124.2 604.2 160 560 160C515.8 160 480 124.2 480 80zM0 456.1C0 445.6 2.964 435.3 8.551 426.4L225.3 81.01C231.9 70.42 243.5 64 256 64C268.5 64 280.1 70.42 286.8 81.01L412.7 281.7L460.9 202.7C464.1 196.1 472.2 192 480 192C487.8 192 495 196.1 499.1 202.7L631.1 419.1C636.9 428.6 640 439.7 640 450.9C640 484.6 612.6 512 578.9 512H55.91C25.03 512 .0006 486.1 .0006 456.1L0 456.1z" />
</svg>
</div>
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
<div className="flex items-center mt-4 space-x-3">
<svg
className="text-gray-200 w-14 h-14 dark:text-gray-700"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-6-3a2 2 0 11-4 0 2 2 0 014 0zm-2 4a5 5 0 00-4.546 2.916A5.986 5.986 0 0010 16a5.986 5.986 0 004.546-2.084A5 5 0 0010 11z"
clip-rule="evenodd"
></path>
</svg>
<div>
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-32 mb-2"></div>
<div className="w-48 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
</div>
</div>
<span className="sr-only">Loading...</span>
</div>
<div
role="status"
className="space-y-8 animate-pulse md:space-y-0 md:space-x-8 md:flex md:items-center"
>
<div className="flex items-center justify-center w-full h-48 bg-gray-300 rounded sm:w-96 dark:bg-gray-700">
<svg
className="w-12 h-12 text-gray-200"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 640 512"
>
<path d="M480 80C480 35.82 515.8 0 560 0C604.2 0 640 35.82 640 80C640 124.2 604.2 160 560 160C515.8 160 480 124.2 480 80zM0 456.1C0 445.6 2.964 435.3 8.551 426.4L225.3 81.01C231.9 70.42 243.5 64 256 64C268.5 64 280.1 70.42 286.8 81.01L412.7 281.7L460.9 202.7C464.1 196.1 472.2 192 480 192C487.8 192 495 196.1 499.1 202.7L631.1 419.1C636.9 428.6 640 439.7 640 450.9C640 484.6 612.6 512 578.9 512H55.91C25.03 512 .0006 486.1 .0006 456.1L0 456.1z" />
</svg>
</div>
<div className="w-full">
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[480px] mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[440px] mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[460px] mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[360px]"></div>
</div>
<span className="sr-only">Loading...</span>
</div>
<Skeleton />
</div>
</Layout>
</div>
Expand Down
20 changes: 20 additions & 0 deletions src/components/common/Horizon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @params marginX, marginY (default : 0)
* @params border color (default : gray-300)
*
* @returns hr tag
*/

interface IHorizon {
margin?: "0" | "1" | "2" | "3" | "4" | "5" | "6";
borderColor?: string;
}
const Horizon = ({ margin = "4", borderColor = "gray" }: IHorizon) => {
return (
<hr
className={`m-${margin} border-${borderColor}-300 dark:border-${borderColor}-700`}
/>
);
};

export default Horizon;
33 changes: 33 additions & 0 deletions src/components/common/JuiceFont.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
*
* @params isBold (default : font-medium)
* @params isSmall (default : text-base)
* @params others (enter tailwindCSS)
*/

interface IJuiceFont {
isBold?: boolean;
isSmall?: boolean;
others?: string;
children: React.ReactNode;
}
const JuiceFont = ({
isBold = false,
isSmall = false,
others = "none",
children,
}: IJuiceFont) => {
return (
<>
<div
className={`font-mono ${isBold && `font-bold`} ${
isSmall && `text-sm`
} ${others}`}
>
{children}
</div>
</>
);
};

export default JuiceFont;
73 changes: 73 additions & 0 deletions src/components/common/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const Skeleton = () => {
return (
<>
<div
role="status"
className="max-w-sm p-4 border border-gray-200 rounded shadow md:p-6 dark:border-gray-700"
>
<div className="flex items-center justify-center h-48 mb-4 bg-gray-300 rounded dark:bg-gray-700">
<svg
className="w-12 h-12 text-gray-200 dark:text-gray-600"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 640 512"
>
<path d="M480 80C480 35.82 515.8 0 560 0C604.2 0 640 35.82 640 80C640 124.2 604.2 160 560 160C515.8 160 480 124.2 480 80zM0 456.1C0 445.6 2.964 435.3 8.551 426.4L225.3 81.01C231.9 70.42 243.5 64 256 64C268.5 64 280.1 70.42 286.8 81.01L412.7 281.7L460.9 202.7C464.1 196.1 472.2 192 480 192C487.8 192 495 196.1 499.1 202.7L631.1 419.1C636.9 428.6 640 439.7 640 450.9C640 484.6 612.6 512 578.9 512H55.91C25.03 512 .0006 486.1 .0006 456.1L0 456.1z" />
</svg>
</div>
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
<div className="flex items-center mt-4 space-x-3">
<svg
className="text-gray-200 w-14 h-14 dark:text-gray-700"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-6-3a2 2 0 11-4 0 2 2 0 014 0zm-2 4a5 5 0 00-4.546 2.916A5.986 5.986 0 0010 16a5.986 5.986 0 004.546-2.084A5 5 0 0010 11z"
clip-rule="evenodd"
></path>
</svg>
<div>
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-32 mb-2"></div>
<div className="w-48 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
</div>
</div>
<span className="sr-only">Loading...</span>
</div>
<div
role="status"
className="space-y-8 animate-pulse md:space-y-0 md:space-x-8 md:flex md:items-center"
>
<div className="flex items-center justify-center w-full h-48 bg-gray-300 rounded sm:w-96 dark:bg-gray-700">
<svg
className="w-12 h-12 text-gray-200"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 640 512"
>
<path d="M480 80C480 35.82 515.8 0 560 0C604.2 0 640 35.82 640 80C640 124.2 604.2 160 560 160C515.8 160 480 124.2 480 80zM0 456.1C0 445.6 2.964 435.3 8.551 426.4L225.3 81.01C231.9 70.42 243.5 64 256 64C268.5 64 280.1 70.42 286.8 81.01L412.7 281.7L460.9 202.7C464.1 196.1 472.2 192 480 192C487.8 192 495 196.1 499.1 202.7L631.1 419.1C636.9 428.6 640 439.7 640 450.9C640 484.6 612.6 512 578.9 512H55.91C25.03 512 .0006 486.1 .0006 456.1L0 456.1z" />
</svg>
</div>
<div className="w-full">
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[480px] mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[440px] mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[460px] mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[360px]"></div>
</div>
<span className="sr-only">Loading...</span>
</div>
</>
);
};

export default Skeleton;
69 changes: 69 additions & 0 deletions src/components/dDay/DayInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from "react";
import { useRecoilState, useSetRecoilState } from "recoil";
import {
dDayListState,
dDayUserInputState,
isSubmitState,
} from "../../recoil/dDay";
import Horizon from "../common/Horizon";

type UserInput = { dDayName: string; date: string };
const DayInput = () => {
const setIsSubmit = useSetRecoilState<boolean>(isSubmitState);
const [userInputs, setUserInputs] =
useRecoilState<UserInput>(dDayUserInputState);
const [list, setList] = useRecoilState<UserInput[]>(dDayListState);
const handleChange = (event: React.FormEvent<HTMLInputElement>) => {
setUserInputs({
...userInputs,
[event.currentTarget.name]: event.currentTarget.value,
});
};
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (userInputs.dDayName === "" || userInputs.date === "") {
return;
} else {
setIsSubmit(true);
setList([...list, userInputs]);
}
event.currentTarget.reset();
};
/*
const deleteItem = (event: React.FormEvent<HTMLInputElement>) => {
const key = event.currentTarget.value;
list.splice(parseInt(key), 1);
setList([...list]);
};*/
return (
<div className="mt-4">
<form
name="isSubmit"
onSubmit={handleSubmit}
className="flex justify-between px-4"
>
<input
name="dDayName"
type="text"
placeholder="D-day 이름"
onChange={handleChange}
className="w-[40%] rounded-md shadow-md focus:ring-blue-200 hover:animate-pulse"
/>
<input
name="date"
type="date"
onChange={handleChange}
className="w-[40%] rounded-md shadow-md focus:ring-blue-200 hover:animate-pulse"
/>
<button
type="submit"
className="w-[10%] bg-sky-500 text-white rounded-md font-mono text-sm shadow-md hover:bg-sky-700"
>
+
</button>
</form>
<Horizon />
</div>
);
};
export default DayInput;

0 comments on commit 1b264bc

Please sign in to comment.