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

🚑 프론트 핫픽스 #141

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions src/app/_components/answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ export default function Answer({ value, idState, ref }: askProps) {

useEffect(() => {
fetchProfile(value).then((r) => setUserInfo(r));
setShowNsfw(!value.nsfwedAnswer);
}, [value]);

return (
<div className="w-full glass rounded-box px-2 desktop:px-8 py-4 mb-2 shadow">
{!showNsfw && (
{!showNsfw && value.nsfwedAnswer && (
<div className="fixed top-0 left-0 z-10 gap-2 w-full h-full flex flex-col justify-center items-center">
<span>답변자가 NSFW로 체크한 질문이에요!</span>
<button className="btn" onClick={() => setShowNsfw(!showNsfw)}>
Expand All @@ -55,7 +54,7 @@ export default function Answer({ value, idState, ref }: askProps) {
</div>
)}

<div className={`${!showNsfw && 'blur'} w-full h-full`}>
<div className={`${!showNsfw && value.nsfwedAnswer && 'blur'} w-full h-full`}>
<div className="chat chat-start flex ml-2 desktop:ml-0 justify-between">
<div className="w-full">
<div className="chat-header dark:text-white">
Expand Down
13 changes: 9 additions & 4 deletions src/app/main/user/[handle]/[answer]/answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import Answer from '@/app/_components/answer';
import { useParams } from 'next/navigation';
import { useRef } from 'react';
import { AnswerDto } from '@/app/_dto/answers/Answers.dto';
import { useEffect, useRef, useState } from 'react';
import { AnswerWithProfileDto } from '@/app/_dto/answers/Answers.dto';
import DialogModalTwoButton from '@/app/_components/modalTwoButton';
import { onApiError } from '@/utils/api-error/onApiError';

export default function SingleAnswer({ answerBody }: { answerBody: AnswerDto }) {
export default function SingleAnswer({ answerBody }: { answerBody: AnswerWithProfileDto }) {
const [answerBodyState, setAnswerBodyState] = useState<AnswerWithProfileDto | undefined>();
const singleQuestionDeleteModalRef = useRef<HTMLDialogElement>(null);
const { userHandle } = useParams() as { userHandle: string };

Expand All @@ -22,9 +23,13 @@ export default function SingleAnswer({ answerBody }: { answerBody: AnswerDto })
}
};

useEffect(() => {
setAnswerBodyState(answerBody);
}, [answerBody]);

return (
<div className="flex w-[90%] window:w-[80%] desktop:w-[70%]">
{answerBody !== undefined ? (
{answerBodyState ? (
<>
<Answer value={answerBody} id={answerBody.id} ref={singleQuestionDeleteModalRef} />
<DialogModalTwoButton
Expand Down
8 changes: 4 additions & 4 deletions src/app/main/user/[handle]/[answer]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ export async function generateMetadata({
return {
title: answerBody.question,
openGraph: {
title: answerBody.question,
description: answerBody.answer,
title: `Q. ${answerBody.question}`,
description: `A. ${answerBody.answer}`,
images: answerBody.answeredPerson?.avatarUrl,
},
};
}

async function fetchAnswer(userHandle: string, id: string) {
async function fetchAnswer(userHandle: string, id: string): Promise<AnswerWithProfileDto | undefined> {
const url = process.env.WEB_URL;
const res = await fetch(`${url}/api/db/answers/${userHandle}/${id}`, {
method: 'GET',
});
if (res.status === 404) {
return null;
return undefined;
} else if (!res.ok) {
throw new Error(`Fail to fetch answer! ${await res.text()}`);
}
Expand Down
Loading