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

Feat#57 animation post #61

Open
wants to merge 9 commits into
base: feat#54-animationGet
Choose a base branch
from
20 changes: 20 additions & 0 deletions src/api/postCollectionAnimation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from 'axios';
import { postCollectionAnimationProps } from 'types/postCollectionAnimationTypes';

export async function postCollectionAnimation(props: postCollectionAnimationProps) {
const { userId, content } = props;
const response = await axios.post(
`${import.meta.env.VITE_APP_BASE_URL}/api/collection/1`,
{
userId: userId,
content: content,
},
{
headers: {
'Content-Type': 'application/json',
},
},
);

return response;
}
38 changes: 36 additions & 2 deletions src/components/animation/Comment/CommentInput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import { useState } from 'react';
import { flexCenter } from '@styles/globalStyle';
import styled from 'styled-components';
import { CollectDetailChatBottomIc } from '@assets/index';
import { useMutation, useQueryClient } from 'react-query';
import { postCollectionAnimation } from '@api/postCollectionAnimation';

export default function CommentInput() {
const [inputValue, setInputValue] = useState('');
const queryClient = useQueryClient();

const { mutate: postComment } = useMutation(postCollectionAnimation, {
onSuccess: () => {
queryClient.invalidateQueries('getAnimationCollection');
setInputValue('');
},
onSettled: () => {
console.log('loading..');
},
onError: (error) => {
console.log(error);
},
});

function handleClickPostButton() {
if (inputValue.trim() !== '') {
postComment({ userId: 1, content: inputValue });
}
}

function handleChangeComment(e: React.ChangeEvent<HTMLInputElement>) {
setInputValue(e.target.value);
}

return (
<Wrapper>
<CommentInputBox placeholder="์ปฌ๋ ‰์…˜์— ๋Œ“๊ธ€์„ ๋‚จ๊ฒจ๋ณด์„ธ์š”." type="text" />
<InputSubmitButton>
<CommentInputBox
onChange={handleChangeComment}
value={inputValue}
placeholder="์ปฌ๋ ‰์…˜์— ๋Œ“๊ธ€์„ ๋‚จ๊ฒจ๋ณด์„ธ์š”."
type="text"
/>
<InputSubmitButton onClick={handleClickPostButton}>
<CollectDetailChatBottomIcon />
๋“ฑ๋ก
</InputSubmitButton>
Expand Down
1 change: 1 addition & 0 deletions src/types/Dummy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ํด๋” ๊ตฌ์กฐ ์˜ฌ๋ฆฌ๊ธฐ ์œ„ํ•ด ์ƒ์„ฑํ•œ ํŒŒ์ผ - ๋‚˜์ค‘์— ์ง€์šธ ๊ฒƒ
4 changes: 4 additions & 0 deletions src/types/postCollectionAnimationTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface postCollectionAnimationProps {
userId: number;
content: string;
}