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

Commit

Permalink
fix(delete draft when empty the wrong way
Browse files Browse the repository at this point in the history
  • Loading branch information
horacioh committed Mar 4, 2024
1 parent aed307a commit 9b4b37a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
21 changes: 1 addition & 20 deletions frontend/packages/app/models/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {ContextFrom, fromPromise} from 'xstate'
import {useGRPCClient} from '../app-context'
import {useNavRoute} from '../utils/navigation'
import {pathNameify} from '../utils/path'
import {DraftRoute, NavRoute} from '../utils/routes'
import {NavRoute} from '../utils/routes'
import {useNavigate} from '../utils/useNavigate'
import {useAllAccounts} from './accounts'
import {DraftStatusContext, draftMachine} from './draft-machine'
Expand Down Expand Up @@ -668,15 +668,6 @@ export function useDraftEditor({

const gwUrl = useGatewayUrlStream()

useEffect(() => {
return () => {
if (!gotEdited.current && backendDraft.data?.children.length == 0) {
// this means the draft was not edited
deleteDraft.mutate((route as DraftRoute).draftId!)
}
}
}, [backendDraft.data])

// create editor
const editor = useBlockNote<typeof hmBlockSchema>({
onEditorContentChange(editor: BlockNoteEditor<typeof hmBlockSchema>) {
Expand Down Expand Up @@ -851,16 +842,6 @@ export const findBlock = findParentNode(
(node) => node.type.name === 'blockContainer',
)

function generateBlockId(length: number = 8): string {
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let result = ''
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length))
}
return result
}

export function useDocTextContent(pub?: HMPublication) {
return useMemo(() => {
let res = ''
Expand Down
12 changes: 12 additions & 0 deletions frontend/packages/app/models/draft-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const draftMachine = createMachine(
title: '',
errorMessage: '',
restoreTries: 0,
changed: false,
},
id: 'Draft',
initial: 'fetching',
Expand Down Expand Up @@ -117,6 +118,9 @@ export const draftMachine = createMachine(
{
type: 'indicatorChange',
},
{
type: 'setchanged',
},
],
after: {
autosaveTimeout: {
Expand Down Expand Up @@ -273,6 +277,7 @@ export const draftMachine = createMachine(
title: string
errorMessage: string
restoreTries: number
changed: boolean
},
},
},
Expand All @@ -284,6 +289,13 @@ export const draftMachine = createMachine(
resetChangeWhileSaving: assign({
hasChangedWhileSaving: false,
}),
setchanged: assign({
changed: ({context}) => {
if (!context.changed) {
return true
}
},
}),
setCurrentBlocksmap: assign({
// @ts-expect-error
blocksMap: ({context, event}) => {
Expand Down

0 comments on commit 9b4b37a

Please sign in to comment.