Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial welcome note #48

Merged
merged 1 commit into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ For more info on features and upcoming changes, please visit our [Open Issues](h

## [0.23.0] - 2021-10-20

### TBA
### Added

- The welcome note on space creation or import

### Fixed

- Space navigation on space remove (defaults to first available space)

## [Released]

## [0.22.3] - 2021-09-18
## [0.22.3] - 2021-09-24

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ const App = () => {
const spaceCount = size(storageMap)
if (index >= spaceCount) {
pushMessage({
title: 'No such storage.',
title: 'No such space.',
description: `You selected ${index + 1}${
index == 0 ? 'st' : index == 1 ? 'nd' : 'th'
} space but only ${spaceCount} space${spaceCount == 1 ? '' : 's'} ${
spaceCount > 1 ? 'are' : 'is'
} available. Please add more storages or switch to existing ones. `,
} available. Please add more spaces or switch to existing ones. `,
})
} else {
navigateToStorage(targetStorageId)
Expand Down
9 changes: 7 additions & 2 deletions src/lib/db/FSNoteDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
unlinkFile,
} from '../electronOnly'
import { removeDuplicates } from '../../shared/lib/utils/array'
import { welcomeNote } from '../templates/welcomeNote'

interface StorageJSONData {
folderMap: ObjectMap<FolderDoc>
Expand All @@ -60,7 +61,7 @@ class FSNoteDb implements NoteDb {
this.location = location
}

async init(): Promise<void> {
async init(newStorage?: boolean): Promise<void> {
await prepareDirectory(this.location)
await prepareDirectory(this.getNotesFolderPathname())
await prepareDirectory(this.getAttachmentsFolderPathname())
Expand All @@ -82,6 +83,10 @@ class FSNoteDb implements NoteDb {
})
}

if (newStorage) {
notes.push(await this.createNote(welcomeNote))
}

await Promise.all([
...[...missingFolderPathnameSet].map((pathname) =>
this.upsertFolder(pathname)
Expand All @@ -97,7 +102,7 @@ class FSNoteDb implements NoteDb {
anyFolderDocUpdated = true
}
})
if (anyFolderDocUpdated) {
if (anyFolderDocUpdated || newStorage) {
await this.saveBoostNoteJSON()
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/lib/db/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ export function createDbStoreCreator(

const storageData = { id, name }

const storage = await prepareStorage({
...storageData,
...props,
})
const storage = await prepareStorage(
{
...storageData,
...props,
},
true
)

let newStorageMap: ObjectMap<NoteStorage> = {}
setStorageMap((prevStorageMap) => {
Expand Down Expand Up @@ -1347,11 +1350,12 @@ function saveStorageDataList(
}

async function prepareStorage(
storageData: NoteStorageData
storageData: NoteStorageData,
newStorage?: boolean
): Promise<NoteStorage> {
const { id, name } = storageData
const db = new FSNoteDb(id, name, storageData.location)
await db.init()
await db.init(newStorage)

const foldersToUpdateOrderedIds: string[] = []

Expand Down
24 changes: 24 additions & 0 deletions src/lib/templates/welcomeNote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NoteDocEditibleProps, NoteDocImportableProps } from '../db/types'

const noteContent = [
'# Welcome to Boost Note Local',
'',
'## Here are few helpful links to get you started',
'',
'- [About](https://github.com/BoostIO/BoostNote.next-local/wiki/About)',
'',
'- [Keymap](https://github.com/BoostIO/BoostNote.next-local/wiki/Keyboard-Shortcuts)',
'',
'- [Discussions](https://github.com/BoostIO/BoostNote.next-local/discussions)',
'',
'- [Q&A](https://github.com/BoostIO/BoostNote.next-local/discussions/categories/q-a)',
'',
]

export const welcomeNote: Partial<
NoteDocEditibleProps | NoteDocImportableProps
> = {
title: 'Welcome',
content: noteContent.join('\n'),
folderPathname: '/',
}
7 changes: 4 additions & 3 deletions src/lib/v2/hooks/local/useLocalUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ export function useLocalUI() {
{
variant: 'warning',
label: t('storage.remove'),
onClick: () => {
removeStorage(workspace.id)
onClick: async () => {
await removeStorage(workspace.id)
push('/')
},
},
{
Expand All @@ -316,7 +317,7 @@ export function useLocalUI() {
],
})
},
[messageBox, removeStorage, t]
[messageBox, push, removeStorage, t]
)

const deleteFolder = useCallback(
Expand Down