-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from JongMany/feat/refactor-architecture
[Refactor] FSD 아키텍처 미숙한 부분 수정
- Loading branch information
Showing
38 changed files
with
356 additions
and
211 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default } from "./ui/Project"; | ||
export { default } from "./ui/project/Project"; | ||
export { default as FileDownloadButton } from "./ui/download-button/FileDownloadButton"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
fe/src/entities/projects/ui/download-button/FileDownloadButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useDownloadFile } from "@/entities/projects/libs/useDownloadFile"; | ||
|
||
type Props = { | ||
fileUrl: string; | ||
}; | ||
|
||
export default function FileDownload({ fileUrl }: Props) { | ||
// const [isDownloading, setIsDownloading] = useState(false); | ||
// const handleFileDownload = () => { | ||
// if (!isDownloading) { | ||
// setIsDownloading(true); | ||
// fetch(fileUrl) | ||
// .then((response) => response.blob()) | ||
// .then((blob) => { | ||
// const url = window.URL.createObjectURL(new Blob([blob])); | ||
// const linkElem = document.createElement("a"); | ||
// linkElem.href = url; | ||
// linkElem.download = fileUrl.split("/").pop() || "download"; | ||
// document.body.appendChild(linkElem); | ||
// linkElem.click(); | ||
|
||
// window.URL.revokeObjectURL(url); | ||
// setIsDownloading(false); | ||
// }) | ||
// .catch((error) => { | ||
// console.error(`File download failed: ${error}`); | ||
// setIsDownloading(false); | ||
// }); | ||
// } | ||
// }; | ||
const { isDownloading, handleFileDownload } = useDownloadFile(fileUrl); | ||
|
||
return ( | ||
<button | ||
onClick={handleFileDownload} | ||
disabled={isDownloading} | ||
className="font-semibold text-white px-2 py-1 rounded-md border-[1px] mt-4" | ||
> | ||
<span>{isDownloading ? "다운로드 중" : "다운로드하기"}</span> | ||
{/* <form action={fileUrl} method="get" target="_blank"> | ||
<button type="submit">Download</button> | ||
</form> */} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
fe/src/shared/constants/animationScript.ts → ...ed/constants/animation/animationScript.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
80 changes: 80 additions & 0 deletions
80
fe/src/shared/libs/media-query/__tests__/useMediaQuery.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { renderHook, act } from "@testing-library/react"; | ||
import { useMediaQuery } from "@/shared/libs/media-query/useMediaQuery"; | ||
|
||
describe("useMediaQuery", () => { | ||
const originalMatchMedia = window.matchMedia; | ||
|
||
afterEach(() => { | ||
// Restore original window.matchMedia after each test | ||
window.matchMedia = originalMatchMedia; | ||
}); | ||
|
||
const createMockMatchMedia = (matches: boolean) => { | ||
const addListener = vi.fn(); | ||
const removeListener = vi.fn(); | ||
const addEventListener = vi.fn(); | ||
const removeEventListener = vi.fn(); | ||
|
||
return vi.fn().mockImplementation((query: string) => ({ | ||
matches, | ||
media: query, | ||
onchange: null, | ||
addListener, | ||
removeListener, | ||
addEventListener, | ||
removeEventListener, | ||
dispatchEvent: vi.fn(), | ||
})) as unknown as (query: string) => MediaQueryList; | ||
}; | ||
|
||
it("should return true for desktop query", () => { | ||
window.matchMedia = createMockMatchMedia(true); | ||
|
||
const { result } = renderHook(() => useMediaQuery("(min-width: 1024px)")); | ||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it("should return false for mobile query", () => { | ||
window.matchMedia = createMockMatchMedia(false); | ||
|
||
const { result } = renderHook(() => useMediaQuery("(max-width: 767px)")); | ||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it("should update when media query changes", () => { | ||
const matchMediaListeners: { [key: string]: () => void } = {}; | ||
window.matchMedia = vi.fn().mockImplementation((query: string) => { | ||
// const listeners: Array<() => void> = []; | ||
return { | ||
matches: query === "(min-width: 1024px)", | ||
media: query, | ||
onchange: null, | ||
addListener: (listener: () => void) => { | ||
matchMediaListeners[query] = listener; | ||
}, | ||
removeListener: vi.fn(), | ||
addEventListener: (event: string, listener: () => void) => { | ||
matchMediaListeners[query] = listener; | ||
}, | ||
removeEventListener: vi.fn(), | ||
dispatchEvent: vi.fn(), | ||
}; | ||
}) as unknown as (query: string) => MediaQueryList; | ||
|
||
const { result, rerender } = renderHook(() => | ||
useMediaQuery("(min-width: 1024px)") | ||
); | ||
|
||
expect(result.current).toBe(true); | ||
|
||
act(() => { | ||
window.matchMedia = createMockMatchMedia(false); | ||
if (matchMediaListeners["(min-width: 1024px)"]) { | ||
matchMediaListeners["(min-width: 1024px)"](); | ||
} | ||
}); | ||
|
||
rerender(); | ||
expect(result.current).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useMediaQuery } from "@/shared/libs/media-query/useMediaQuery"; | ||
|
||
export function useDeviceSize() { | ||
const isDesktopQuery = "(min-width: 1024px)"; | ||
const isTabletQuery = "(min-width: 768px) and (max-width: 1023px)"; | ||
const isMobileQuery = "(max-width: 767px)"; | ||
|
||
const isDesktop = useMediaQuery(isDesktopQuery); | ||
const isTablet = useMediaQuery(isTabletQuery); | ||
const isMobile = useMediaQuery(isMobileQuery); | ||
|
||
if (isDesktop) { | ||
return "desktop"; | ||
} | ||
|
||
if (isTablet) { | ||
return "tablet"; | ||
} | ||
|
||
if (isMobile) { | ||
return "mobile"; | ||
} | ||
|
||
return "mobile"; | ||
} |
Oops, something went wrong.