Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#71 글쓰기 페이지 #81

Merged
merged 16 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function App(): JSX.Element {
<Suspense fallback={<div />}>
<Routes>
<Route path="/" element={<DefaultLayout />}>
<Route path="/post" element={<Post />} />
<Route path="/search" element={<Search />} />
<Route path="/search/:keyword" element={<SearchDetails />} />
<Route path="/inquiry" element={<Inquiry />} />
Expand All @@ -36,6 +35,7 @@ export default function App(): JSX.Element {
<Route path="/setting" element={<Setting />} />
<Route path="/setting/id-change" element={<IdChange />} />
<Route path="/withdrawal" element={<Withdrawal />} />
<Route path="/post" element={<Post />} />
</Route>
<Route element={<AuthRoute needAuth={false} redirectRoute="/" />}>
<Route path="/login" element={<Login />} />
Expand Down
4 changes: 4 additions & 0 deletions src/assets/svg/post/cancel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/assets/svg/post/picture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/MyInquiry/MyInquiry.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$highlight: #ff7f23;

.my-inquiry {
.title {
display: flex;
justify-content: center;
align-items: center;
Expand All @@ -18,6 +18,6 @@ $highlight: #ff7f23;
text-decoration: none;
}

.move {
.moveIcon {
hyejun0228 marked this conversation as resolved.
Show resolved Hide resolved
margin-left: 9px;
}
8 changes: 4 additions & 4 deletions src/components/MyInquiry/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Link } from 'react-router-dom';
import { ReactComponent as Move } from 'assets/svg/inquiry/myinquiry.svg';
import { ReactComponent as MoveIcon } from 'assets/svg/inquiry/myinquiry.svg';
import styles from './MyInquiry.module.scss';

export default function MyInquiry(): JSX.Element {
return (
<div>
<Link to="/myinquiry" className={styles.link}>
<div className={styles['my-inquiry']}>
<div className={styles.title}>
나의 문의 바로가기
<div className={styles.move}>
<Move />
<div className={styles.moveIcon}>
<MoveIcon />
</div>
</div>
</Link>
Expand Down
4 changes: 3 additions & 1 deletion src/components/StarRating/StarRating.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
align-items: center;
width: 160px;
height: 32px;
margin-bottom: 24px;
margin-bottom: 16px;
}

.wrapper {
Expand All @@ -14,6 +14,8 @@
justify-content: center;
background: none;
border: none;
padding-top: 35px;
padding-bottom: 35px;

&__star {
transition: all 0.2s ease-out;
Expand Down
77 changes: 77 additions & 0 deletions src/components/editor/TextEditor/AddImage/AddImage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.container {
display: flex;
width: 320px;
margin-left: 20px;
white-space: nowrap;
overflow-x: scroll;

&__item {
display: flex;
margin: 6px 2px 10px;
position: relative;
}

&__button {
width: 18px;
height: 18px;
margin-left: 62px;
border: solid 5px;
border-color: #ff7f23;
border-radius: 50%;
background-color: transparent;
z-index: 2;
position: absolute;
}

&__image {
display: flex;
width: 80px;
height: 80px;
object-fit: cover;
border-radius: 10px;
margin-top: 10px;
cursor: pointer;
}

&::-webkit-scrollbar {
display: none;
scrollbar-width: none;
}
}

.editor {
line-height: 15px;
height: 450px;
width: 357px;
font-size: 16px;
color: #222222;
z-index: 1;

&--withImage {
height: calc(100% - 220px);
}
}

.button-container {
display: flex;
flex-direction: row-reverse;
}

.addImage-button {
display: flex;
justify-content: center;
z-index: 2;
background-color: white;
width: 48px;
height: 48px;
align-items: center;
border-radius: 50px;
box-shadow: 2px 3px 12px 1px rgb(0 0 0 / 10%);
position: relative;
right: 35px;
bottom: 55px;
}

.input {
display: none;
}
33 changes: 13 additions & 20 deletions src/components/editor/TextEditor/AddImage/ImageItem.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
import { ReactComponent as Trash } from 'assets/svg/post/trash.svg';
import { ReactComponent as Trash } from 'assets/svg/post/cancel.svg';
import { useRef } from 'react';
import useBooleanState from 'utils/hooks/useBooleanState';
import useOnClickOutside from 'utils/hooks/useOnClickOutside';
import styles from '../TextEditor.module.scss';
import styles from './AddImage.module.scss';

interface Props {
value: string,
onDelete: (value: string) => void,
}

export default function ImageItem({ value, onDelete }: Props) {
const [opened, open, close] = useBooleanState(false);
const imageRef = useRef<HTMLInputElement>(null);
useOnClickOutside(imageRef, close);

return (
<>
{ opened && (
<button
type="button"
aria-label="trash"
className={styles['image-container__button']}
onClick={() => onDelete(value)}
>
<Trash />
</button>
)}
<div>
<button
type="button"
aria-label="trash"
className={styles.container__button}
onClick={() => onDelete(value)}
>
<Trash />
</button>
<input
type="image"
alt=""
className={styles['image-container__image']}
className={styles.container__image}
src={value}
ref={imageRef}
onClick={open}
/>
</>
</div>
);
}
50 changes: 33 additions & 17 deletions src/components/editor/TextEditor/AddImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
import { ReactComponent as Picture } from 'assets/svg/post/picture.svg';
import { useEffect } from 'react';
import styles from '../TextEditor.module.scss';
import { useEffect, useRef } from 'react';
import Wysiwyg, { WysiwygType } from 'components/editor/Wysiwyg';
import useBooleanState from 'utils/hooks/useBooleanState';
import cn from 'utils/ts/classNames';
import styles from './AddImage.module.scss';
import useImageList from '../hooks/useImageList';
import ImageItem from './ImageItem';

interface Props {
active: () => void,
inActive: () => void,
}

function AddImage({ active, inActive }: Props) {
function AddImage() {
const { imageList, addImage, removeImage } = useImageList();
const wysiwygRef = useRef<WysiwygType | null>(null);
const [opened, active, inActive] = useBooleanState(false);
useEffect(() => {
if (imageList === null || imageList.length === 0) inActive();
else active();
}, [imageList, active, inActive]);
Comment on lines +13 to 17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘내들을 모아서 로직을 분리한다면, useWisiwygImageOpen 같은 훅으로 모아서 useEffect를 넣어두는 쪽으로 작성한다면 컴포넌트에 로직이 뭉치는 것을 방지할 수 있을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const [opened, active, inActive] = useBooleanState(false); 에서 반환되는 값들이 useEffect 뿐만아니라 AddImage.tsx 에도 쓰이고 있어 컴포넌트를 나눠준다면 더 복잡해지지 않을까요..?!


return (
<>
<button
type="button"
className={styles.item__button}
onClick={addImage}
>
<Picture />
</button>
<div className={styles['image-container']}>
<div className={styles.container}>
{ imageList?.map((value) => (
<div key={value} className={styles['image-container__item']}>
<div key={value} className={styles.container__item}>
<ImageItem value={value} onDelete={removeImage} />
</div>
))}
</div>
<div
className={cn({
[styles.editor]: true,
[styles['editor--withImage']]: opened,
})}
>
<Wysiwyg ref={wysiwygRef} />
</div>
<div className={styles['button-container']}>
<label htmlFor="image">
<div className={styles['addImage-button']}>
<Picture />
</div>
<input
type="file"
onChange={addImage}
id="image"
className={styles.input}
multiple
accept="image/jpeg,image/gif,image/png"
/>
</label>
</div>
</>
);
}
Expand Down
47 changes: 47 additions & 0 deletions src/components/editor/TextEditor/AddImageFile/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState, ChangeEvent } from 'react';
import { ReactComponent as Plus } from 'assets/svg/post/picture.svg';
import styles from './AddImageFile.module.scss';

function AddImageFile() {
const [imageSrc, setImageSrc] = useState<string>();

const encodeFileToBase64 = (fileBlob: Blob) => {
const reader = new FileReader();
reader.readAsDataURL(fileBlob);
return new Promise<void>((resolve) => {
reader.onload = () => {
setImageSrc(reader.result as string);
resolve();
};
});
};

const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files && e.target.files[0];
if (file) {
encodeFileToBase64(file);
}
};

return (
<main>
<label htmlFor="image">
<div className={styles.getImage}>
<Plus className={styles.getImage__Image} />
</div>
<input
type="file"
onChange={handleFileChange}
id="image"
className={styles.input}
multiple
/>
</label>
<div>
{imageSrc && <img src={imageSrc} alt="preview-img" width="80" height="80" className={styles.preview} />}
</div>
</main>
);
}

export default AddImageFile;
Loading