From 3ddcdcbf2709cff3d6a43f040784679812aa8aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=8C=EC=9A=B8=EC=B9=98=ED=82=A8?= <90738604+soulchicken@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:01:28 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Feat:=20InApp=EC=9D=B8=20=EA=B2=BD=EC=9A=B0?= =?UTF-8?q?=EB=8A=94=20=EC=99=B8=EB=B6=80=20=EB=B8=8C=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=EC=A0=80=EA=B0=80=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/inApp/InApp.tsx | 60 +++++++++++++++++++++++++++ src/pages/index.tsx | 2 + 2 files changed, 62 insertions(+) create mode 100644 src/components/common/inApp/InApp.tsx diff --git a/src/components/common/inApp/InApp.tsx b/src/components/common/inApp/InApp.tsx new file mode 100644 index 0000000..4dd68b4 --- /dev/null +++ b/src/components/common/inApp/InApp.tsx @@ -0,0 +1,60 @@ +import color from '@/styles/color'; +import { css } from '@emotion/react'; + +type Theme = 'green' | 'white' + +const themeTable = { + green: { + backgroundColor: color.darkGreen, + color: color.offWhite, + }, + white: { + backgroundColor: color.offWhite, + color: color.greenGray, + }, +}; + +const InApp = () => { + const handleButtonClick = () => { + if (typeof window !== 'undefined') { + window.open(window.location.href, '_blank'); + } + }; + + // 인앱 브라우저인지 확인하는 함수 + const isInAppBrowser = () => { + if (typeof window !== 'undefined') { + const userAgent = window.navigator.userAgent.toLowerCase(); + if (userAgent.indexOf('kakao') >= 0) return true; + if (userAgent.indexOf('[fb') >= 0) return true; + if (userAgent.indexOf('instagram') >= 0) return true; + if (userAgent.indexOf('trill') >= 0) return true; + if (userAgent.indexOf('line') >= 0) return true; + } + return false; + }; + + // 인앱 브라우저가 아니라면 null을 반환하여 컴포넌트를 렌더링하지 않습니다. + if (!isInAppBrowser()) { + return null; + } + return ( + + ); +}; + +export default InApp; + +const ButtonCSS = (theme: Theme) => css` + width: 100%; + background-color: ${themeTable[theme].backgroundColor}; + border: none; + padding: 1rem; + border-radius: 1rem; + margin-top: 0.625rem; + font-size: 1rem; + font-weight: 400; + color: ${themeTable[theme].color}; +`; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 635c495..3c4d157 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -4,6 +4,7 @@ import Image from 'next/image'; import SEO from '@/components/common/head/SEO'; import Button from '@/components/common/button/Button'; import { useSession } from 'next-auth/react'; +import InApp from '@/components/common/inApp/InApp'; const Home = () => { console.log(); @@ -22,6 +23,7 @@ const Home = () => { /> From ae938443285babfe451597091ff811b98362fa26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=8C=EC=9A=B8=EC=B9=98=ED=82=A8?= <90738604+soulchicken@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:59:51 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Refactor:=20=EB=B0=B1=EC=97=94=EB=93=9C=20A?= =?UTF-8?q?PI=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/postDetail/CommentInput.tsx | 4 ++-- src/store/comment.ts | 8 ++++---- src/utils/api/accounts.ts | 4 ++-- src/utils/api/boards.ts | 17 +++++++++++------ src/utils/api/character.ts | 4 ++-- src/utils/axiosInstance/webServerInstance.ts | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/components/community/postDetail/CommentInput.tsx b/src/components/community/postDetail/CommentInput.tsx index 63f1878..dda599e 100644 --- a/src/components/community/postDetail/CommentInput.tsx +++ b/src/components/community/postDetail/CommentInput.tsx @@ -20,8 +20,8 @@ const CommentInput : FC = ({ characterId, postId }) => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); if (message && characterId && postId) { - createComment(characterId, postId, message).then(() => { - fetchComments(characterId, postId); + createComment(postId, message).then(() => { + fetchComments(postId); }); setMessage(''); } diff --git a/src/store/comment.ts b/src/store/comment.ts index a057b76..020f1f1 100644 --- a/src/store/comment.ts +++ b/src/store/comment.ts @@ -1,20 +1,20 @@ import { CommentData } from '@/types/post'; -import { findCommentsByPostAndCharacterId } from '@/utils/api/boards'; +import { readComment } from '@/utils/api/boards'; import { create } from 'zustand'; interface CommentState { comments: CommentData[], loading: boolean, - fetchComments: (characterId: string, postId: string) => void; + fetchComments: (postId: string) => void; } const useCommentStore = create((set) => ({ comments: [], loading: true, - fetchComments: async (characterId, postId) => { + fetchComments: async (postId) => { set({ loading: false }); try { - const response = await findCommentsByPostAndCharacterId(characterId, postId); + const response = await readComment(postId); console.log(response); set({ comments: response, loading: true }); } catch (error) { diff --git a/src/utils/api/accounts.ts b/src/utils/api/accounts.ts index 5bdab42..67e61b6 100644 --- a/src/utils/api/accounts.ts +++ b/src/utils/api/accounts.ts @@ -24,7 +24,7 @@ interface SocialLoginForm { } export const credentialsLoginAPI = async (credentials : Credentials) => { - const result = await ssrInstance.post('members/login', JSON.stringify(credentials)); + const result = await ssrInstance.post('members/login', credentials); return result.data; }; @@ -63,7 +63,7 @@ export const credentialsSignupAPI = async ({ }; export const refreshAccessToken = async (refreshToken: string) => { - const result = await ssrInstance.post('members/refreshToken', { refreshToken }); + const result = await ssrInstance.post('members/refreshtoken', { refreshToken }); return result.data; }; diff --git a/src/utils/api/boards.ts b/src/utils/api/boards.ts index 7e3db26..0b61335 100644 --- a/src/utils/api/boards.ts +++ b/src/utils/api/boards.ts @@ -16,18 +16,23 @@ export const createPost = async (characterId: string, title: string, content: st return result; }; -export const findCommentsByPostAndCharacterId = async (characterId: string, postId: string) => { - const result = await webServerInstance.get(`boards/${characterId}/${postId}/comments`); +export const readComment = async (postId: string) => { + const result = await webServerInstance.get(`comments/${postId}`); return result.data; }; -export const createComment = async (characterId: string, postId: string, comment: string) => { - const result = await webServerInstance.post(`boards/${characterId}/${postId}/comments`, { comment }); +export const createComment = async (postId: string, comment: string) => { + const result = await webServerInstance.post(`comments/${postId}`, { comment }); return result.data; }; -export const deleteComment = async (commentId: string) => { - const result = await webServerInstance.put(`comments/${commentId}`); +export const deleteComment = async (postId: string, commentId: string) => { + const result = await webServerInstance.delete(`comments/${postId}/${commentId}`); + return result.data; +}; + +export const updateComment = async (postId: string, commentId: string) => { + const result = await webServerInstance.put(`comments/${postId}/${commentId}`); return result.data; }; diff --git a/src/utils/api/character.ts b/src/utils/api/character.ts index b8ac9c2..839d1e8 100644 --- a/src/utils/api/character.ts +++ b/src/utils/api/character.ts @@ -13,11 +13,11 @@ export const findCharacterById = async (characterId: string) => { }; export const ssrFindAllCharacters = async () => { - const result = await ssrInstance.get('/api/characters'); + const result = await ssrInstance.get('/characters'); return result.data; }; export const ssrFindCharacterById = async (characterId: string) => { - const result = await ssrInstance.get(`/api/characters/${characterId}`); + const result = await ssrInstance.get(`/characters/${characterId}`); return result.data; }; diff --git a/src/utils/axiosInstance/webServerInstance.ts b/src/utils/axiosInstance/webServerInstance.ts index 5ec5fc9..18cd472 100644 --- a/src/utils/axiosInstance/webServerInstance.ts +++ b/src/utils/axiosInstance/webServerInstance.ts @@ -2,7 +2,7 @@ import axios, { AxiosError } from 'axios'; import { getSession } from 'next-auth/react'; const webServerInstance = axios.create({ - baseURL: `${process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:8080/'}api/`, + baseURL: `${process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:8080/'}/`, // headers: { 'Content-Type': 'application/json' }, }); From d97b915e47ddf2c962db5e28738aaa1d8293571c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=8C=EC=9A=B8=EC=B9=98=ED=82=A8?= <90738604+soulchicken@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:07:32 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Fix:=20=ED=95=A8=EC=88=98=20=EC=9D=B8?= =?UTF-8?q?=EC=9E=90=20=EB=B3=80=EA=B2=BD=20=EC=8B=A4=EC=88=98=20(?= =?UTF-8?q?=EB=B9=8C=EB=93=9C=EC=97=90=EC=84=9C=20=EB=B0=9C=EA=B2=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/community/postDetail/Comment.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/community/postDetail/Comment.tsx b/src/components/community/postDetail/Comment.tsx index 558625b..1509a0d 100644 --- a/src/components/community/postDetail/Comment.tsx +++ b/src/components/community/postDetail/Comment.tsx @@ -15,7 +15,7 @@ const CommentList: FC = ({ characterId, postId }) => { const { loading, comments, fetchComments } = useCommentStore(); useEffect(() => { if (characterId && postId) { - fetchComments(characterId, postId); + fetchComments(postId); } }, [characterId, postId, fetchComments]);