Repository navigation
Expand file tree
/
Copy pathDatabaseStorageNotice.tsx
More file actions
64 lines (62 loc) · 2.57 KB
/
Copy pathDatabaseStorageNotice.tsx
File metadata and controls
64 lines (62 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useAtomSet, useAtomValue } from "@effect/atom-react";
import { AsyncResult } from "effect/reactivity";
import { copyTextWithHaptic } from "../../../lib/copyTextWithHaptic";
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../../state/preferences";
import { serverEnvironment } from "../../../state/server";
import type { SettingsTarget } from "../settings-environment-filter";
import { ListActionRow as SettingsActionRow } from "../../../components/ui/ListActionRow";
import { SettingsSection } from "./SettingsSection";
/** Suggests `t3 doctor` on every machine whose database still holds at least 1 GiB of freed pages. */
export function DatabaseStorageNotice({
targets,
}: {
readonly targets: readonly SettingsTarget[];
}) {
const recommendations = useAtomValue(
serverEnvironment.databaseCompactionRecommendations(
JSON.stringify(targets.map((target) => target.environmentId)),
),
);
const preferences = useAtomValue(mobilePreferencesAtom);
const updatePreferences = useAtomSet(updateMobilePreferencesAtom);
const dismissed = AsyncResult.isSuccess(preferences)
? (preferences.value.dismissedDatabaseStorageNotices ?? [])
: [];
const visible = recommendations.filter(
(recommendation) => !dismissed.includes(recommendation.environmentId),
);
if (visible.length === 0) return null;
return (
<SettingsSection
title="Reclaim database space"
footer="These databases still hold space freed by history cleanup. Run the command on each machine to reclaim it. It restarts the background service. Quit the desktop app first if it hosts the environment."
>
{visible.map(({ environmentId, status }) => (
<SettingsActionRow
key={environmentId}
icon="doc.on.doc"
label={targets.find((target) => target.environmentId === environmentId)?.label ?? ""}
description={status.compactCommand}
detail={`${(status.reclaimableBytes / 1024 ** 3).toFixed(1)} GiB`}
onPress={() => copyTextWithHaptic(status.compactCommand, { target: "command" })}
/>
))}
<SettingsActionRow
icon="xmark"
label="Dismiss"
onPress={() =>
updatePreferences({
transform: (current) => ({
dismissedDatabaseStorageNotices: [
...new Set([
...(current.dismissedDatabaseStorageNotices ?? []),
...visible.map((recommendation) => recommendation.environmentId),
]),
],
}),
})
}
/>
</SettingsSection>
);
}