Skip to content

Commit 8bb80b7

Browse files
KomediruzeckiRokt33r
authored andcommitted
Implement drag and drop based order in sidebar for local space
Add array move lib Implemented orderedIds and DnD handling Add logic for moving note or doc into note target Add basic Database updates and API for orderedIds changes Implement ordered IDs initialization in storages Implement ordered IDs initializatio only in FSNote Remove excess function from createStore Updated handling of pouch DB in createStore Add create note update for parent folder ordered IDs Fix direct subfolders rather than all for create subfolders function Add implementation of trash/untrash note workspace orderedIds Update rename folder to update ordered IDs as well Implement createNote update of ordered IDs (workspace) Implement createFolder update of ordered IDs (workspace and parent folders) Implement folder reordering Implement moving of folders across different folder Refactor folder IDs to use real IDs Initialize real IDs (only FSNoteDB) Update rename folder so that it handles realIDs updates (previous and new parent folders ordered IDs update) Refactor code to use root folder instead of workspace ordered Ids Refactor and update for loading of storages Some improvements on loading multiple storages and some fails Add folder realID changing instead of reusing (also previous ordered IDs should be persisted on folder rename) Add handling of trash/untrash regarding ordered Ids Some ordered IDs bugfixes Remove console logs (most of them) Fix bug with parallel execution and parent folder creation on rename folder upsert folder calls Remove note id set from local space Fix bug with hiding items in sidebar (invalid key provided on callback) Assess some todos Update storages list data key Add order ID removal in purge note Fix sidebar tree ordered IDs handling
1 parent 466656e commit 8bb80b7

File tree

18 files changed

+845
-265
lines changed

18 files changed

+845
-265
lines changed

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"@mdi/js": "^5.9.55",
118118
"@mdi/react": "^1.2.1",
119119
"@types/react-color": "^3.0.4",
120+
"array-move": "^2.2.1",
120121
"chart.js": "^2.9.4",
121122
"classcat": "^4.0.2",
122123
"codemirror": "^5.59.2",

src/components/App.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import ContextMenu from '../shared/components/molecules/ContextMenu'
2121
import AppNavigator from './organisms/AppNavigator'
2222
import Toast from '../shared/components/organisms/Toast'
2323
import styled from '../shared/lib/styled'
24+
import { useToast } from '../shared/lib/stores/toast'
2425

2526
const LoadingText = styled.div`
2627
margin: 30px;
@@ -36,11 +37,12 @@ const AppContainer = styled.div`
3637
`
3738

3839
const App = () => {
39-
const { initialize, storageMap } = useDb()
40+
const { initialize, storageMap, getUninitializedStorageData } = useDb()
4041
const { push, pathname } = useRouter()
4142
const [initialized, setInitialized] = useState(false)
4243
const { togglePreferencesModal, preferences } = usePreferences()
4344
const { navigate: navigateToStorage } = useStorageRouter()
45+
const { pushMessage } = useToast()
4446

4547
useEffectOnce(() => {
4648
initialize()
@@ -60,8 +62,21 @@ const App = () => {
6062
}
6163
}
6264
setInitialized(true)
65+
66+
// notify on failed initializations
67+
const uninitializedStorageData = await getUninitializedStorageData()
68+
if (uninitializedStorageData.length > 0) {
69+
pushMessage({
70+
title: 'Error',
71+
description: `Failed to initialize some storages, please check console for more info.`,
72+
})
73+
}
6374
})
6475
.catch((error) => {
76+
pushMessage({
77+
title: 'Error',
78+
description: `Failed to initialize some storages, please check console for more info.`,
79+
})
6580
console.error(error)
6681
})
6782
})

src/components/organisms/FolderDetail.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
selectStyle,
1919
} from '../../shared/lib/styled/styleFunctions'
2020
import styled from '../../shared/lib/styled'
21+
import { NOTE_ID_PREFIX } from '../../lib/db/consts'
2122

2223
interface FolderDetailProps {
2324
storage: NoteStorage
@@ -46,7 +47,11 @@ const FolderDetail = ({ storage, folderPathname }: FolderDetailProps) => {
4647
return []
4748
}
4849

49-
return [...folder.noteIdSet]
50+
return [
51+
...(folder.orderedIds || []).filter((orderId) =>
52+
orderId.startsWith(NOTE_ID_PREFIX)
53+
),
54+
]
5055
.reduce((notes, noteId) => {
5156
const note = storage.noteMap[noteId]
5257
if (note != null && !note.trashed) {

src/components/organisms/SidebarContainer.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import { useTranslation } from 'react-i18next'
2222
import { useSearchModal } from '../../lib/searchModal'
2323
import styled from '../../shared/lib/styled'
2424
import cc from 'classcat'
25+
import { SidebarTreeSortingOrders } from '../../shared/lib/sidebar'
2526
import { useGeneralStatus } from '../../lib/generalStatus'
2627
import { useLocalUI } from '../../lib/v2/hooks/local/useLocalUI'
27-
import {
28-
mapTree,
29-
SidebarTreeSortingOrders,
30-
} from '../../lib/v2/mappers/local/sidebarTree'
28+
import { mapTree } from '../../lib/v2/mappers/local/sidebarTree'
3129
import { useLocalDB } from '../../lib/v2/hooks/local/useLocalDB'
3230
import { useLocalDnd } from '../../lib/v2/hooks/local/useLocalDnd'
3331
import { CollapsableType } from '../../lib/v2/stores/sidebarCollapse'
@@ -275,14 +273,22 @@ const SidebarContainer = ({
275273
)
276274

277275
const getFoldEvents = useCallback(
278-
(type: CollapsableType, key: string) => {
276+
(type: CollapsableType, key: string, reversed?: boolean) => {
277+
if (reversed) {
278+
return {
279+
fold: () => unfoldItem(type, key),
280+
unfold: () => foldItem(type, key),
281+
toggle: () => toggleItem(type, key),
282+
}
283+
}
284+
279285
return {
280286
fold: () => foldItem(type, key),
281287
unfold: () => unfoldItem(type, key),
282288
toggle: () => toggleItem(type, key),
283289
}
284290
},
285-
[foldItem, unfoldItem, toggleItem]
291+
[toggleItem, unfoldItem, foldItem]
286292
)
287293

288294
const tree = useMemo(() => {
@@ -338,11 +344,13 @@ const SidebarContainer = ({
338344
const sidebarHeaderControls: SidebarControls = useMemo(() => {
339345
return {
340346
'View Options': (tree || []).map((category) => {
347+
const key = (category.label || '').toLocaleLowerCase()
348+
const hideKey = `hide-${key}`
341349
return {
342350
type: 'check',
343351
label: category.label,
344-
checked: !sideBarOpenedLinksIdsSet.has(`hide-${category.label}`),
345-
onClick: () => toggleItem('links', `hide-${category.label}`),
352+
checked: !sideBarOpenedLinksIdsSet.has(hideKey),
353+
onClick: () => toggleItem('links', hideKey),
346354
}
347355
}),
348356
Sorting: Object.values(SidebarTreeSortingOrders).map((sort) => {

0 commit comments

Comments
 (0)