Skip to content

Commit

Permalink
Fix the virtual uncategorized category appearing as tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
VPKSoft committed Sep 28, 2024
1 parent 2c3eccc commit e38b8d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/components/reusable/PasswordList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DataEntry } from "../../types/PasswordEntry";
import { CommonProps } from "../Types";
import { useLocalize } from "../../i18n";
import { generalId } from "../../misc/DataUtils";
import { unCategorized } from "../../utilities/app/Files";
import { SearchMode, SearchTextBoxValue } from "./inputs/SearchTextBox";

/**
Expand Down Expand Up @@ -53,7 +54,7 @@ const PasswordList = ({
const treeData = React.useMemo(() => {
const generalName = lm("categoryGeneral");
const generalNode = dataSource.find(f => f.id === generalId) ?? {
name: "#NO_CATEGORY#",
name: unCategorized,
id: generalId,
parentId: -1,
};
Expand Down
12 changes: 11 additions & 1 deletion src/misc/DataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SOFTWARE.
*/

import { DataEntry } from "../types/PasswordEntry";
import { unCategorized } from "../utilities/app/Files";

const getNewId = (dataSource: DataEntry[]) => {
let id = Math.max(...dataSource.map(f => f.id));
Expand All @@ -36,14 +37,23 @@ const getNewId = (dataSource: DataEntry[]) => {
const newEntry = (parentId: number, dataSource: DataEntry[], newDataName: string) => {
const id = getNewId(dataSource);

let tags = dataSource.find(f => f.id === parentId)?.name;
if (!tags) {
tags = "";
}

if (tags === unCategorized) {
tags = "";
}

const result: DataEntry = {
name: newDataName,
password: "",
userName: "",
notes: "",
id: id,
parentId: parentId,
tags: dataSource.find(f => f.id === parentId)?.name,
tags: tags,
};

return result;
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/app/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const loadFile = async (password: string, fileName: string) => {
data.entries.push({
parentId: -1,
id: generalId,
name: "#NO_CATEGORY#",
name: unCategorized,
});

data.version = 1;
Expand Down Expand Up @@ -234,4 +234,6 @@ const generateTags = <T>(fileData: (DataEntry | GeneralEntry<T>)[]) => {
return [...resultSet];
};

export { loadFile, saveFile, selectFileToOpen, selectFileToSave, generateTags };
const unCategorized = "#NO_CATEGORY#";

export { loadFile, saveFile, selectFileToOpen, selectFileToSave, generateTags, unCategorized };

0 comments on commit e38b8d5

Please sign in to comment.