diff --git a/src/pages/Newtab/components/MainTop.tsx b/src/pages/Newtab/components/MainTop.tsx index f5d38c4..ce07210 100644 --- a/src/pages/Newtab/components/MainTop.tsx +++ b/src/pages/Newtab/components/MainTop.tsx @@ -1,16 +1,18 @@ import React, { useCallback, useState } from 'react' -import { Button, Tooltip, FormElement, Input, useTheme, changeTheme, Switch } from '@nextui-org/react' -import { RiAddLine, RiMenuFoldFill, RiMenuUnfoldFill, RiMoonFill, RiPrinterLine, RiSunFill } from 'react-icons/ri' + +import { Button, changeTheme, Tooltip, useTheme } from '@nextui-org/react' +import { saveAs } from 'file-saver' +import { BiExport, BiImport } from 'react-icons/bi' import { FiHome } from 'react-icons/fi' -import { BiImport, BiExport } from 'react-icons/bi' +import { RiAddLine, RiMenuFoldFill, RiMenuUnfoldFill, RiMoonFill, RiPrinterLine, RiSunFill } from 'react-icons/ri' +import { useRecoilState, useRecoilValue } from 'recoil' import { v4 as uuidv4 } from 'uuid' -import { saveAs } from 'file-saver'; -import './css/MainTop.scss' -import { ImportDataModal } from './data' import { activeNoteState, binNotesState, notesState, sidebarActiveState } from '../Store' import { Note, QuickLink } from '../types' -import { useRecoilState, useRecoilValue } from 'recoil' +import { ImportDataModal } from './data' + +import './css/MainTop.scss' const { storage } = chrome @@ -89,18 +91,21 @@ const MainTop = () => { binNotes: Note[] quicklinks: QuickLink[] quicklinksorder: string[] + pinnedNoteIds: string[] } const data: Data = { dbnotes: notes, binNotes, quicklinks: [], - quicklinksorder: [] + quicklinksorder: [], + pinnedNoteIds: [], } - storage.local.get(['quicklinks', 'quicklinksorder'], ({ quicklinks, quicklinksorder }) => { + storage.local.get(['quicklinks', 'quicklinksorder', 'pinnedNoteIds'], ({ quicklinks, quicklinksorder, pinnedNoteIds }) => { data.quicklinks = quicklinks || [] data.quicklinksorder = quicklinksorder || [] + data.pinnedNoteIds = pinnedNoteIds const fileToSave = new Blob([JSON.stringify(data)], { type: 'application/json' }) diff --git a/src/pages/Newtab/components/data/ImportDataModal.tsx b/src/pages/Newtab/components/data/ImportDataModal.tsx index 7e45270..d1f0195 100644 --- a/src/pages/Newtab/components/data/ImportDataModal.tsx +++ b/src/pages/Newtab/components/data/ImportDataModal.tsx @@ -1,12 +1,13 @@ import React, { useEffect, useRef, useState } from 'react'; -import { Modal, Text, Button, Loading } from '@nextui-org/react'; -import { useRecoilValue } from 'recoil'; +import { Button, Loading, Modal, Text } from '@nextui-org/react'; import { isPlainObject } from 'lodash'; +import { useRecoilValue } from 'recoil'; -import { Note, QuickLink } from '../../types'; import { binNotesState, notesState } from '../../Store'; -import './css/ImportDataModel.scss' +import { Note, QuickLink } from '../../types'; + +import './css/ImportDataModel.scss'; interface ImportDataModalProps { isImportDataModelOpen: boolean @@ -18,6 +19,7 @@ interface Data { binNotes: Note[] quicklinks: QuickLink[] quicklinksorder: string[] + pinnedNoteIds: string[] } const { storage } = chrome @@ -43,12 +45,30 @@ export const ImportDataModal: React.FC = ({ isImportDataMo try { const json: Data = JSON.parse(jsonDataString) - const { dbnotes, binNotes, quicklinks, quicklinksorder } = json - - const [isNotesValid, isBinNotesValid, isQuicklinksValid, isQuicklinksOrderValid] = [Array.isArray(dbnotes), Array.isArray(binNotes), isPlainObject(quicklinks), Array.isArray(quicklinksorder)] - - if (!isNotesValid || !isBinNotesValid || !isQuicklinksOrderValid || !isQuicklinksValid) { - const err = `${!isNotesValid ? 'notes, ' : ""}${!isBinNotesValid ? 'binNotes, ' : ""}${!isQuicklinksValid ? 'quicklinks, ' : ""}${!isQuicklinksOrderValid ? 'quicklinksorder' : ""} not valid.` + const { dbnotes, binNotes, quicklinks, quicklinksorder, pinnedNoteIds } = json + + const [ + isNotesValid, + isBinNotesValid, + isQuicklinksValid, + isQuicklinksOrderValid, + isPinnedNoteIdsValid + ] = [ + Array.isArray(dbnotes), + Array.isArray(binNotes), + isPlainObject(quicklinks), + Array.isArray(quicklinksorder), + Array.isArray(pinnedNoteIds || []) + ] + + if ( + !isNotesValid + || !isBinNotesValid + || !isQuicklinksOrderValid + || !isQuicklinksValid + || !isPinnedNoteIdsValid + ) { + const err = `${!isNotesValid ? 'notes, ' : ""}${!isBinNotesValid ? 'binNotes, ' : ""}${!isQuicklinksValid ? 'quicklinks, ' : ""}${!isQuicklinksOrderValid ? 'quicklinksorder, ' : ""}${!isPinnedNoteIdsValid ? 'pinnedNoteIds, ' : ''} not valid.` console.error(err) setIsJsonValid(false) return