Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/bodyBudy/bodyBuddy into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
urther committed Jul 6, 2022
2 parents 81f1f3b + 6903314 commit a5672a3
Show file tree
Hide file tree
Showing 24 changed files with 846 additions and 290 deletions.
7 changes: 1 addition & 6 deletions components/common/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,15 @@ export const TopButton = ({ containerRef }: TopButtonProps) => {
const button = useRef<HTMLButtonElement>(null);

useEffect(() => {
if (!containerRef || !button) return;
const HandleScroll = throttle(() => {
if (!button.current) return;
button.current.style.display = containerRef?.current.scrollTop > 100 ? 'block' : 'none';
}, 300);

const GoToTop = () => containerRef.current.scroll({ top: 0, behavior: 'smooth' });

containerRef.current.addEventListener('scroll', HandleScroll);
button.current?.addEventListener('click', GoToTop);

return () => {
containerRef.current.removeEventListener('scroll', HandleScroll);
button.current?.removeEventListener('click', GoToTop);
};
}, []);

return (
Expand Down
30 changes: 29 additions & 1 deletion components/common/buttongroup/buttonGroup.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
interface post {
content: string;
creationDate: Date;
fieldId: string;
images: string | string[];
title: string;
totalComments: number;
userId: string;
}

interface review {
content: string;
creationDate: Date;
isActivation: boolean;
rating: number;
userId: string;
trainerInfo: trainer;
}

interface trainer {
trainerId: string;
image: string;
name: string;
fieldId: string;
introduction: string;
}

interface EditorGroupProps {
selectedItem: string;
className: string;
leftUrl?: string;
EditorURL?: string;
lastEdited?: reveiw | post;
onChangeEditingMode?: Dispatch<SetStateAction<boolean>>;
onChangeDeleteMode: Dispatch<SetStateAction<boolean>>;
}
11 changes: 9 additions & 2 deletions components/common/buttongroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ButtonContainer } from './styledButtonGroup';
const EditorGroup = ({
selectedItem,
className,
leftUrl,
EditorURL,
lastEdited,
onChangeEditingMode,
onChangeDeleteMode,
}: EditorGroupProps) => {
Expand All @@ -16,7 +17,13 @@ const EditorGroup = ({
return (
<ButtonContainer className={className}>
{className !== 'comment' ? (
<Link href={leftUrl ? leftUrl : '/'}>
<Link
href={{
pathname: EditorURL ? EditorURL : '/',
query: { edited: JSON.stringify(lastEdited) },
}}
as={EditorURL}
>
<a>수정</a>
</Link>
) : (
Expand Down
27 changes: 27 additions & 0 deletions components/common/profile/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Image from 'next/image';
import { ChangeEvent } from 'react';
import { StyledImageUploader } from './styledProfile';

export const ProfileUploader = ({ profile, setProfile }: ProfileProps) => {
const uploadImage = (e: ChangeEvent<HTMLInputElement>) => {
e.target.files && setProfile(URL.createObjectURL(e.target.files[0]));
};

return (
<StyledImageUploader>
<div className={profile ? 'uploaded' : ''}>
{profile ? (
<>
<Image src={profile} alt="프로필" width={'125px'} height={'125px'} />
<button onClick={() => setProfile('')}></button>
</>
) : (
<>
<label htmlFor="profile"></label>
<input type="file" id="profile" name="file" onChange={uploadImage} />
</>
)}
</div>
</StyledImageUploader>
);
};
4 changes: 4 additions & 0 deletions components/common/profile/profile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface ProfileProps {
profile: string;
setProfile: Dispatch<SetStateAction<string>>;
}
33 changes: 33 additions & 0 deletions components/common/profile/styledProfile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import styled from '@emotion/styled';

export const StyledImageUploader = styled.div`
margin: 0 auto;
width: 125px;
.uploaded {
position: relative;
}
button {
position: absolute;
right: -10px;
top: -10px;
width: 25px;
height: 25px;
background: url('/assets/common/button-delete.svg') no-repeat;
cursor: pointer;
}
label {
display: inline-block;
cursor: pointer;
background: center url('/assets/common/profile.svg') no-repeat;
width: 125px;
height: 125px;
border-radius: 50%;
}
input[type='file'] {
display: none;
}
`;
83 changes: 52 additions & 31 deletions components/common/rating/index.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,74 @@
import styled from '@emotion/styled';
import Image from 'next/image';
import { useMemo } from 'react';

interface RatingGroupProps {
isEditingMode: boolean;
width: number;
height: number;
}
const RatingGroupContainer = styled.div`
display: inline-block;
&.edit {
display: flex;
flex-direction: row-reverse;
width: 50%;
margin: 0 auto;
}
input {
display: none;
}
label {
background: url('/assets/common/star.svg') no-repeat;
background: url('/assets/common/star-blank.svg') no-repeat;
background-size: 30px;
background-position: center;
width: 40px;
height: 40px;
display: inline-block;
cursor: pointer;
}
& :checked ~ label {
background: url('/assets/common/star.svg') no-repeat;
background-size: 30px;
background-position: center;
}
`;

const RatingGroup = ({ isEditingMode, width, height }: RatingGroupProps) => {
const RatingGroup = ({ isEditingMode, onChangeRating, star, width, height }: RatingGroupProps) => {
const StarFill = useMemo(
() =>
[1, 2, 3, 4, 5].map((v, index) => (
<Image
key={index}
src={star < v ? '/assets/common/star-blank.svg' : '/assets/common/star.svg'}
alt={v + ''}
width={width}
height={height}
/>
)),
[star]
);

const RatingGroup = useMemo(
() => (
<>
{' '}
<input type="radio" id="5-stars" name="rating" value="5" />
<label htmlFor="5-stars"></label>
<input type="radio" id="4-stars" name="rating" value="4" />
<label htmlFor="4-stars"></label>
<input type="radio" id="3-stars" name="rating" value="3" />
<label htmlFor="3-stars"></label>
<input type="radio" id="2-stars" name="rating" value="2" />
<label htmlFor="2-stars"></label>
<input type="radio" id="1-stars" name="rating" value="1" />
<label htmlFor="1-stars"></label>
</>
),
[]
);

return (
<RatingGroupContainer className="rating-container">
{isEditingMode ? (
<>
<input type="radio" id="5-stars" name="rating" value="5" />
<label htmlFor="5-stars"></label>
<input type="radio" id="4-stars" name="rating" value="4" />
<label htmlFor="4-stars"></label>
<input type="radio" id="3-stars" name="rating" value="3" />
<label htmlFor="3-stars"></label>
<input type="radio" id="2-stars" name="rating" value="2" />
<label htmlFor="2-stars"></label>
<input type="radio" id="1-stars" name="rating" value="1" />
<label htmlFor="1-stars"></label>
</>
) : (
<>
<Image src="/assets/common/star.svg" alt="1" width={width} height={height} />
<Image src="/assets/common/star.svg" alt="2" width={width} height={height} />
<Image src="/assets/common/star.svg" alt="3" width={width} height={height} />
<Image src="/assets/common/star.svg" alt="3" width={width} height={height} />
<Image src="/assets/common/star-blank.svg" alt="5" width={width} height={height} />
</>
)}
<RatingGroupContainer
className={isEditingMode ? 'edit' : 'none'}
onChange={(e) => onChangeRating(e)}
>
{isEditingMode ? <>{RatingGroup}</> : <>{StarFill}</>}
</RatingGroupContainer>
);
};
Expand Down
7 changes: 7 additions & 0 deletions components/common/rating/rating.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface RatingGroupProps {
isEditingMode: boolean;
onChangeRating?: ChangeEvent<HTMLInputElement>;
star?: number;
width: number;
height: number;
}
6 changes: 2 additions & 4 deletions components/common/uploader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ChangeEvent, useState } from 'react';
import { ChangeEvent } from 'react';
import { StyledImageUploader } from './styledUploader';

export const ImageUploader = () => {
const [url, setImageUrl] = useState<string[]>(['', '', '']);

export const ImageUploader = ({ url, setImageUrl }: ImageUploaderProps) => {
const uploadImage = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files === null) return;
const tempUrl = URL.createObjectURL(e.target.files[0]);
Expand Down
4 changes: 4 additions & 0 deletions components/common/uploader/uploader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface ImageUploaderProps {
url: string[];
setImageUrl: Dispatch<SetStateAction<string[]>>;
}
Loading

0 comments on commit a5672a3

Please sign in to comment.