Skip to content

Commit

Permalink
feat: update announcement
Browse files Browse the repository at this point in the history
feat: update announcement
Co-Authored-By: Minghan Zhang <[email protected]>
  • Loading branch information
Sh1n3zZ and zmh-program committed Mar 30, 2024
1 parent aaa1a8e commit 03512d0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 29 deletions.
54 changes: 27 additions & 27 deletions app/src/components/app/Announcement.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useTranslation } from "react-i18next";
import { useEffect, useState } from "react";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
DialogAction,
DialogCancel,
} from "@/components/ui/dialog";
import { AnnouncementEvent, announcementEvent } from "@/events/announcement.ts";
import { Bell, Check } from "lucide-react";
import Markdown from "@/components/Markdown.tsx";
Expand All @@ -32,37 +32,37 @@ function Announcement() {
}, []);

return (
<AlertDialog open={open} onOpenChange={setOpen}>
<AlertDialogTrigger asChild>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button
variant={`outline`}
size={`icon`}
className={cn(!announcement.length && `hidden`)}
>
<Bell className={`h-4 w-4`} />
</Button>
</AlertDialogTrigger>
<AlertDialogContent className={`announcement-dialog flex-dialog`}>
<AlertDialogHeader notTextCentered>
<AlertDialogTitle
</DialogTrigger>
<DialogContent className={`announcement-dialog flex-dialog`}>
<DialogHeader notTextCentered>
<DialogTitle
className={"flex flex-row items-center select-none"}
>
<Bell className="inline-block w-4 h-4 mr-2" />
<p className={`translate-y-[-1px]`}>{t("announcement")}</p>
</AlertDialogTitle>
<AlertDialogDescription>
</DialogTitle>
<DialogDescription>
<Markdown acceptHtml={true}>{announcement || t("empty")}</Markdown>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("close")}</AlertDialogCancel>
<AlertDialogAction>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogCancel onClick={() => setOpen(false)}>{t("close")}</DialogCancel>
<DialogAction onClick={() => setOpen(false)}>
<Check className="w-4 h-4 mr-1" />
{t("i-know")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</DialogAction>
</DialogFooter>
</DialogContent>
</Dialog>
);
}

Expand Down
33 changes: 31 additions & 2 deletions app/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as DialogPrimitive from "@radix-ui/react-dialog";
import { X } from "lucide-react";

import { cn } from "./lib/utils";
import { Button, ButtonProps } from "@/components/ui/button.tsx";

const Dialog = DialogPrimitive.Root;

Expand Down Expand Up @@ -61,11 +62,13 @@ DialogContent.displayName = DialogPrimitive.Content.displayName;

const DialogHeader = ({
className,
notTextCentered,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
}: React.HTMLAttributes<HTMLDivElement> & {notTextCentered?: boolean}) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
"flex flex-col space-y-1.5 sm:text-left",
!notTextCentered && "text-center",
className,
)}
{...props}
Expand Down Expand Up @@ -114,6 +117,30 @@ const DialogDescription = React.forwardRef<
));
DialogDescription.displayName = DialogPrimitive.Description.displayName;

const DialogCancel = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, ...props }, ref) => (
<Button
ref={ref}
variant={variant ?? "outline"}
{...props}
/>
)
);

DialogCancel.displayName = "DialogCancel";

const DialogAction = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, ...props }, ref) => (
<Button
ref={ref}
variant={variant ?? "default"}
{...props}
/>
)
);
DialogAction.displayName = "DialogAction";


export {
Dialog,
DialogTrigger,
Expand All @@ -122,4 +149,6 @@ export {
DialogFooter,
DialogTitle,
DialogDescription,
DialogCancel,
DialogAction,
};

0 comments on commit 03512d0

Please sign in to comment.