🩹 fix: Fix Hydration errors for TableRowHeightSwitch
This commit is contained in:
parent
7098065704
commit
a0b14ace3c
2 changed files with 36 additions and 31 deletions
|
|
@ -10,11 +10,9 @@ import {
|
||||||
import TableColumnFilter, {
|
import TableColumnFilter, {
|
||||||
type Column,
|
type Column,
|
||||||
} from "@/components/table-column-filter";
|
} from "@/components/table-column-filter";
|
||||||
import {
|
import { type RowHeight } from "@/components/table-row-height-switch";
|
||||||
type RowHeight,
|
|
||||||
TableRowHeightSwitch,
|
|
||||||
} from "@/components/table-row-height-switch";
|
|
||||||
import FileTypeFilter from "@/components/file-type-filter";
|
import FileTypeFilter from "@/components/file-type-filter";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
interface FileFiltersProps {
|
interface FileFiltersProps {
|
||||||
telegramId: string;
|
telegramId: string;
|
||||||
|
|
@ -27,6 +25,14 @@ interface FileFiltersProps {
|
||||||
setRowHeight: (e: RowHeight) => void;
|
setRowHeight: (e: RowHeight) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TableRowHeightSwitch = dynamic(
|
||||||
|
() =>
|
||||||
|
import("@/components/table-row-height-switch").then(
|
||||||
|
(mod) => mod.TableRowHeightSwitch,
|
||||||
|
),
|
||||||
|
{ ssr: false },
|
||||||
|
);
|
||||||
|
|
||||||
export function FileFilters({
|
export function FileFilters({
|
||||||
telegramId,
|
telegramId,
|
||||||
chatId,
|
chatId,
|
||||||
|
|
@ -39,7 +45,7 @@ export function FileFilters({
|
||||||
}: FileFiltersProps) {
|
}: FileFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="mb-6 flex flex-col justify-between md:flex-row">
|
<div className="mb-6 flex flex-col justify-between md:flex-row">
|
||||||
<div className="grid grid-cols-2 gap-4 md:flex-row md:flex">
|
<div className="grid grid-cols-2 gap-4 md:flex md:flex-row">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search files..."
|
placeholder="Search files..."
|
||||||
value={filters.search}
|
value={filters.search}
|
||||||
|
|
@ -83,12 +89,10 @@ export function FileFilters({
|
||||||
columns={columns}
|
columns={columns}
|
||||||
onColumnConfigChange={onColumnConfigChange}
|
onColumnConfigChange={onColumnConfigChange}
|
||||||
/>
|
/>
|
||||||
{!!rowHeight && !!setRowHeight && (
|
<TableRowHeightSwitch
|
||||||
<TableRowHeightSwitch
|
rowHeight={rowHeight}
|
||||||
rowHeight={rowHeight}
|
setRowHeightAction={setRowHeight}
|
||||||
setRowHeightAction={setRowHeight}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import { FileCard } from "./file-card";
|
||||||
import React, {
|
import React, {
|
||||||
memo,
|
memo,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
|
@ -155,25 +155,23 @@ export function FileList({ accountId, chatId }: FileListProps) {
|
||||||
return () => observer.disconnect();
|
return () => observer.disconnect();
|
||||||
}, [handleLoadMore]);
|
}, [handleLoadMore]);
|
||||||
|
|
||||||
const contentWH = useMemo(() => {
|
const dynamicClass = useCallback(() => {
|
||||||
switch (rowHeight) {
|
switch (rowHeight) {
|
||||||
case "s":
|
case "s":
|
||||||
return "h-6 w-6";
|
return {
|
||||||
|
content: "h-6 w-6",
|
||||||
|
contentCell: "w-6",
|
||||||
|
};
|
||||||
case "m":
|
case "m":
|
||||||
return "h-20 w-20";
|
return {
|
||||||
|
content: "h-20 w-20",
|
||||||
|
contentCell: "w-24",
|
||||||
|
};
|
||||||
case "l":
|
case "l":
|
||||||
return "h-60 w-60";
|
return {
|
||||||
}
|
content: "h-60 w-60",
|
||||||
}, [rowHeight]);
|
contentCell: "w-64",
|
||||||
|
};
|
||||||
const contentCellWidth = useMemo(() => {
|
|
||||||
switch (rowHeight) {
|
|
||||||
case "s":
|
|
||||||
return "w-6";
|
|
||||||
case "m":
|
|
||||||
return "w-24";
|
|
||||||
case "l":
|
|
||||||
return "w-64";
|
|
||||||
}
|
}
|
||||||
}, [rowHeight]);
|
}, [rowHeight]);
|
||||||
|
|
||||||
|
|
@ -245,7 +243,7 @@ export function FileList({ accountId, chatId }: FileListProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
contentWH,
|
dynamicClass().content,
|
||||||
"flex items-center justify-center rounded bg-muted",
|
"flex items-center justify-center rounded bg-muted",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -269,7 +267,7 @@ export function FileList({ accountId, chatId }: FileListProps) {
|
||||||
<PhotoColumnImage
|
<PhotoColumnImage
|
||||||
thumbnail={file.thumbnail}
|
thumbnail={file.thumbnail}
|
||||||
name={file.name}
|
name={file.name}
|
||||||
wh={contentWH}
|
wh={dynamicClass().content}
|
||||||
/>
|
/>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent asChild>
|
<TooltipContent asChild>
|
||||||
|
|
@ -371,9 +369,10 @@ export function FileList({ accountId, chatId }: FileListProps) {
|
||||||
col.isVisible ? (
|
col.isVisible ? (
|
||||||
<TableHead
|
<TableHead
|
||||||
key={col.id}
|
key={col.id}
|
||||||
|
suppressHydrationWarning
|
||||||
className={cn(
|
className={cn(
|
||||||
col.className ?? "",
|
col.className ?? "",
|
||||||
col.id === "content" ? contentCellWidth : "",
|
col.id === "content" ? dynamicClass().contentCell : "",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{col.label}
|
{col.label}
|
||||||
|
|
@ -406,7 +405,9 @@ export function FileList({ accountId, chatId }: FileListProps) {
|
||||||
key={col.id}
|
key={col.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
col.className ?? "",
|
col.className ?? "",
|
||||||
col.id === "content" ? contentCellWidth : "",
|
col.id === "content"
|
||||||
|
? dynamicClass().contentCell
|
||||||
|
: "",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{columnRenders[col.id]!(file, index)}
|
{columnRenders[col.id]!(file, index)}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue