fix: remove redundant note detail props

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-15 21:29:28 +02:00
parent cdfcd325a1
commit 77f858bff8
13 changed files with 12 additions and 49 deletions

View file

@ -16,8 +16,6 @@ const testFrontmatter: NoteFrontmatter = {
lang: 'en', lang: 'en',
dir: NoteTextDirection.LTR, dir: NoteTextDirection.LTR,
newlinesAreBreaks: true, newlinesAreBreaks: true,
GA: '',
disqus: '',
license: '', license: '',
type: NoteType.DOCUMENT, type: NoteType.DOCUMENT,
opengraph: {}, opengraph: {},

View file

@ -27,8 +27,6 @@ export interface NoteFrontmatter {
lang: Iso6391Language lang: Iso6391Language
dir: NoteTextDirection dir: NoteTextDirection
newlinesAreBreaks: boolean newlinesAreBreaks: boolean
GA: string
disqus: string
license: string license: string
type: NoteType type: NoteType
opengraph: OpenGraph opengraph: OpenGraph

View file

@ -45,7 +45,7 @@ export const useOnImageUploadFromRenderer = (): void => {
const file = new File([blob], fileName, { type: blob.type }) const file = new File([blob], fileName, { type: blob.type })
const { cursorSelection, alt, title } = Optional.ofNullable(lineIndex) const { cursorSelection, alt, title } = Optional.ofNullable(lineIndex)
.flatMap((actualLineIndex) => { .flatMap((actualLineIndex) => {
const lineOffset = getGlobalState().noteDetails.frontmatterRendererInfo.lineOffset const lineOffset = getGlobalState().noteDetails.startOfContentLineOffset
return findPlaceholderInMarkdownContent(actualLineIndex + lineOffset, placeholderIndexInLine) return findPlaceholderInMarkdownContent(actualLineIndex + lineOffset, placeholderIndexInLine)
}) })
.orElse({} as ExtractResult) .orElse({} as ExtractResult)

View file

@ -21,8 +21,7 @@ export const useOnScrollWithLineOffset = (onScroll: ScrollCallback | undefined):
} else { } else {
return (scrollState: ScrollState) => { return (scrollState: ScrollState) => {
onScroll({ onScroll({
firstLineInView: firstLineInView: scrollState.firstLineInView + getGlobalState().noteDetails.startOfContentLineOffset,
scrollState.firstLineInView + getGlobalState().noteDetails.frontmatterRendererInfo.lineOffset,
scrolledPercentage: scrollState.scrolledPercentage scrolledPercentage: scrollState.scrolledPercentage
}) })
} }

View file

@ -14,7 +14,7 @@ import { useMemo } from 'react'
* @return the adjusted scroll state without the line offset * @return the adjusted scroll state without the line offset
*/ */
export const useScrollStateWithoutLineOffset = (scrollState: ScrollState | undefined): ScrollState | undefined => { export const useScrollStateWithoutLineOffset = (scrollState: ScrollState | undefined): ScrollState | undefined => {
const lineOffset = useApplicationState((state) => state.noteDetails.frontmatterRendererInfo.lineOffset) const lineOffset = useApplicationState((state) => state.noteDetails.startOfContentLineOffset)
return useMemo(() => { return useMemo(() => {
return scrollState === undefined return scrollState === undefined
? undefined ? undefined

View file

@ -32,7 +32,7 @@ export const useSetCheckboxInEditor = () => {
return useCallback( return useCallback(
({ lineInMarkdown, newCheckedState }: TaskCheckedEventPayload): void => { ({ lineInMarkdown, newCheckedState }: TaskCheckedEventPayload): void => {
changeEditorContent?.(({ markdownContent }) => { changeEditorContent?.(({ markdownContent }) => {
const correctedLineIndex = lineInMarkdown + store.getState().noteDetails.frontmatterRendererInfo.lineOffset const correctedLineIndex = lineInMarkdown + store.getState().noteDetails.startOfContentLineOffset
const edits = findCheckBox(markdownContent, correctedLineIndex) const edits = findCheckBox(markdownContent, correctedLineIndex)
.map(([startIndex, endIndex]) => createCheckboxContentEdit(startIndex, endIndex, newCheckedState)) .map(([startIndex, endIndex]) => createCheckboxContentEdit(startIndex, endIndex, newCheckedState))
.orElse([]) .orElse([])

View file

@ -18,7 +18,7 @@ export const useTrimmedNoteMarkdownContentWithoutFrontmatter = (): string[] => {
lines: state.noteDetails.markdownContent.lines, lines: state.noteDetails.markdownContent.lines,
content: state.noteDetails.markdownContent.plain content: state.noteDetails.markdownContent.plain
})) }))
const lineOffset = useApplicationState((state) => state.noteDetails.frontmatterRendererInfo.lineOffset) const lineOffset = useApplicationState((state) => state.noteDetails.startOfContentLineOffset)
const trimmedLines = useMemo(() => { const trimmedLines = useMemo(() => {
if (markdownContent.content.length > maxLength) { if (markdownContent.content.length > maxLength) {

View file

@ -60,10 +60,10 @@ const buildStateFromMarkdownContentAndLines = (
lines: markdownContentLines, lines: markdownContentLines,
lineStartIndexes lineStartIndexes
}, },
startOfContentLineOffset: 0,
rawFrontmatter: '', rawFrontmatter: '',
title: generateNoteTitle(initialState.frontmatter, state.firstHeading), title: generateNoteTitle(initialState.frontmatter, state.firstHeading),
frontmatter: initialState.frontmatter, frontmatter: initialState.frontmatter
frontmatterRendererInfo: initialState.frontmatterRendererInfo
} }
} }
} }
@ -88,11 +88,7 @@ const buildStateFromFrontmatterUpdate = (
rawFrontmatter: frontmatterExtraction.rawText, rawFrontmatter: frontmatterExtraction.rawText,
frontmatter: frontmatter, frontmatter: frontmatter,
title: generateNoteTitle(frontmatter, state.firstHeading), title: generateNoteTitle(frontmatter, state.firstHeading),
frontmatterRendererInfo: { startOfContentLineOffset: frontmatterExtraction.lineOffset
lineOffset: frontmatterExtraction.lineOffset,
frontmatterInvalid: false,
slideOptions: frontmatter.slideOptions
}
} }
} catch (e) { } catch (e) {
return { return {
@ -100,11 +96,7 @@ const buildStateFromFrontmatterUpdate = (
title: generateNoteTitle(initialState.frontmatter, state.firstHeading), title: generateNoteTitle(initialState.frontmatter, state.firstHeading),
rawFrontmatter: frontmatterExtraction.rawText, rawFrontmatter: frontmatterExtraction.rawText,
frontmatter: initialState.frontmatter, frontmatter: initialState.frontmatter,
frontmatterRendererInfo: { startOfContentLineOffset: frontmatterExtraction.lineOffset
lineOffset: frontmatterExtraction.lineOffset,
frontmatterInvalid: true,
slideOptions: initialState.frontmatterRendererInfo.slideOptions
}
} }
} }
} }

View file

@ -25,11 +25,7 @@ export const initialState: NoteDetails = {
}, },
selection: { from: 0 }, selection: { from: 0 },
rawFrontmatter: '', rawFrontmatter: '',
frontmatterRendererInfo: { startOfContentLineOffset: 0,
frontmatterInvalid: false,
lineOffset: 0,
slideOptions: initialSlideOptions
},
id: '', id: '',
createdAt: 0, createdAt: 0,
updatedAt: 0, updatedAt: 0,
@ -52,8 +48,6 @@ export const initialState: NoteDetails = {
lang: 'en', lang: 'en',
dir: NoteTextDirection.LTR, dir: NoteTextDirection.LTR,
newlinesAreBreaks: true, newlinesAreBreaks: true,
GA: '',
disqus: '',
license: '', license: '',
type: NoteType.DOCUMENT, type: NoteType.DOCUMENT,
opengraph: {}, opengraph: {},

View file

@ -39,8 +39,6 @@ const parseRawNoteFrontmatter = (rawData: RawNoteFrontmatter): NoteFrontmatter =
description: rawData.description ?? initialState.frontmatter.description, description: rawData.description ?? initialState.frontmatter.description,
robots: rawData.robots ?? initialState.frontmatter.robots, robots: rawData.robots ?? initialState.frontmatter.robots,
newlinesAreBreaks: parseBoolean(rawData.breaks) ?? initialState.frontmatter.newlinesAreBreaks, newlinesAreBreaks: parseBoolean(rawData.breaks) ?? initialState.frontmatter.newlinesAreBreaks,
GA: rawData.GA ?? initialState.frontmatter.GA,
disqus: rawData.disqus ?? initialState.frontmatter.disqus,
lang: parseLanguage(rawData), lang: parseLanguage(rawData),
type: parseNoteType(rawData), type: parseNoteType(rawData),
dir: parseTextDirection(rawData), dir: parseTextDirection(rawData),

View file

@ -12,8 +12,6 @@ export interface RawNoteFrontmatter {
lang: string | undefined lang: string | undefined
dir: string | undefined dir: string | undefined
breaks: boolean | undefined breaks: boolean | undefined
GA: string | undefined
disqus: string | undefined
license: string | undefined license: string | undefined
type: string | undefined type: string | undefined
slideOptions: { [key: string]: string } | null slideOptions: { [key: string]: string } | null

View file

@ -5,7 +5,6 @@
*/ */
import type { Note } from '../../../api/notes/types' import type { Note } from '../../../api/notes/types'
import * as buildStateFromUpdatedMarkdownContentModule from '../build-state-from-updated-markdown-content' import * as buildStateFromUpdatedMarkdownContentModule from '../build-state-from-updated-markdown-content'
import { initialSlideOptions } from '../initial-state'
import type { NoteDetails } from '../types/note-details' import type { NoteDetails } from '../types/note-details'
import { buildStateFromServerDto } from './build-state-from-set-note-data-from-server' import { buildStateFromServerDto } from './build-state-from-set-note-data-from-server'
import { NoteTextDirection, NoteType } from '@hedgedoc/commons' import { NoteTextDirection, NoteType } from '@hedgedoc/commons'
@ -88,8 +87,6 @@ describe('build state from set note data from server', () => {
license: '', license: '',
dir: NoteTextDirection.LTR, dir: NoteTextDirection.LTR,
newlinesAreBreaks: true, newlinesAreBreaks: true,
GA: '',
disqus: '',
type: NoteType.DOCUMENT, type: NoteType.DOCUMENT,
opengraph: {}, opengraph: {},
slideOptions: { slideOptions: {
@ -100,11 +97,7 @@ describe('build state from set note data from server', () => {
slideNumber: false slideNumber: false
} }
}, },
frontmatterRendererInfo: { startOfContentLineOffset: 0,
frontmatterInvalid: false,
lineOffset: 0,
slideOptions: initialSlideOptions
},
title: 'title', title: 'title',
selection: { from: 0 }, selection: { from: 0 },
markdownContent: { markdownContent: {

View file

@ -5,7 +5,6 @@
*/ */
import type { NoteMetadata } from '../../../api/notes/types' import type { NoteMetadata } from '../../../api/notes/types'
import type { CursorSelection } from '../../../components/editor-page/editor-pane/tool-bar/formatters/types/cursor-selection' import type { CursorSelection } from '../../../components/editor-page/editor-pane/tool-bar/formatters/types/cursor-selection'
import type { SlideOptions } from '@hedgedoc/commons'
import type { NoteFrontmatter } from '@hedgedoc/commons' import type { NoteFrontmatter } from '@hedgedoc/commons'
type UnnecessaryNoteAttributes = 'updatedAt' | 'createdAt' | 'tags' | 'description' type UnnecessaryNoteAttributes = 'updatedAt' | 'createdAt' | 'tags' | 'description'
@ -25,11 +24,5 @@ export interface NoteDetails extends Omit<NoteMetadata, UnnecessaryNoteAttribute
firstHeading?: string firstHeading?: string
rawFrontmatter: string rawFrontmatter: string
frontmatter: NoteFrontmatter frontmatter: NoteFrontmatter
frontmatterRendererInfo: RendererFrontmatterInfo startOfContentLineOffset: number
}
export interface RendererFrontmatterInfo {
lineOffset: number
frontmatterInvalid: boolean
slideOptions: SlideOptions
} }