Skip to content

Commit

Permalink
Merge pull request #116 from DSM-Repo/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
six-standard authored Oct 28, 2024
2 parents bc9ce9b + 3b09d58 commit 84c5129
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion configs/util-config/src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const errFunc = (err: any) => {
toast.error(
`오류가 발생했습니다 (${response.status}: ${response.data.description || response.data})`
);
throw new Error(err);
throw err;
}
};

Expand Down
2 changes: 1 addition & 1 deletion configs/util-config/src/components/Common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "@configs/tailwindcss";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 3,
retry: false,
staleTime: 1000 * 60 * 2,
refetchOnWindowFocus: false
}
Expand Down
9 changes: 7 additions & 2 deletions configs/util-config/src/hooks/useMyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// @ts-expect-error
import { UseQueryResult, useQuery, keepPreviousData } from "@tanstack/react-query";
import { instance, path, pathType } from "../apis";
import { AxiosError } from "axios";

export const useMyQuery = <T>(
pathname: pathType,
Expand All @@ -11,8 +12,12 @@ export const useMyQuery = <T>(
return useQuery<T>({
queryKey: [path[pathname], url],
queryFn: async (): Promise<T> => {
const res = await instance.get(path[pathname] + url);
return res.data;
try {
const res = await instance.get(path[pathname] + url);
return res.data;
} catch (e) {
throw e;
}
},
placeholderData: keepPreviousData || placeholder
});
Expand Down
14 changes: 11 additions & 3 deletions packages/main/src/Pages/PublicViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import { Viewer } from "ui";

export const PublicViewer = () => {
const { id } = useParams();
const { data: detailData } = useMyQuery<Api.Library.LibraryDetail>(
const { data: detailData, isError } = useMyQuery<Api.Library.LibraryDetail>(
"library",
`/${id}/public`,
Placeholder.LibraryDetailPlace
);

return (
<div className="w-full h-screen bg-black">
<Viewer url={detailData?.resume_url} indexList={detailData?.index} />
<div className="w-full h-screen bg-black flex flex-center">
{isError ? (
<span>존재하지 않거나 접근 권한이 없는 레주메북입니다</span>
) : (
<Viewer
url={detailData?.resume_url}
indexList={detailData?.index}
disableDownload
/>
)}
</div>
);
};
2 changes: 1 addition & 1 deletion packages/main/src/Pages/ResumePublicViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ResumePublicViewer = () => {

return (
<div className="w-full h-screen bg-black">
<JSONViewer data={detailData} />
<JSONViewer data={detailData} disableDownload />
</div>
);
};
2 changes: 1 addition & 1 deletion packages/teacher/src/page/Render/Cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const Cover = ({ grade }: IProp) => {
Resume
</span>
<span className="text-gray-300 font-light text-[25px] leading-none">
Daedeok Software Mester High School
Daedeok Software Meister High School
</span>
</div>
<div
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/src/components/PDFs/JSONViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import { saveAs } from "file-saver";

interface IProp extends IHeader {
data?: Document.Resume;
disableDownload?: boolean;
}

export const JSONViewer = ({ data, buttons = [], sidebars = [] }: IProp) => {
export const JSONViewer = ({
data,
buttons = [],
sidebars = [],
disableDownload
}: IProp) => {
const [scale, setScale] = useState(0);
const [page, setPage] = useState(1);
const [max, setMax] = useState({
Expand Down Expand Up @@ -86,6 +92,8 @@ export const JSONViewer = ({ data, buttons = [], sidebars = [] }: IProp) => {
{
icon: "Download",
title: "다운로드",
disabled: disableDownload,
disabledReason: "다운로드가 비활성화된 상태입니다.",
action: () => {
let id = toast.loading("변환하고 있습니다...");
const data = document.querySelector(".resume");
Expand Down
8 changes: 6 additions & 2 deletions packages/ui/src/components/PDFs/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ interface IProp {
indexList?: Api.Library.indexData[];
buttons?: buttonType[];
sidebars?: sidebarType[];
disableDownload?: boolean;
}

export const Viewer = ({
url,
indexList,
buttons = [],
sidebars = []
sidebars = [],
disableDownload
}: IProp) => {
const [index, setIndex] = useState<Api.Library.indexData[][]>([]);
const [loading, setLoading] = useState(true);
Expand Down Expand Up @@ -84,7 +86,9 @@ export const Viewer = ({
{
icon: "Download",
title: "다운로드",
action: () => url && saveAs(url, `Resume.pdf`)
action: () => url && saveAs(url, `Resume.pdf`),
disabled: disableDownload,
disabledReason: "다운로드가 비활성화된 상태입니다."
},
indexList
? {
Expand Down

0 comments on commit 84c5129

Please sign in to comment.