Skip to content

Commit

Permalink
refactor: Editor와 VideoList컴포넌트에 중복적으로 존재하던 코드를 LogoSelect 컴포넌트로 코드 리…
Browse files Browse the repository at this point in the history
…펙토링함
  • Loading branch information
qkrwoghd04 committed Jan 17, 2025
1 parent 3a3fa7c commit b1bd101
Show file tree
Hide file tree
Showing 37 changed files with 614 additions and 210 deletions.
2 changes: 1 addition & 1 deletion dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['./workbox-54d0af47'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.dbuqiibdomg"
"revision": "0.48tff2uhq0g"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
496 changes: 462 additions & 34 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
},
"dependencies": {
"axios": "^1.7.9",
"motion": "^11.18.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^7.0.2",
"react-select": "^5.9.0",
"react-youtube": "^10.1.0"
},
"devDependencies": {
Expand Down
Binary file removed public/Moneygraphy-Pixel.ttf
Binary file not shown.
Binary file removed public/Moneygraphy-Rounded.ttf
Binary file not shown.
Binary file added public/NanumSquareB.ttf
Binary file not shown.
Binary file added public/NanumSquareEB.ttf
Binary file not shown.
Binary file added public/NanumSquareL.ttf
Binary file not shown.
Binary file added public/NanumSquareR.ttf
Binary file not shown.
Binary file added public/NanumSquare_acB.ttf
Binary file not shown.
Binary file added public/NanumSquare_acEB.ttf
Binary file not shown.
Binary file added public/NanumSquare_acL.ttf
Binary file not shown.
Binary file added public/NanumSquare_acR.ttf
Binary file not shown.
Binary file removed public/SpoqaHanSansNeo-Bold.ttf
Binary file not shown.
Binary file removed public/SpoqaHanSansNeo-Light.ttf
Binary file not shown.
Binary file removed public/SpoqaHanSansNeo-Medium.ttf
Binary file not shown.
Binary file removed public/SpoqaHanSansNeo-Regular.ttf
Binary file not shown.
Binary file removed public/SpoqaHanSansNeo-Thin.ttf
Binary file not shown.
11 changes: 10 additions & 1 deletion src/components/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import "./css/Button.css";
import { motion } from "motion/react";

const Button = ({ text, type, onClick }) => {
return <button onClick={onClick} className={`Button Button_${type}`}>{text}</button>
return (
<motion.button
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
onClick={onClick}
className={`Button Button_${type}`}>
{text}
</motion.button>
)
}

export default Button;
34 changes: 18 additions & 16 deletions src/components/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { useEffect, useState } from 'react'
import './css/Editor.css'
import LogoItem from './LogoItem'
import Button from './Button'
import { useNavigate } from 'react-router-dom'
import { LogoList } from '../utils/constants'
import { getStringedDate } from '../utils/getStringedDate'
import LogoSelector from './LogoSelector'

const Editor = ({ initData, onSubmit, videoId = "" }) => {
const [input, setInput] = useState({
createdDate: new Date(),
content: ["", "", ""],
videoId: "",
logoName: ""
});

const nav = useNavigate();
Expand Down Expand Up @@ -55,6 +56,16 @@ const Editor = ({ initData, onSubmit, videoId = "" }) => {
onSubmit(updatedInput);
};

const handleLogoSelect = (company) => {
onChangeInput({
target: {
name: "logoName",
value: company
}
});
}


useEffect(() => {
if (initData) {
setInput({
Expand All @@ -65,6 +76,8 @@ const Editor = ({ initData, onSubmit, videoId = "" }) => {
}
}, [initData]);

console.log(input.logoName)

return (
<div className='Editor'>
{/* 날짜 선택 */}
Expand All @@ -75,21 +88,10 @@ const Editor = ({ initData, onSubmit, videoId = "" }) => {
{/* 로고 섹션 */}
<section className='logo_section'>
<h4>주제</h4>
<div className='logo_list_wrapper'>
{LogoList.map((item, index) => {
return (
<LogoItem
key={index} {...item}
isSelected={item.logoId === input.logoId}
onClick={() => onChangeInput({
target: {
name: "logoId",
value: item.logoId
}
})} />
)
})}
</div>
<LogoSelector
selectedLogo={input.logoName}
onLogoSelect={handleLogoSelect}
/>
</section>
{/* if videoId 비디오 섹션 */}
{
Expand Down
3 changes: 1 addition & 2 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './css/Header.css';


const Header = ({ title, leftChild, rightChild, color = "black" }) => {
return (
<header
Expand All @@ -13,4 +12,4 @@ const Header = ({ title, leftChild, rightChild, color = "black" }) => {
)
}

export default Header;
export default Header;
1 change: 0 additions & 1 deletion src/components/LogoItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getLogoImage } from '../utils/getLogoImage'

const LogoItem = ({ logoId, isSelected, onClick }) => {
return (

<div onClick={onClick} className={`LogoItem ${isSelected ? `LogoItem_on_${logoId}` : ""}`}>
<img className="logo_img" src={getLogoImage(logoId)} />
</div>
Expand Down
24 changes: 24 additions & 0 deletions src/components/LogoSelector.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import './css/LogoSelector.css'
import LogoItem from './LogoItem'
import { LogoList } from '../utils/constants'

const LogoSelector = ({ selectedLogo, onLogoSelect }) => {
return (
<div className="LogoSelector">
{
LogoList.map((company, index) => {
return (
<LogoItem
key={index}
isSelected={company.logoName === selectedLogo}
onClick={() => onLogoSelect(company.logoName)}
logoId={company.logoId}
/>
)
})
}
</div>
)
}

export default LogoSelector
22 changes: 22 additions & 0 deletions src/components/MenuBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Button from "./Button";
import { useNavigate } from 'react-router-dom'
import './css/MenuBar.css'
import Select from './Select'

const MenuBar = ({ onChange }) => {
const nav = useNavigate();

const handleSelectChange = (selectedOption) => {
onChange({ target: { value: selectedOption.value } });
}

return (
<div className="MenuBar">
<Select onChange={handleSelectChange} />
<Button text={"새 지식 쓰기"} type={"POSITIVE"} onClick={() => nav("/new")} />
<Button text={"영상 글쓰기"} type={"POSITIVE"} onClick={() => nav("/video")} />
</div>
)
}

export default MenuBar
14 changes: 2 additions & 12 deletions src/components/PostList.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import Button from "./Button";
import { useNavigate } from 'react-router-dom'
import PostItem from "./PostItem";
import "./css/PostList.css";
import { useState } from 'react'
import MenuBar from "./MenuBar";


const PostList = ({ data }) => {
const nav = useNavigate();
const [sortType, setSortType] = useState('latest')

const onChangeSortType = e => {
setSortType(e.target.value)
console.log(e.target.value)
}

const getSortedDate = () => {
Expand All @@ -27,14 +24,7 @@ const PostList = ({ data }) => {
const sortedDate = getSortedDate()
return (
<div className="PostList">
<div className="menu_bar">
<select onChange={onChangeSortType}>
<option value={"latest"}>최신순</option>
<option value={"oldest"}>오래된 순</option>
</select>
<Button text={"새 지식 쓰기"} type={"POSITIVE"} onClick={() => nav("/new")} />
<Button text={"영상 글쓰기"} type={"POSITIVE"} onClick={() => nav("/video")} />
</div>
<MenuBar onChange={onChangeSortType} />
<div className="list_wrapper">
{sortedDate.map((item) => {
return (
Expand Down
35 changes: 35 additions & 0 deletions src/components/Select.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ReactSelect from 'react-select'

const options = [
{ value: 'latest', label: '최신순' },
{ value: 'oldest', label: '오래된 순' },
]

const customStyles = {
option: (provided, state) => ({
...provided,
fontWeight: state.isSelected ? "bold" : "normal",
backgroundColor: state.isSelected ? 'rgb(49, 130, 239)' : 'white',
}),
control: (provided) => ({
...provided,
width: 120
}),
singleValue: (provided, state) => ({
...provided,
fontSize: state.selectProps.myFontSize
})
};

const Select = ({ onChange }) => {
return (
<ReactSelect
styles={customStyles}
onChange={onChange}
options={options}
defaultValue={options[0]}
/>
)
}

export default Select
30 changes: 0 additions & 30 deletions src/components/Selector.jsx

This file was deleted.

10 changes: 7 additions & 3 deletions src/components/VideoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState, useMemo } from 'react';
import './css/VideoList.css';
// 컴포넌트
import SearchBar from './SearchBar';
import Selector from './Selector'
import LogoSelector from './LogoSelector'
import VideoItem from './VideoItem'
// constant
import { getStorageVideoIds, storeVideoIds } from '../utils/storage';
Expand Down Expand Up @@ -36,7 +36,6 @@ const VideoList = () => {
const results = await Promise.all(allVideoIdPromises);
const allVideoId = results.flat();

console.log(allVideoId);
storeVideoIds(allVideoId);
setVideoList(allVideoId);
} catch (error) {
Expand Down Expand Up @@ -66,10 +65,15 @@ const VideoList = () => {
);
}, [videoList, searchKeyword]);

const handleLogoSelect = (company) => {
setQuery(company);
setSearchKeyword("");
}

return (
<>
<SearchBar setSearchKeyword={setSearchKeyword} />
<Selector setQuery={setQuery} setSearchKeyword={setSearchKeyword} />
<LogoSelector selectedLogo={query} onLogoSelect={handleLogoSelect} />
{selectedVideo && (
<VideoOverlay selectedVideo={selectedVideo} setSelectedVideo={setSelectedVideo} />
)}
Expand Down
7 changes: 4 additions & 3 deletions src/components/css/Button.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.Button {
background-color: rgb(216, 216, 216);
background-color: rgb(244, 244, 246);
color: black;
border : none;
border-radius: 5px;
Expand All @@ -8,13 +8,14 @@
white-space: nowrap;

font-size: small;
font-weight: 700;
}

.Button_POSITIVE {
background-color: rgb(133, 175, 243);
background-color: rgb(49, 130, 239);
color: white;
}
.Button_NEGATIVE {
background-color: rgb(236, 68, 82);
background-color: rgb(231, 56, 70);
color: white
}
3 changes: 2 additions & 1 deletion src/components/css/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

.Header .header_center {
width: 50%;
font-size: 25px;
font-size: x-large;
font-weight: 500;
justify-content: center;
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/css/LogoItem.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
border-radius: 5px;
cursor: pointer;
text-align: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);

/* 정사각형 모양 유지 */
aspect-ratio: 1;
Expand All @@ -16,7 +17,7 @@
}

.LogoItem .logo_img {
width: 75%;
width: 80%;
height: auto;
object-fit: contain;
margin-bottom: 8px;
Expand Down
6 changes: 6 additions & 0 deletions src/components/css/LogoSelector.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.LogoSelector {
display: flex;
justify-content: center;
gap: 16px;
margin: 20px 0;
}
10 changes: 10 additions & 0 deletions src/components/css/MenuBar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.MenuBar {
margin: 20px 0px;
display: flex;
gap: 10px;
align-items: center;
}

.MenuBar Button {
flex : 1;
}
Loading

0 comments on commit b1bd101

Please sign in to comment.