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

hotfix(update): 기존 잔버그 수정 및 봉합수술.. #78

Merged
merged 1 commit into from
Mar 17, 2024
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
12 changes: 7 additions & 5 deletions app/(docs)/docs/[title]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Container from "@/components/Container";
import React from "react";
import { HydrationBoundary } from "@tanstack/react-query";
import { HydrationBoundary, dehydrate } from "@tanstack/react-query";
import { useDocsByTitleQuery } from "@/services/docs/docs.query";
import getQueryClient from "@/app/getQueryClient";
import Docs from "./Docs";

interface PageProps {
Expand All @@ -11,14 +12,15 @@ interface PageProps {
}

const Page = async ({ params: { title } }: PageProps) => {
const queryClient = getQueryClient();
const docs = await useDocsByTitleQuery({ title });

return (
<Container {...docs}>
<HydrationBoundary>
<HydrationBoundary state={dehydrate(queryClient)}>
<Container {...docs}>
<Docs docs={docs} />
</HydrationBoundary>
</Container>
</Container>
</HydrationBoundary>
);
};

Expand Down
1 change: 1 addition & 0 deletions app/(docs)/docs/[title]/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const container = style({

export const body = style({
width: "100%",
whiteSpace: "pre-wrap",
});

export const contributorsBox = style({
Expand Down
4 changes: 2 additions & 2 deletions app/edit/[title]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ interface PageProps {
}

const Page = async ({ params: { title } }: PageProps) => {
const doc = await useDocsByTitleQuery({ title });
const docs = await useDocsByTitleQuery({ title });
return (
<div>
<Editor contents={doc.contents} title={doc.title} mode="EDIT" />
<Editor {...docs} mode="EDIT" />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function RootLayout({
<body>
<Providers>
<ToastContainer
autoClose={5000}
autoClose={3000}
hideProgressBar
closeOnClick
pauseOnHover
Expand Down
5 changes: 3 additions & 2 deletions components/Accordion/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { style } from "@vanilla-extract/css";

export const container = style({
width: "100%",
padding: "20px 0",
});

export const title = style({
textAlign: "center",
lineHeight: "45px",
});

export const details = style({});
export const details = style({
paddingBottom: "50px",
});

export const summary = style({
width: "100%",
Expand Down
2 changes: 1 addition & 1 deletion components/Container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import useUser from "@/hooks/useUser";
import { dateText } from "@/utils";
import { useDeleteDocsMutation } from "@/services/docs/docs.mutation";
import { useRouter } from "next/navigation";
import * as styles from "./style.css";
import { toast } from "react-toastify";
import * as styles from "./style.css";
import Toastify from "../Toastify";

interface ContainerProps extends PropsWithChildren {
Expand Down
37 changes: 21 additions & 16 deletions components/Editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { useCallback, useEffect, useState } from "react";
import React, { useCallback, useState } from "react";
import { decodeContent, getYear } from "@/utils";
import { ArrowIcon } from "@/assets";
import { useDocs } from "@/hooks/useDocs";
Expand All @@ -10,13 +10,15 @@ import {
useUpdateDocsMutation,
} from "@/services/docs/docs.mutation";
import { useRouter } from "next/navigation";
import * as styles from "./style.css";
import DragDropUpload from "../DragDropUpload";
import { EditorPropsType } from "@/types/editorPropType.interface";
import { toast } from "react-toastify";
import Toastify from "../Toastify";
import { EditorPropsType } from "@/types/editorPropType.interface";
import useModal from "@/hooks/useModal";
import { useQueryClient } from "@tanstack/react-query";
import getQueryClient from "@/app/getQueryClient";
import * as styles from "./style.css";
import DragDropUpload from "../DragDropUpload";
import Confirm from "../(modal)/Confirm";
import Toastify from "../Toastify";

const wikiExampleList = [
[
Expand Down Expand Up @@ -46,20 +48,21 @@ const wikiExampleList = [
],
];

const Editor = ({ contents = "", title = "", mode }: EditorPropsType) => {
const Editor = ({ contents = "", title = "", docsType = "", mode }: EditorPropsType) => {
const [isExampleOpen, setIsExampleOpen] = useState(false);
const { autoClosingTag, getDocsTypeByClassify, translateClassify } = useDocs();
const { mutateAsync: create } = useCreateDocsMutation();
const { mutateAsync: upload } = useUploadImageMutation();
const { mutateAsync: update } = useUpdateDocsMutation();
const router = useRouter();
const [cursorPosition, setCursorPosition] = useState(0);
const queryClient = useQueryClient(getQueryClient());
const { openModal } = useModal();
const [docs, setDocs] = useState({
enroll: 0,
title,
contents,
docsType: "",
docsType,
});

const handleOpenComfirm = () => {
Expand All @@ -83,10 +86,9 @@ const Editor = ({ contents = "", title = "", mode }: EditorPropsType) => {
if (!file) return;
const { url } = await upload(file);
setDocs((prev) => {
const { contents } = prev;
const first = contents.substring(0, cursorPosition);
const first = prev.contents.substring(0, cursorPosition);
const middle = `<사진 {200px}>${url}</사진>`;
const last = contents.substring(cursorPosition, contents.length);
const last = prev.contents.substring(cursorPosition, prev.contents.length);
return {
...prev,
contents: `${first}${middle}${last}`,
Expand Down Expand Up @@ -116,6 +118,7 @@ const Editor = ({ contents = "", title = "", mode }: EditorPropsType) => {
};

const handleEditDocsClick = async () => {
if (!docs.contents.trim()) return toast(<Toastify content="내용이 없습니다!" />);
if (contents === docs.contents.trim())
return toast(<Toastify content="변경된 사항이 없습니다!" />);
try {
Expand All @@ -124,7 +127,9 @@ const Editor = ({ contents = "", title = "", mode }: EditorPropsType) => {
contents: docs.contents,
});
toast(<Toastify content="문서가 수정되었습니다!" />);
router.push(`/docs/${docs.title}`);
// await queryClient.refetchQueries();
// router.push(`/docs/${docs.title}`);
window.location.href = `/docs/${docs.title}`;
} catch (err) {
console.log(err);
}
Expand Down Expand Up @@ -186,13 +191,13 @@ const Editor = ({ contents = "", title = "", mode }: EditorPropsType) => {
"전공동아리",
"사설동아리",
"틀",
].map((docsType) => (
].map((type) => (
<button
onClick={() => setDocs((prev) => ({ ...prev, docsType }))}
key={docsType}
className={styles.docsType[String(docsType === docs.docsType)]}
onClick={() => setDocs((prev) => ({ ...prev, docsType: type }))}
key={type}
className={styles.docsType[String(type === docs.docsType)]}
>
{docsType}
{type}
</button>
))}
</div>
Expand Down
4 changes: 4 additions & 0 deletions components/Editor/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const titleInput = style({
"::placeholder": {
color: theme.boldgray,
},

":disabled": {
backgroundColor: "transparent",
},
});

export const previewBox = style({
Expand Down
2 changes: 1 addition & 1 deletion components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { useRouter } from "next/navigation";
import { Storage } from "@/storage";
import { TOKEN } from "@/constants/token.constant";
import * as styles from "./style.css";
import { toast } from "react-toastify";
import * as styles from "./style.css";
import Toastify from "../Toastify";

const navigationList = [
Expand Down
2 changes: 1 addition & 1 deletion components/Toastify/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as styles from "./style.css";
import Image from "next/image";
import * as styles from "./style.css";

const Tostify = ({ content }: { content: string }) => {
return (
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"prettier": "^3.2.5",
"react": "^18",
"react-dom": "^18",
"react-spinners": "^0.13.8"
"react-spinners": "^0.13.8",
"react-toastify": "^10.0.5"
},
"devDependencies": {
"@stylexjs/babel-plugin": "^0.5.1",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions services/docs/docs.key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const DOCS = {
LIST: (classify: string) => ["docsList", classify],
TITLE: (title: string) => ["docsByTitle", title],
KEYWORD: (keyword: string) => ["docsList", keyword],
LIST: (classify: string) => ["docsList", { classify }],
TITLE: (title: string) => ["docsByTitle", { title }],
KEYWORD: (keyword: string) => ["docsList", { keyword }],
LASTMODIFY: ["docsListModified"],
};
4 changes: 2 additions & 2 deletions services/docs/docs.mutation.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useMutation } from "@tanstack/react-query";
import { toast } from "react-toastify";
import Toastify from "@/components/Toastify";
import {
requestCreateDocs,
requestDeleteDocs,
requestUpdateDocs,
requestUploadImage,
} from "./docs.api";
import { toast } from "react-toastify";
import Toastify from "@/components/Toastify";

export const useCreateDocsMutation = () => {
return useMutation({
Expand Down
1 change: 1 addition & 0 deletions types/editorPropType.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface EditorPropsType {
contents?: string;
title?: string;
docsType?: string;
mode: "EDIT" | "CREATE";
}