diff --git a/eslint.config.js b/eslint.config.js index 01d423c..7034435 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -23,6 +23,18 @@ export default [ rules: { "react/react-in-jsx-scope": "off", "react/no-unknown-property": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + args: "all", + argsIgnorePattern: "^_", + caughtErrors: "all", + caughtErrorsIgnorePattern: "^_", + destructuredArrayIgnorePattern: "^_", + varsIgnorePattern: "^_", + ignoreRestSiblings: true, + }, + ], }, }, ] diff --git a/src/components/cardSelector/ImportButton.tsx b/src/components/cardSelector/ImportButton.tsx index 025a5f0..6991aca 100644 --- a/src/components/cardSelector/ImportButton.tsx +++ b/src/components/cardSelector/ImportButton.tsx @@ -7,11 +7,13 @@ import { updateLocalStorage } from "../../utils/localStorage" import { Tooltip } from "./Tooltip" import { defaultClassName } from "./utils" +type legacySupportTypes = { type: CardTypes | string } + export function ImportButton() { function _handleImport() { // guard clause to prevent overwriting existing cards - if (images.images.value || notes.notes.value) { + if (Object.keys(images.images.value).length || Object.keys(notes.notes.value).length) { const isConfirmed = confirm("Are you sure you want to overwrite your existing cards?") if (!isConfirmed) return } @@ -32,30 +34,22 @@ export function ImportButton() { let content = readerEvent.target?.result; // get only the base64 parts and not any identifiers content = (content as string).split(',')[1] - const data: Record> = convertBase64ToJson(content) - console.log(data) + const data: Record, 'type'> & legacySupportTypes> = convertBase64ToJson(content) for (const key in data) { const item = data[key] - const { id, ...rest } = item - console.log(id, rest) - switch (item.type) { - case CardTypes.IMAGES: - console.log("adding image: ", rest) - images.addImage(rest as ImageCardType) - break; - case CardTypes.NOTES: - notes.addNote(rest as NoteCardType) - break; - case CardTypes.TEXTS: - texts.addText(rest as TextCardType) - break; - default: - break; + const { id: _, ...rest } = item + if (item.type === CardTypes.IMAGES || item.type == 'image') { + images.addImage(rest as ImageCardType) + continue + } else if (item.type === CardTypes.NOTES || item.type === 'note') { + notes.addNote(rest as NoteCardType) + continue + } else if (item.type === CardTypes.TEXTS || item.type === 'text') { + texts.addText(rest as TextCardType) + continue } } - console.log("images: ", images.images.value) - updateLocalStorage(CardTypes.NOTES, notes.notes).notify() updateLocalStorage(CardTypes.IMAGES, images.images).notify() updateLocalStorage(CardTypes.TEXTS, texts.texts).notify() diff --git a/tsconfig.json b/tsconfig.json index 618eae5..a3237a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,7 @@ { "compilerOptions": { + "noUnusedLocals": false, + "noUnusedParameters": false, "target": "ES2020", "useDefineForClassFields": true, "module": "ESNext", @@ -15,8 +17,6 @@ /* Linting */ "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "jsx": "preserve" },