small refactor
This commit is contained in:
parent
276a63a4dc
commit
84490a1c70
|
@ -1,4 +1,4 @@
|
||||||
import React from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { Button } from "@/app/_components/ui/button";
|
import { Button } from "@/app/_components/ui/button";
|
||||||
import { Card, CardContent } from "@/app/_components/ui/card";
|
import { Card, CardContent } from "@/app/_components/ui/card";
|
||||||
import { ScrollArea } from "@/app/_components/ui/scroll-area";
|
import { ScrollArea } from "@/app/_components/ui/scroll-area";
|
||||||
|
@ -33,9 +33,42 @@ const importOptions: ImportOption[] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const ImportData = () => {
|
const ImportData = () => {
|
||||||
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [isScrollable, setIsScrollable] = useState(false);
|
||||||
|
const scrollAreaHeight = "calc(100vh-140px)";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkScrollable = () => {
|
||||||
|
if (contentRef.current) {
|
||||||
|
const contentHeight = contentRef.current.scrollHeight;
|
||||||
|
const containerHeight = parseInt(
|
||||||
|
scrollAreaHeight.replace("calc(100vh-", "").replace("px)", "")
|
||||||
|
);
|
||||||
|
const viewportHeight = window.innerHeight - containerHeight;
|
||||||
|
|
||||||
|
setIsScrollable(contentHeight > viewportHeight);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check initially
|
||||||
|
checkScrollable();
|
||||||
|
|
||||||
|
// Check on window resize
|
||||||
|
window.addEventListener("resize", checkScrollable);
|
||||||
|
|
||||||
|
// Clean up event listener
|
||||||
|
return () => window.removeEventListener("resize", checkScrollable);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollArea className="h-[calc(100vh-140px)] w-full">
|
<ScrollArea
|
||||||
<div className="min-h-screen p-8 max-w-4xl mx-auto space-y-8">
|
className={`h-[${scrollAreaHeight}] w-full`}
|
||||||
|
scrollable={isScrollable}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
ref={contentRef}
|
||||||
|
className="min-h-screen p-8 max-w-4xl mx-auto space-y-8"
|
||||||
|
>
|
||||||
<div className="space-y-4 mb-4">
|
<div className="space-y-4 mb-4">
|
||||||
<h1 className="font-medium">Import data</h1>
|
<h1 className="font-medium">Import data</h1>
|
||||||
<Separator />
|
<Separator />
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { Switch } from "@/app/_components/ui/switch";
|
import { Switch } from "@/app/_components/ui/switch";
|
||||||
import { Separator } from "@/app/_components/ui/separator";
|
import { Separator } from "@/app/_components/ui/separator";
|
||||||
import { ScrollArea } from "@/app/_components/ui/scroll-area";
|
import { ScrollArea } from "@/app/_components/ui/scroll-area";
|
||||||
|
@ -14,10 +14,33 @@ import {
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export default function NotificationsSetting() {
|
export default function NotificationsSetting() {
|
||||||
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [lastToastTime, setLastToastTime] = useState(0);
|
const [lastToastTime, setLastToastTime] = useState(0);
|
||||||
const [notificationPreferences, setNotificationPreferences] =
|
const [notificationPreferences, setNotificationPreferences] =
|
||||||
useState<NotificationPreferences | null>(null);
|
useState<NotificationPreferences | null>(null);
|
||||||
|
const [isScrollable, setIsScrollable] = useState(false);
|
||||||
|
const scrollAreaHeight = "calc(100vh - 140px)";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkScrollable = () => {
|
||||||
|
if (contentRef.current) {
|
||||||
|
const contentHeight = contentRef.current.scrollHeight;
|
||||||
|
const viewportHeight = window.innerHeight - 140;
|
||||||
|
|
||||||
|
setIsScrollable(contentHeight > viewportHeight);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check initially
|
||||||
|
checkScrollable();
|
||||||
|
|
||||||
|
// Check on window resize
|
||||||
|
window.addEventListener("resize", checkScrollable);
|
||||||
|
|
||||||
|
// Clean up event listener
|
||||||
|
return () => window.removeEventListener("resize", checkScrollable);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Show toast with debounce to prevent too many notifications
|
// Show toast with debounce to prevent too many notifications
|
||||||
const showSavedToast = () => {
|
const showSavedToast = () => {
|
||||||
|
@ -70,8 +93,14 @@ export default function NotificationsSetting() {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollArea className="h-[calc(100vh-140px)] w-full">
|
<ScrollArea
|
||||||
<div className="min-h-screen p-8 max-w-4xl mx-auto space-y-14">
|
className="h-[calc(100vh-140px)] w-full"
|
||||||
|
scrollable={isScrollable}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
ref={contentRef}
|
||||||
|
className="min-h-screen p-8 max-w-4xl mx-auto space-y-14"
|
||||||
|
>
|
||||||
<div>
|
<div>
|
||||||
<div className="space-y-4 mb-4">
|
<div className="space-y-4 mb-4">
|
||||||
<h1 className="font-medium">Notifications</h1>
|
<h1 className="font-medium">Notifications</h1>
|
||||||
|
|
|
@ -15,6 +15,8 @@ import {
|
||||||
AvatarImage,
|
AvatarImage,
|
||||||
} from "@/app/_components/ui/avatar";
|
} from "@/app/_components/ui/avatar";
|
||||||
import {
|
import {
|
||||||
|
IconAdjustmentsHorizontal,
|
||||||
|
IconBaselineDensityLarge,
|
||||||
IconBell,
|
IconBell,
|
||||||
IconFileExport,
|
IconFileExport,
|
||||||
IconFileImport,
|
IconFileImport,
|
||||||
|
@ -82,7 +84,7 @@ export function SettingsDialog({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "preferences",
|
id: "preferences",
|
||||||
icon: IconSettings,
|
icon: IconAdjustmentsHorizontal,
|
||||||
title: "Preferences",
|
title: "Preferences",
|
||||||
content: <PreferencesSettings />,
|
content: <PreferencesSettings />,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const ScrollArea = React.forwardRef<
|
const ScrollArea = React.forwardRef<
|
||||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> & {
|
||||||
>(({ className, children, ...props }, ref) => (
|
scrollable?: boolean;
|
||||||
|
}
|
||||||
|
>(({ className, children, scrollable = true, ...props }, ref) => (
|
||||||
<ScrollAreaPrimitive.Root
|
<ScrollAreaPrimitive.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("relative overflow-hidden", className)}
|
className={cn("relative overflow-hidden", className)}
|
||||||
|
@ -17,11 +19,11 @@ const ScrollArea = React.forwardRef<
|
||||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||||
{children}
|
{children}
|
||||||
</ScrollAreaPrimitive.Viewport>
|
</ScrollAreaPrimitive.Viewport>
|
||||||
<ScrollBar />
|
{scrollable && <ScrollBar />}
|
||||||
<ScrollAreaPrimitive.Corner />
|
{scrollable && <ScrollAreaPrimitive.Corner />}
|
||||||
</ScrollAreaPrimitive.Root>
|
</ScrollAreaPrimitive.Root>
|
||||||
))
|
));
|
||||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
|
||||||
|
|
||||||
const ScrollBar = React.forwardRef<
|
const ScrollBar = React.forwardRef<
|
||||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||||
|
@ -42,7 +44,7 @@ const ScrollBar = React.forwardRef<
|
||||||
>
|
>
|
||||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||||
))
|
));
|
||||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
|
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
|
||||||
|
|
||||||
export { ScrollArea, ScrollBar }
|
export { ScrollArea, ScrollBar };
|
||||||
|
|
Loading…
Reference in New Issue