Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@heroui/theme": "^2.4.6",
"@radix-ui/react-avatar": "^1.1.2",
"@radix-ui/react-checkbox": "^1.1.3",
"@radix-ui/react-dialog": "^1.1.5",
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-popover": "^1.1.4",
"@radix-ui/react-progress": "^1.1.1",
Expand Down
120 changes: 120 additions & 0 deletions src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"

const Dialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName

const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"

const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"

const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName

const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}
10 changes: 10 additions & 0 deletions src/content/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import FilterBadge from './components/FilterBadge';
import FilterPanel from './components/FilterPanel';
import { useCourseData } from '@/hooks/useCourseData';
import { filterVods, filterAssigns, filterQuizes } from '@/lib/filterData';
import PendingDialogWithBeforeUnload from './components/pending-dialog';

// 리팩토링: 필터 옵션 추출
const attendanceOptions = ['출석', '결석']; // string[]
Expand Down Expand Up @@ -149,6 +150,14 @@ export default function App() {
};

return (
<>
<PendingDialogWithBeforeUnload
isPending={isPending}
onClose={() => {
// 필요한 경우 강제 종료 처리
console.log("사용자가 다이얼로그를 닫았습니다")
}}
/>
<Popover open={isOpen}>
<PopoverTrigger asChild className="transition-all duration-1000 justify-self-end">
{isOpen ? (
Expand Down Expand Up @@ -318,5 +327,6 @@ export default function App() {
<PopoverFooter activeTab={activeTab} setActiveTab={setActiveTab} />
</PopoverContent>
</Popover>
</>
);
}
124 changes: 124 additions & 0 deletions src/content/components/pending-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Loader2 } from 'lucide-react';
import styles from '@/styles/shadow.css?inline';
import { createShadowRoot } from '@/lib/createShadowRoot';

interface PendingDialogProps {
isPending: boolean;
onClose?: () => void;
}

export default function PendingDialog({ isPending, onClose }: PendingDialogProps) {
const [open, setOpen] = useState(false);
const [cancelEnabled, setCancelEnabled] = useState(false);
const [modalContainer, setModalContainer] = useState<Element | DocumentFragment | null>(null);
const [hostElement, setHostElement] = useState<HTMLElement | null>(null);

useEffect(() => {
let host = document.getElementById('shadow-modal-host') as HTMLElement | null;
if (!host) {
host = document.createElement('div');
host.id = 'shadow-modal-host';
host.style.zIndex = '9999';
host.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
document.body.prepend(host);
}
setHostElement(host);
const newShadowRoot = createShadowRoot(host, [
styles,
`
:host {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
`,
]);
setModalContainer(newShadowRoot);
}, []);

// open 상태에 따라 host의 display 업데이트
useEffect(() => {
if (hostElement) {
hostElement.style.display = open ? 'flex' : 'none';
}
}, [open, hostElement]);

// isPending 상태에 따라 모달 열림/닫힘 관리
useEffect(() => {
if (isPending) {
setOpen(true);
setCancelEnabled(false);
} else {
setOpen(false);
setCancelEnabled(false);
}
}, [isPending]);

// 모달이 열리면 스크롤을 막고, 닫히면 복구
useEffect(() => {
if (open) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
}, [open]);

// 모달이 열릴 때 15초 후에 취소 버튼 활성화
useEffect(() => {
let timer: NodeJS.Timeout;
if (open) {
timer = setTimeout(() => {
setCancelEnabled(true);
}, 15000);
}
return () => {
clearTimeout(timer);
};
}, [open]);

const handleClose = () => {
// 취소 버튼이 활성화된 경우에만 닫힘 동작 실행
if (cancelEnabled) {
setOpen(false);
if (onClose) {
onClose();
}
}
};

const modalContent = (
<Card className="w-3/4 max-w-4xl">
<CardHeader className="m-4">
<CardTitle className="text-4xl font-bold">요청 진행 중</CardTitle>
<p className="my-6 text-xl text-zinc-500 font-medium">요청이 진행중입니다. 잠시만 기다려주세요.</p>
</CardHeader>
<CardContent className="m-4">
<div className="flex flex-col items-center justify-center py-6 space-y-8">
<Loader2 className="h-10 w-10 animate-spin text-primary" />
<p className="my-6 text-xl text-zinc-900 font-medium">완료되면 자동으로 창이 닫힙니다.</p>
</div>
<Button
variant={'destructive'}
onClick={handleClose}
className="w-full h-16 rounded-lg"
disabled={!cancelEnabled}
>
<span className="text-xl text-white font-semibold">취소</span>
</Button>
</CardContent>
</Card>
);

if (!modalContainer) return null;
return ReactDOM.createPortal(modalContent, modalContainer);
}
11 changes: 11 additions & 0 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,14 @@ h1 {
@apply bg-background text-foreground;
}
}



@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
9 changes: 9 additions & 0 deletions src/styles/shadow.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,12 @@
overscroll-behavior: none;
}
}

@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
Loading