Skip to content

Commit

Permalink
web: add support for clearing attachments cache
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Jul 22, 2024
1 parent 9a37f7c commit c8aa8e3
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 35 deletions.
4 changes: 3 additions & 1 deletion apps/web/src/components/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ import {
mdiFormatListBulleted,
mdiLink,
mdiWindowClose,
mdiFileMusicOutline
mdiFileMusicOutline,
mdiBroom
} from "@mdi/js";
import { useTheme } from "@emotion/react";
import { Theme } from "@notesnook/theme";
Expand Down Expand Up @@ -548,3 +549,4 @@ export const WindowRestore = createIcon(
"M8 16V4h12v12Zm2-2h8V6h-8Zm-6 6V8.525h2V18h9.475v2Zm6-6V6v8Z"
);
export const WindowClose = createIcon(mdiWindowClose);
export const ClearCache = createIcon(mdiBroom);
119 changes: 85 additions & 34 deletions apps/web/src/dialogs/attachments-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Dialog from "../components/dialog";
import {
ChevronDown,
ChevronUp,
ClearCache,
Close,
DoubleCheckmark,
Download,
Expand Down Expand Up @@ -63,6 +64,8 @@ import {
} from "../components/virtualized-table";
import { FlexScrollContainer } from "../components/scroll-container";
import { BaseDialogProps, DialogManager } from "../common/dialog-manager";
import { ConfirmDialog } from "./confirm";
import { showToast } from "../utils/toast";

type ToolbarAction = {
title: string;
Expand Down Expand Up @@ -233,7 +236,11 @@ export const AttachmentsDialog = DialogManager.register(
</Flex>
{attachments && (
<VirtualizedTable
style={{ tableLayout: "fixed", borderCollapse: "collapse" }}
style={{
tableLayout: "fixed",
width: "100%",
borderCollapse: "collapse"
}}
header={
<Box
as="tr"
Expand Down Expand Up @@ -443,6 +450,7 @@ const Sidebar = memo(
<Flex
className="theme-scope-navigationMenu"
sx={{
flexShrink: 0,
flexDirection: "column",
justifyContent: "space-between",
width: 240,
Expand Down Expand Up @@ -484,40 +492,83 @@ const Sidebar = memo(
</Text>
)}
</Flex>
<Button
variant="secondary"
sx={{
bg: "transparent",
borderRadius: 100,
position: "relative",
width: 38,
height: 38
}}
title="Download all attachments"
onClick={async () => {
if (downloadStatus) {
await cancelDownload();
} else {
onDownloadAll();
}
}}
>
{downloadStatus ? <Close size={18} /> : <Download size={18} />}
{downloadStatus ? (
<Donut
value={
(downloadStatus.current / downloadStatus.total) * 100
<Flex>
<Button
variant="secondary"
sx={{
bg: "transparent",
borderRadius: 100,
position: "relative",
width: 38,
height: 38
}}
disabled={!!downloadStatus}
title="Clear cache"
onClick={async () => {
if (
await ConfirmDialog.show({
title: "Clear attachments cache?",
message: `Clearing attachments cache will perform the following actions:
- Downloaded images & files: **cleared**
- Pending uploads: **cleared**
- Uploaded images & files: _unaffected_
All attachments will be downloaded & cached again on access.
---
**Only use this for troubleshooting purposes. If you are having persistent issues, it is recommended that you reach out to us via support@streetwriters.co so we can help you resolve it permanently.**`,
negativeButtonText: "No",
positiveButtonText: "Yes"
})
) {
await db.fs().clear();
showToast("success", "Attachments cache cleared!");
}
max={100}
size={38}
sx={{
position: "absolute",
top: 0,
left: 0
}}
/>
) : null}
</Button>
}}
>
<ClearCache />
</Button>
<Button
variant="secondary"
sx={{
bg: "transparent",
borderRadius: 100,
position: "relative",
width: 38,
height: 38
}}
title="Download all attachments"
onClick={async () => {
if (downloadStatus) {
await cancelDownload();
} else {
onDownloadAll();
}
}}
>
{downloadStatus ? (
<Close size={18} />
) : (
<Download size={18} />
)}
{downloadStatus ? (
<Donut
value={
(downloadStatus.current / downloadStatus.total) * 100
}
max={100}
size={38}
sx={{
position: "absolute",
top: 0,
left: 0
}}
/>
) : null}
</Button>
</Flex>
</Flex>
</Flex>
</Flex>
Expand Down

0 comments on commit c8aa8e3

Please sign in to comment.