fix: preserve board drafts and widget scroll state (#6637)
This commit is contained in:
1 parent
b2fa46c760
commit
011ce8e5a3
2 files changed
+19
-8
No files matched your search
@@ -93,8 +93,7 @@ export const LayoutSettingsContent = ({ board, form, isSaving, saveSettingsAsync
|
|||||||
setResettingLayoutId(layout.id);
|
setResettingLayoutId(layout.id);
|
||||||
void (async () => {
|
void (async () => {
|
||||||
try {
|
try {
|
||||||
const savedValues = form.isDirty() ? await saveSettingsAsync() : form.values;
|
const canonicalLayout = board.layouts.find((candidate) => candidate.id === layout.id);
|
||||||
const canonicalLayout = savedValues ? findCanonicalLayout(savedValues.layouts, layout) : undefined;
|
|
||||||
if (!canonicalLayout) return;
|
if (!canonicalLayout) return;
|
||||||
|
|
||||||
await resetLayout({ boardId: board.id, layoutId: canonicalLayout.id });
|
await resetLayout({ boardId: board.id, layoutId: canonicalLayout.id });
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
Box,
|
Box,
|
||||||
@@ -58,6 +58,10 @@ export default function MediaMissingWidget({
|
|||||||
});
|
});
|
||||||
const data = getUsableWidgetQueryData(mediaQuery);
|
const data = getUsableWidgetQueryData(mediaQuery);
|
||||||
const [selectedTab, setSelectedTab] = useState<MediaMissingTab>(showMissing ? "missing" : "queued");
|
const [selectedTab, setSelectedTab] = useState<MediaMissingTab>(showMissing ? "missing" : "queued");
|
||||||
|
const tabScrollPositionsRef = useRef<Record<MediaMissingTab, { x: number; y: number }>>({
|
||||||
|
missing: { x: 0, y: 0 },
|
||||||
|
queued: { x: 0, y: 0 },
|
||||||
|
});
|
||||||
const activeTab = resolveMediaMissingTab(selectedTab, showMissing, showQueued);
|
const activeTab = resolveMediaMissingTab(selectedTab, showMissing, showQueued);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -92,10 +96,18 @@ export default function MediaMissingWidget({
|
|||||||
const tabLabel = (label: string, shown: number, total: number) => (isThin ? total : `${label} (${shown}/${total})`);
|
const tabLabel = (label: string, shown: number, total: number) => (isThin ? total : `${label} (${shown}/${total})`);
|
||||||
|
|
||||||
const renderPanel = (
|
const renderPanel = (
|
||||||
|
tab: MediaMissingTab,
|
||||||
entries: { item: MissingMediaItem | QueuedMediaItem; integrationId: string }[],
|
entries: { item: MissingMediaItem | QueuedMediaItem; integrationId: string }[],
|
||||||
emptyLabel: string,
|
emptyLabel: string,
|
||||||
) => (
|
) => (
|
||||||
<ScrollArea h="100%" scrollbarSize={4}>
|
<ScrollArea
|
||||||
|
h="100%"
|
||||||
|
scrollbarSize={4}
|
||||||
|
startScrollPosition={tabScrollPositionsRef.current[tab]}
|
||||||
|
onScrollPositionChange={(position) => {
|
||||||
|
tabScrollPositionsRef.current[tab] = position;
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Box p="xs">
|
<Box p="xs">
|
||||||
{entries.length === 0 ? (
|
{entries.length === 0 ? (
|
||||||
<Text size="sm" c="dimmed" ta="center" py="md">
|
<Text size="sm" c="dimmed" ta="center" py="md">
|
||||||
@@ -146,7 +158,7 @@ export default function MediaMissingWidget({
|
|||||||
{tabLabel(t("tab.missing"), missing.length, missingCount)}
|
{tabLabel(t("tab.missing"), missing.length, missingCount)}
|
||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
<Box h="calc(100% - 40px)">{renderPanel(missing, t("empty.missing"))}</Box>
|
<Box h="calc(100% - 40px)">{renderPanel("missing", missing, t("empty.missing"))}</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
)}
|
)}
|
||||||
{showQueued && (
|
{showQueued && (
|
||||||
@@ -157,7 +169,7 @@ export default function MediaMissingWidget({
|
|||||||
{tabLabel(t("tab.queued"), queued.length, queuedCount)}
|
{tabLabel(t("tab.queued"), queued.length, queuedCount)}
|
||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
<Box h="calc(100% - 40px)">{renderPanel(queued, t("empty.queued"))}</Box>
|
<Box h="calc(100% - 40px)">{renderPanel("queued", queued, t("empty.queued"))}</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
)}
|
)}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
@@ -202,12 +214,12 @@ export default function MediaMissingWidget({
|
|||||||
|
|
||||||
{showMissing && (
|
{showMissing && (
|
||||||
<Tabs.Panel value="missing" flex={1} style={{ overflow: "hidden" }}>
|
<Tabs.Panel value="missing" flex={1} style={{ overflow: "hidden" }}>
|
||||||
{activeTab === "missing" && renderPanel(missing, t("empty.missing"))}
|
{activeTab === "missing" && renderPanel("missing", missing, t("empty.missing"))}
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
)}
|
)}
|
||||||
{showQueued && (
|
{showQueued && (
|
||||||
<Tabs.Panel value="queued" flex={1} style={{ overflow: "hidden" }}>
|
<Tabs.Panel value="queued" flex={1} style={{ overflow: "hidden" }}>
|
||||||
{activeTab === "queued" && renderPanel(queued, t("empty.queued"))}
|
{activeTab === "queued" && renderPanel("queued", queued, t("empty.queued"))}
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
)}
|
)}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|||||||
Reference in new issue
Block a user