Skip to content

Commit

Permalink
Merge pull request #93 from teamViNO/feature-072
Browse files Browse the repository at this point in the history
  • Loading branch information
whistleJs authored Feb 17, 2024
2 parents bdeb651 + a1e0fbc commit e8160bc
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ import useUpdateCategories from '@/hooks/useUpdateCategories';

// Store
import { userTokenState } from '@/stores/user';
import { getTempToken } from './apis/videos';

const App = () => {
const userToken = useRecoilValue(userTokenState);
const { updateCategories } = useUpdateCategories();

useEffect(() => {
(async () => {
const response = await getTempToken();
document.cookie = `tempToken=${response.result.tempToken}`;
})();
userToken && updateCategories();
}, [updateCategories, userToken]);

return (
<ThemeProvider theme={theme}>
<GlobalStyle />
Expand Down
6 changes: 6 additions & 0 deletions src/apis/feedback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import axiosInstance from './config/instance';

export const postFeedback = async (text: string) => {
const response = await axiosInstance.post('/feedback', { text });
return response;
};
14 changes: 14 additions & 0 deletions src/apis/videos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIBaseResponse, APIResponse } from '@/models/config/axios';
import {
ITempTokenResponse,
IVideo,
UpdateVideoCategoryRequest,
UpdateVideoRequest,
Expand Down Expand Up @@ -91,3 +92,16 @@ export const createDummyVideoToMine = async (

return response.data;
};

export const getTempToken = async (): Promise<
APIResponse<ITempTokenResponse>
> => {
const response = await axiosInstance.get('/');
return response.data;
};

export const getVideoModeling = async (url: string) => {
const response = await axiosInstance.get(`/video/?v=${url}`);
console.log(response);
return response.data;
};
7 changes: 6 additions & 1 deletion src/components/Home/SearchYoutube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

import VideoIcon from '@/assets/icons/video.svg?react';
import WarningIcon from '@/assets/icons/warning.svg?react';
import { getVideoModeling } from '@/apis/videos';

interface SearchBarProps {
onSearch: (value: string) => void;
Expand All @@ -27,6 +28,10 @@ const SearchYoutube: React.FC<SearchBarProps> = ({ onSearch, searchRef }) => {

const setModalOpen = useSetRecoilState(recommendationModalState);

const onStartConvert = async () => {
await getVideoModeling(inputLink);
};

const handleSubmit = (event: FormEvent) => {
event.preventDefault();
if (isValidYoutubeLink(inputLink)) {
Expand Down Expand Up @@ -112,7 +117,7 @@ const SearchYoutube: React.FC<SearchBarProps> = ({ onSearch, searchRef }) => {
</div>
<SearchButton
type="submit"
// onClick={ handleClick }
onClick={onStartConvert}
style={{
color: isButtonValid ? 'white' : theme.color.gray300,
backgroundColor: isButtonValid
Expand Down
18 changes: 17 additions & 1 deletion src/components/layout/footer/SendEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import * as FooterStyle from '@/styles/layout/footer';
import { useState } from 'react';

import SendEmailImage from '@/assets/mail.png';
import { postFeedback } from '@/apis/feedback';

const SendEmail = () => {
const [feedback, setFeedback] = useState<string>('');

const handleInputFeedback = (e: React.ChangeEvent<HTMLInputElement>) =>
setFeedback(e.target.value);

const onSendFeedback = async () => {
const res = await postFeedback(feedback);
if (res.data.success) {
setFeedback('');
return;
}
alert('피드백을 전송하는 과정에서 오류가 발생했습니다.');
};

return (
<FooterStyle.SendEmailWrap>
<FooterStyle.SendEmailImage src={SendEmailImage} alt="메일 보내기" />
Expand All @@ -18,7 +28,13 @@ const SendEmail = () => {
value={feedback}
onChange={handleInputFeedback}
/>
<FooterStyle.SendEmailButton>보내기</FooterStyle.SendEmailButton>
<FooterStyle.SendEmailButton
onClick={onSendFeedback}
disabled={!feedback}
className={`${!feedback && 'disabled'}`}
>
보내기
</FooterStyle.SendEmailButton>
</FooterStyle.SendEmailWrap>
);
};
Expand Down
4 changes: 4 additions & 0 deletions src/models/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ export interface UpdateVideoRequest {
export interface UpdateVideoCategoryRequest {
video_id: (string | number)[];
}

export interface ITempTokenResponse {
tempToken: string;
}
8 changes: 8 additions & 0 deletions src/styles/layout/footer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export const SendEmailButton = styled.button`
color: ${theme.color.white};
border: 0;
cursor: pointer;
transition: all 0.2s;
&.disabled {
cursor: default;
background-color: ${theme.color.gray200};
color: ${theme.color.gray300};
border: 0;
}
`;

export const AboutViNOWrap = styled.div`
Expand Down
7 changes: 7 additions & 0 deletions src/utils/getTokenInCookie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getTokenInCookie = () =>
document.cookie
.split(';')
.find((cookie) => cookie.includes('tempToken'))
?.split('=')[1];

export default getTokenInCookie;

0 comments on commit e8160bc

Please sign in to comment.