Skip to content

Commit 0e4d6db

Browse files
committed
Update some components
Refactor AppNavigator Port features from AppNavigator Refactor CreateStoragePage
1 parent 060eb6c commit 0e4d6db

18 files changed

+296
-205
lines changed

src/components/Application.tsx

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import ContentLayout, {
66
} from '../shared/components/templates/ContentLayout'
77
import { SidebarState } from '../shared/lib/sidebar'
88
import { useRouter } from '../lib/router'
9-
import {
10-
StorageNotesRouteParams,
11-
StorageTagsRouteParams,
12-
StorageTrashCanRouteParams,
13-
useRouteParams,
14-
} from '../lib/routeParams'
15-
import { NoteStorage } from '../lib/db/types'
9+
import { StorageNotesRouteParams, useRouteParams } from '../lib/routeParams'
1610
import { filenamify } from '../lib/string'
1711
import { usePreferences } from '../lib/preferences'
1812
import { usePreviewStyle } from '../lib/preview'
@@ -41,19 +35,17 @@ interface ApplicationProps {
4135
content: ContentLayoutProps
4236
className?: string
4337
initialSidebarState?: SidebarState
44-
storage: NoteStorage
4538
}
4639

4740
const Application = ({
4841
content: { topbar, ...content },
4942
children,
50-
storage,
5143
initialSidebarState,
5244
}: React.PropsWithChildren<ApplicationProps>) => {
53-
const routeParams = useRouteParams() as
54-
| StorageNotesRouteParams
55-
| StorageTrashCanRouteParams
56-
| StorageTagsRouteParams
45+
const { storageMap } = useDb()
46+
const routeParams = useRouteParams() as StorageNotesRouteParams
47+
const { workspaceId } = routeParams
48+
const storage = storageMap[workspaceId]
5749

5850
const { push, goBack, goForward } = useRouter()
5951
const { generalStatus, setGeneralStatus } = useGeneralStatus()
@@ -65,6 +57,9 @@ const Application = ({
6557
const { pushMessage } = useToast()
6658

6759
const note = useMemo(() => {
60+
if (storage == null) {
61+
return undefined
62+
}
6863
switch (routeParams.name) {
6964
case 'workspaces.notes': {
7065
if (routeParams.noteId == null) {
@@ -79,53 +74,37 @@ const Application = ({
7974
}
8075
return note
8176
}
82-
case 'workspaces.labels.show': {
83-
if (routeParams.noteId == null) {
84-
return undefined
85-
}
86-
const note = storage.noteMap[routeParams.noteId]
87-
if (note == null) {
88-
return undefined
89-
}
90-
if (!note.tags.includes(routeParams.tagName)) {
91-
return undefined
92-
}
93-
return note
94-
}
95-
case 'workspaces.archive': {
96-
if (routeParams.noteId == null) {
97-
return undefined
98-
}
99-
const note = storage.noteMap[routeParams.noteId]
100-
if (note == null || !note.trashed) {
101-
return undefined
102-
}
103-
return note
104-
}
10577
}
10678
return undefined
107-
}, [routeParams, storage.noteMap])
79+
}, [
80+
routeParams.folderPathname,
81+
routeParams.name,
82+
routeParams.noteId,
83+
storage,
84+
])
10885

109-
const storageId = storage.id
11086
const noteId = note?._id
11187

11288
const topbarTree = useMemo(() => {
89+
if (storage == null) {
90+
return undefined
91+
}
11392
return mapTopBarTree(storage.noteMap, storage.folderMap, storage, push)
11493
}, [push, storage])
11594

11695
const bookmark = useCallback(async () => {
117-
if (noteId == null) {
96+
if (noteId == null || storage == null) {
11897
return
11998
}
120-
await bookmarkNote(storageId, noteId)
121-
}, [storageId, noteId, bookmarkNote])
99+
await bookmarkNote(storage.id, noteId)
100+
}, [noteId, storage, bookmarkNote])
122101

123102
const unbookmark = useCallback(async () => {
124-
if (noteId == null) {
103+
if (noteId == null || storage == null) {
125104
return
126105
}
127-
await unbookmarkNote(storageId, noteId)
128-
}, [storageId, noteId, unbookmarkNote])
106+
await unbookmarkNote(storage.id, noteId)
107+
}, [storage, noteId, unbookmarkNote])
129108

130109
const selectEditMode = useCallback(() => {
131110
setGeneralStatus({
@@ -191,7 +170,7 @@ const Application = ({
191170

192171
useEffect(() => {
193172
const handler = () => {
194-
if (note == null) {
173+
if (note == null || storage == null) {
195174
return
196175
}
197176
showSaveDialog({
@@ -283,7 +262,7 @@ const Application = ({
283262
preferences,
284263
previewStyle,
285264
pushMessage,
286-
storage.attachmentMap,
265+
storage,
287266
])
288267

289268
const toggleBookmark = useCallback(() => {
@@ -306,12 +285,12 @@ const Application = ({
306285

307286
return (
308287
<>
309-
{showSearchModal && <SearchModal storage={storage} />}
288+
{storage != null && showSearchModal && <SearchModal storage={storage} />}
310289
<ApplicationLayout
311290
sidebar={
312291
<NoteStorageNavigator
313-
storage={storage}
314292
initialSidebarState={initialSidebarState}
293+
storage={storage}
315294
/>
316295
}
317296
pageBody={

src/components/atoms/BoostHubWebview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
NewWindowEvent,
1919
} from 'electron'
2020
import { useEffectOnce } from 'react-use'
21-
import styled from '../../lib/styled'
2221
import { openNew } from '../../lib/platform'
2322
import {
2423
boostHubNavigateRequestEventEmitter,
@@ -33,6 +32,7 @@ import {
3332
import { usePreferences } from '../../lib/preferences'
3433
import { openContextMenu } from '../../lib/electronOnly'
3534
import { DidFailLoadEvent } from 'electron/main'
35+
import styled from '../../shared/lib/styled'
3636

3737
export interface WebviewControl {
3838
focus(): void

src/components/atoms/FolderDetailListItemControlButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { MouseEventHandler } from 'react'
2-
import Icon from './Icon'
32
import styled from '../../shared/lib/styled'
3+
import Icon from '../../shared/components/atoms/Icon'
44

55
interface FolderDetailListItemControlButtonProps {
66
onClick?: MouseEventHandler<HTMLButtonElement>

src/components/atoms/FormFolderSelector.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React, { useCallback, useState, CSSProperties } from 'react'
22
import { useTranslation } from 'react-i18next'
3-
import styled from '../../lib/styled'
4-
import { border, secondaryButtonStyle } from '../../lib/styled/styleFunctions'
53
import { getPathByName, showOpenDialog } from '../../lib/electronOnly'
4+
import styled from '../../shared/lib/styled'
5+
import {
6+
border,
7+
secondaryButtonStyle,
8+
} from '../../shared/lib/styled/styleFunctions'
69

710
const FormFolderSelectorInput = styled.input`
811
display: block;
@@ -11,7 +14,7 @@ const FormFolderSelectorInput = styled.input`
1114
line-height: 1.5;
1215
border-top-left-radius: 0.25rem;
1316
border-bottom-left-radius: 0.25rem;
14-
${border}
17+
${border};
1518
background-color: white;
1619
cursor: pointer;
1720
&:disabled {
@@ -25,8 +28,8 @@ const FormFolderSelectorContainer = styled.div`
2528
`
2629

2730
const FormFolderSelectorButton = styled.button`
28-
${secondaryButtonStyle}
29-
padding: .375rem .75rem;
31+
${secondaryButtonStyle};
32+
padding: 0.375rem 0.75rem;
3033
font-size: 1rem;
3134
line-height: 1.5;
3235
border-top-right-radius: 0.25rem;

src/components/atoms/markdown/CodeFence.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
22
import copy from 'copy-to-clipboard'
3-
import Icon from '../Icon'
43
import { mdiContentCopy, mdiContentSave } from '@mdi/js'
54
import { flexCenter } from '../../../lib/styled/styleFunctions'
65
import { downloadBlob } from '../../../lib/download'
76
import styled from '../../../shared/lib/styled'
7+
import Icon from '../../../shared/components/atoms/Icon'
88

99
const CodeFenceContainer = styled.div`
1010
position: relative;

src/components/atoms/search/LocalSearchButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
2-
import Icon from '../Icon'
32
import styled from '../../../shared/lib/styled'
3+
import Icon from '../../../shared/components/atoms/Icon'
44

55
interface LocalSearchButtonProps {
66
title?: string
@@ -24,7 +24,7 @@ const LocalSearchButton = ({
2424
className={className}
2525
onClick={onClick}
2626
>
27-
<Icon path={iconPath} />
27+
<Icon size={16} path={iconPath} />
2828
</LocalSearchStyledButton>
2929
)
3030
}

src/components/atoms/search/SearchResultItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from '../../../lib/styled/styled'
1+
import styled from '../../../shared/lib/styled'
22

33
export const SearchResultItem = styled.div`
44
display: flex;

src/components/molecules/NotePageToolbarNoteHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const NotePageToolbarNoteHeader = ({
251251
export default NotePageToolbarNoteHeader
252252

253253
const TitleInput = styled.input`
254-
${inputStyle}
254+
${inputStyle};
255255
flex: 1;
256256
margin: 0 5px;
257257
display: block;
@@ -284,7 +284,7 @@ const NoteTitleButtonContainer = styled.button`
284284
outline: none;
285285
286286
background-color: transparent;
287-
${flexCenter}
287+
${flexCenter};
288288
overflow: hidden;
289289
290290
border: none;

0 commit comments

Comments
 (0)