Skip to content

Open-source status page, incident response and uptime monitoring

Feat/small stuff and upload dimension (#705)

Maximilian Kaske61a5610ada7f
diff --git a/apps/web/src/app/(content)/_components/pagination.tsx b/apps/web/src/app/(content)/_components/pagination.tsx
index 38c55234e..c4d47a5fb 100644
--- a/apps/web/src/app/(content)/_components/pagination.tsx
+++ b/apps/web/src/app/(content)/_components/pagination.tsx
@@ -17,8 +17,8 @@ export function Pagination({
{/* {prev ? (
<div className="w-1/2 flex-1 text-left">
<Button asChild variant="link">
- <Link href={`/changelog/${prev.slug}`}>
- <ChevronLeft className="mr-2 h-4 w-4" />
+ <Link href={`/changelog/${prev.slug}`} className="group">
+ <ChevronLeft className="text-muted-foreground group-hover:text-foreground mr-2 h-4 w-4" />
<span className="truncate">{prev.title}</span>
</Link>
</Button>
@@ -29,9 +29,9 @@ export function Pagination({
{next ? (
<div className="w-1/2 flex-1 text-right">
<Button asChild variant="link">
- <Link href={`/changelog/${next.slug}`}>
+ <Link href={`/changelog/${next.slug}`} className="group">
<span className="truncate">{next.title}</span>
- <ChevronRight className="ml-2 h-4 w-4" />
+ <ChevronRight className="text-muted-foreground group-hover:text-foreground ml-2 h-4 w-4" />
</Link>
</Button>
</div>
diff --git a/apps/web/src/components/forms/status-page/section-advanced.tsx b/apps/web/src/components/forms/status-page/section-advanced.tsx
index db8f06233..20b7b33e3 100644
--- a/apps/web/src/components/forms/status-page/section-advanced.tsx
+++ b/apps/web/src/components/forms/status-page/section-advanced.tsx
@@ -8,6 +8,14 @@ import type { UseFormReturn } from "react-hook-form";
import type { InsertPage } from "@openstatus/db/src/schema";
import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
Button,
FormControl,
FormDescription,
@@ -26,19 +34,58 @@ interface Props {
export function SectionAdvanced({ form }: Props) {
const inputFileRef = useRef<HTMLInputElement>(null);
+ const [open, setOpen] = React.useState(false);
+ const [file, setFile] = React.useState<File | null>(null);
+
+ /**
+ * Determine the width and height of the uploaded image - it ideally is a square
+ */
+ const getFileDimensions = async (file: File) => {
+ const img = document.createElement("img");
+ img.src = URL.createObjectURL(file);
+ await img.decode();
+ return { width: img.naturalWidth, height: img.naturalHeight };
+ };
const handleChange = async (file: FileList | null) => {
if (!file || file.length === 0) {
return;
}
- const response = await fetch(`/api/upload?filename=${file[0].name}`, {
+ const { height, width } = await getFileDimensions(file[0]);
+
+ // remove rounding issues from transformations
+ if (!(Math.abs(height - width) <= 1)) {
+ setOpen(true);
+ setFile(file[0]);
+ return;
+ }
+
+ const newblob = await handleUpload(file[0]);
+ form.setValue("icon", newblob.url);
+ };
+
+ const handleUpload = async (file: File) => {
+ const response = await fetch(`/api/upload?filename=${file.name}`, {
method: "POST",
- body: file[0],
+ body: file,
});
const newblob = (await response.json()) as PutBlobResult;
- form.setValue("icon", newblob.url);
+ return newblob;
+ };
+
+ const handleCancel = () => {
+ inputFileRef.current?.value && (inputFileRef.current.value = "");
+ };
+
+ const handleConfirm = async () => {
+ if (file) {
+ const newblob = await handleUpload(file);
+ form.setValue("icon", newblob.url);
+ setFile(null);
+ }
+ setOpen(false);
};
return (
@@ -110,6 +157,23 @@ export function SectionAdvanced({ form }: Props) {
</FormItem>
)}
/>
+ <AlertDialog open={open} onOpenChange={(value) => setOpen(value)}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Incorrect image size</AlertDialogTitle>
+ <AlertDialogDescription>
+ For the best result, the image should be a square. You can still
+ upload it, but it will be cropped.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel onClick={handleCancel}>Cancel</AlertDialogCancel>
+ <AlertDialogAction onClick={handleConfirm}>
+ Continue
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</div>
);
}
diff --git a/apps/web/src/components/marketing/hero.tsx b/apps/web/src/components/marketing/hero.tsx
index d0d19aa52..9e4cce565 100644
--- a/apps/web/src/components/marketing/hero.tsx
+++ b/apps/web/src/components/marketing/hero.tsx
@@ -32,7 +32,7 @@ export function Hero() {
>
A better way to monitor your services.
</h1>
- <p className="text-muted-foreground mx-auto max-w-md text-lg md:max-w-lg md:text-xl">
+ <p className="text-muted-foreground mx-auto max-w-md text-lg md:max-w-xl md:text-xl">
Monitor your API and website from 6 continents, detect some
performance issues and receive notifications before your users are
affected.