Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
File > New Document plus keyboard shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Sep 15, 2023
1 parent 3a20551 commit 5613cef
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 31 deletions.
14 changes: 7 additions & 7 deletions frontend/apps/desktop/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ mainMenu.append(
new MenuItem({
role: 'fileMenu',
submenu: [
// {
// label: 'New Document',
// accelerator: 'CmdOrCtrl+n',
// click: () => {
// // todo
// },
// },
{
label: 'New Document',
accelerator: 'CmdOrCtrl+n',
click: () => {
trpc.createAppWindow({routes: [{key: 'draft'}]})
},
},
{
label: 'New Window',
accelerator: 'CmdOrCtrl+Shift+n',
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/app/src/components/titlebar/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ function NewDocumentButton() {
onPress={(e) => {
e.preventDefault()
const pubContext = getRoutePubContext(route)
// @ts-ignore
openDraft(!e.shiftKey, pubContext)
openDraft(pubContext)
}}
/>
</Tooltip>
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/app/src/models/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {useGRPCClient} from '../app-context'
import {PublicationRouteContext, useNavRoute} from '../utils/navigation'
import {usePublicationInContext} from './publication'
import {queryKeys} from './query-keys'
import {pathNameify} from '../utils/path'

export type HMBlock = Block<typeof hmBlockSchema>
export type HMPartialBlock = PartialBlock<typeof hmBlockSchema>
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/app/src/pages/draft-list-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {queryDraft} from '../models/documents'
export default function DraftList() {
let drafts = useDraftList()
// TODO: add a `isFetching` indicator
const openDraft = useOpenDraft()
const openDraft = useOpenDraft('push')

if (drafts.data) {
return (
Expand All @@ -49,7 +49,7 @@ export default function DraftList() {
<EmptyList
description="You have no current Drafts."
action={() => {
openDraft(false)
openDraft()
}}
/>
)}
Expand Down
10 changes: 8 additions & 2 deletions frontend/packages/app/src/pages/draft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ import {
Theme,
YStack,
} from '@mintter/ui'
import {useState} from 'react'
import {useEffect, useState} from 'react'
import {ErrorBoundary, FallbackProps} from 'react-error-boundary'
import {DocumentPlaceholder} from './document-placeholder'
import {useOpenDraft} from '../utils/open-draft'

export default function DraftPage() {
let route = useNavRoute()
if (route.key != 'draft')
throw new Error('Draft actor must be passed to DraftPage')

const openDraft = useOpenDraft('replace')
const [debugValue, setDebugValue] = useState(false)
const documentId = route.draftId // TODO, clean this up when draftId != docId

useEffect(() => {
if (route.key === 'draft' && route.draftId === undefined) {
openDraft()
}
}, [route])
const {editor, query} = useDraftEditor(documentId, {
onEditorState: setDebugValue,
})
Expand Down
10 changes: 7 additions & 3 deletions frontend/packages/app/src/pages/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ function InviteMemberDialog({
<>
<Form
onSubmit={() => {
const normalized = normalizeAccountId(memberId)
if (!normalized) {
toast.error('Invalid account ID')
return
}
addMember
.mutateAsync({
groupId: input.groupId,
newMemberAccount: normalizeAccountId(memberId),
newMemberAccount: normalized,
})
.then(() => {
onClose()
Expand All @@ -203,7 +208,7 @@ function InviteMemberDialog({
<Label>Account Id</Label>
<Input value={memberId} onChangeText={setMemberId} />
<DialogDescription>
Search for xmember alias, or paste member ID
Search for member alias, or paste member ID
</DialogDescription>
<Form.Trigger asChild>
<Button>Add Member</Button>
Expand Down Expand Up @@ -284,7 +289,6 @@ export default function GroupPage() {
size="$2"
onPress={() => {
openDraft(
false,
{groupId, pathName: '/', key: 'group'},
{pathName: '/'},
)
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/app/src/pages/publication-list-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function PublicationListPage({trustedOnly}: {trustedOnly: boolean}) {
let publications = usePublicationList({trustedOnly})
let drafts = useDraftList()
let {queryClient, grpcClient} = useAppContext()
let openDraft = useOpenDraft()
let openDraft = useOpenDraft('push')
const pubs = publications.data?.publications

const deleteDialog = useAppDialog(DeleteDocumentDialog, {isAlert: true})
Expand Down Expand Up @@ -92,7 +92,7 @@ export function PublicationListPage({trustedOnly}: {trustedOnly: boolean}) {
<EmptyList
description="You have no Publications yet."
action={() => {
openDraft(false)
openDraft()
}}
/>
</Container>
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/app/src/pages/site-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function SitePage() {
return 0
})
}, [data])
const openDraft = useOpenDraft()
const openDraft = useOpenDraft('push')
if (!host) throw new Error('Hostname not found for SitePage')

return (
Expand All @@ -69,7 +69,7 @@ export default function SitePage() {
<EmptyList
description={`Nothing published on ${host} yet.`}
action={() => {
openDraft(false)
openDraft()
}}
/>
) : null}
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/app/src/utils/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type PublicationRoute = {
export type DraftsRoute = {key: 'drafts'}
export type DraftRoute = {
key: 'draft'
draftId: string
draftId?: string
pubContext?: PublicationRouteContext
contextRoute?: NavRoute
}
Expand Down
14 changes: 4 additions & 10 deletions frontend/packages/app/src/utils/open-draft.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {queryKeys} from '@mintter/app/src/models/query-keys'
import {toast} from 'react-hot-toast'
import {DocumentChange, GRPCClient} from '@mintter/shared'
import {DraftRoute, useNavigate, useNavRoute} from './navigation'
import {DraftRoute, NavMode, useNavigate, useNavRoute} from './navigation'
import {useQueryInvalidator} from '@mintter/app/src/app-context'
import {useGRPCClient} from '../app-context'
import {PublicationRouteContext} from '@mintter/app/utils/navigation'
Expand All @@ -24,14 +24,12 @@ async function createDraft(
return doc.id
}

export function useOpenDraft() {
const navigate = useNavigate()
export function useOpenDraft(navigateMode: NavMode = 'spawn') {
const navigate = useNavigate(navigateMode)
const route = useNavRoute()
const spawn = useNavigate('spawn')
const invalidate = useQueryInvalidator()
const grpcClient = useGRPCClient()
function openNewDraft(
newWindow = true,
pubContext?: PublicationRouteContext | undefined,
opts?: {pathName?: string | null},
) {
Expand All @@ -51,11 +49,7 @@ export function useOpenDraft() {
contextRoute: route,
}
invalidate([queryKeys.GET_DRAFT_LIST])
if (newWindow) {
spawn(draftRoute)
} else {
navigate(draftRoute)
}
navigate(draftRoute)
})
.catch((err) => {
console.error(err)
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/shared/src/utils/entity-id-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ParsedURL = {
}

export function parseCustomURL(url: string): ParsedURL | null {
if (!url) return null
const [scheme, rest] = url.split('://')
if (!rest) return null
const [pathAndQuery, fragment] = rest.split('#')
Expand Down

0 comments on commit 5613cef

Please sign in to comment.