add button to delete junk files

This commit is contained in:
marlon-erler
2024-07-28 16:08:29 +02:00
parent 02374a52be
commit 3274d12337
5 changed files with 50 additions and 9 deletions
+21 -5
View File
@@ -516,12 +516,12 @@
return true; return true;
}; };
// recursion // recursion
recurse = (pathComponents, fn) => { recurse = (rootDirectory, fn) => {
loop_over_files: for (const key of Object.keys(localStorage)) { loop_over_files: for (const key of Object.keys(localStorage)) {
const pathComponentsOfCurrentEntity = _StorageModel.stringToPathComponents(key); const pathComponentsOfCurrentEntity = _StorageModel.stringToPathComponents(key);
loop_over_path_components: for (let i = 0; i < pathComponents.length; i++) { loop_over_path_components: for (let i = 0; i < rootDirectory.length; i++) {
if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files; if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files;
if (pathComponentsOfCurrentEntity[i] != pathComponents[i]) if (pathComponentsOfCurrentEntity[i] != rootDirectory[i])
continue loop_over_files; continue loop_over_files;
} }
fn(pathComponentsOfCurrentEntity); fn(pathComponentsOfCurrentEntity);
@@ -557,6 +557,13 @@
if (object == null) return null; if (object == null) return null;
return object; return object;
}; };
// cleaning
removeJunk = () => {
this.recurse([], (path) => {
if (path[0] == DATA_VERSION) return;
this.remove(path);
});
};
// tree // tree
initializeTree = () => { initializeTree = () => {
console.log("initializing tree"); console.log("initializing tree");
@@ -2685,7 +2692,8 @@
contentEmpty: "(empty)", contentEmpty: "(empty)",
path: "Path", path: "Path",
content: "Content", content: "Content",
deleteItem: "Delete item" deleteItem: "Delete item",
removeJunkButton: "Delete junk files"
}, },
chatPage: { chatPage: {
closeChatAudioLabe: "close chat", closeChatAudioLabe: "close chat",
@@ -5487,7 +5495,11 @@
[storageViewModel2.selectedPath], [storageViewModel2.selectedPath],
() => { () => {
if (storageViewModel2.selectedPath.value == PATH_COMPONENT_SEPARATOR) if (storageViewModel2.selectedPath.value == PATH_COMPONENT_SEPARATOR)
return /* @__PURE__ */ createElement("span", { class: "secondary" }, translations.storage.noItemSelected); return /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("span", { class: "secondary" }, translations.storage.noItemSelected), /* @__PURE__ */ createElement("hr", null), DangerousActionButton(
translations.storage.removeJunkButton,
"delete_forever",
storageViewModel2.removeJunk
));
return /* @__PURE__ */ createElement("div", { class: "flex-column gap" }, /* @__PURE__ */ createElement("div", { class: "tile flex-no" }, /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("b", null, translations.storage.path), /* @__PURE__ */ createElement( return /* @__PURE__ */ createElement("div", { class: "flex-column gap" }, /* @__PURE__ */ createElement("div", { class: "tile flex-no" }, /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("b", null, translations.storage.path), /* @__PURE__ */ createElement(
"span", "span",
{ {
@@ -5559,6 +5571,10 @@
this.storageModel.removeRecursively(path); this.storageModel.removeRecursively(path);
this.didMakeChanges.value = true; this.didMakeChanges.value = true;
}; };
removeJunk = () => {
this.storageModel.removeJunk();
this.selectedPath.value = PATH_COMPONENT_SEPARATOR;
};
// view // view
showStorageModal = () => { showStorageModal = () => {
this.isShowingStorageModal.value = true; this.isShowingStorageModal.value = true;
+11 -3
View File
@@ -68,7 +68,7 @@ export default class StorageModel {
}; };
// recursion // recursion
recurse = (pathComponents: string[], fn: (path: string[]) => void): void => { recurse = (rootDirectory: string[], fn: (path: string[]) => void): void => {
loop_over_files: for (const key of Object.keys(localStorage)) { loop_over_files: for (const key of Object.keys(localStorage)) {
// get path of current entity // get path of current entity
const pathComponentsOfCurrentEntity: string[] = const pathComponentsOfCurrentEntity: string[] =
@@ -77,11 +77,11 @@ export default class StorageModel {
// exit if entity does not match // exit if entity does not match
loop_over_path_components: for ( loop_over_path_components: for (
let i = 0; let i = 0;
i < pathComponents.length; i < rootDirectory.length;
i++ i++
) { ) {
if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files; if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files;
if (pathComponentsOfCurrentEntity[i] != pathComponents[i]) if (pathComponentsOfCurrentEntity[i] != rootDirectory[i])
continue loop_over_files; continue loop_over_files;
} }
@@ -135,6 +135,14 @@ export default class StorageModel {
return object; return object;
}; };
// cleaning
removeJunk = (): void => {
this.recurse([], (path: string[]) => {
if (path[0] == DATA_VERSION) return;
this.remove(path);
})
}
// tree // tree
initializeTree = (): void => { initializeTree = (): void => {
console.log("initializing tree"); console.log("initializing tree");
+11 -1
View File
@@ -14,7 +14,17 @@ export function FileBrowser(storageViewModel: StorageViewModel) {
() => { () => {
if (storageViewModel.selectedPath.value == PATH_COMPONENT_SEPARATOR) if (storageViewModel.selectedPath.value == PATH_COMPONENT_SEPARATOR)
return ( return (
<span class="secondary">{translations.storage.noItemSelected}</span> <div>
<span class="secondary">{translations.storage.noItemSelected}</span>
<hr></hr>
{DangerousActionButton(
translations.storage.removeJunkButton,
"delete_forever",
storageViewModel.removeJunk
)}
</div>
); );
return ( return (
+2
View File
@@ -126,6 +126,8 @@ const englishTranslations = {
content: "Content", content: "Content",
deleteItem: "Delete item", deleteItem: "Delete item",
removeJunkButton: "Delete junk files"
}, },
chatPage: { chatPage: {
+5
View File
@@ -38,6 +38,11 @@ export default class StorageViewModel {
this.didMakeChanges.value = true; this.didMakeChanges.value = true;
}; };
removeJunk = (): void => {
this.storageModel.removeJunk();
this.selectedPath.value = PATH_COMPONENT_SEPARATOR;
};
// view // view
showStorageModal = (): void => { showStorageModal = (): void => {
this.isShowingStorageModal.value = true; this.isShowingStorageModal.value = true;