mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 10:46:30 -05:00
fix: remove redundant note detail props
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
cdfcd325a1
commit
77f858bff8
13 changed files with 12 additions and 49 deletions
|
@ -16,8 +16,6 @@ const testFrontmatter: NoteFrontmatter = {
|
|||
lang: 'en',
|
||||
dir: NoteTextDirection.LTR,
|
||||
newlinesAreBreaks: true,
|
||||
GA: '',
|
||||
disqus: '',
|
||||
license: '',
|
||||
type: NoteType.DOCUMENT,
|
||||
opengraph: {},
|
||||
|
|
|
@ -27,8 +27,6 @@ export interface NoteFrontmatter {
|
|||
lang: Iso6391Language
|
||||
dir: NoteTextDirection
|
||||
newlinesAreBreaks: boolean
|
||||
GA: string
|
||||
disqus: string
|
||||
license: string
|
||||
type: NoteType
|
||||
opengraph: OpenGraph
|
||||
|
|
|
@ -45,7 +45,7 @@ export const useOnImageUploadFromRenderer = (): void => {
|
|||
const file = new File([blob], fileName, { type: blob.type })
|
||||
const { cursorSelection, alt, title } = Optional.ofNullable(lineIndex)
|
||||
.flatMap((actualLineIndex) => {
|
||||
const lineOffset = getGlobalState().noteDetails.frontmatterRendererInfo.lineOffset
|
||||
const lineOffset = getGlobalState().noteDetails.startOfContentLineOffset
|
||||
return findPlaceholderInMarkdownContent(actualLineIndex + lineOffset, placeholderIndexInLine)
|
||||
})
|
||||
.orElse({} as ExtractResult)
|
||||
|
|
|
@ -21,8 +21,7 @@ export const useOnScrollWithLineOffset = (onScroll: ScrollCallback | undefined):
|
|||
} else {
|
||||
return (scrollState: ScrollState) => {
|
||||
onScroll({
|
||||
firstLineInView:
|
||||
scrollState.firstLineInView + getGlobalState().noteDetails.frontmatterRendererInfo.lineOffset,
|
||||
firstLineInView: scrollState.firstLineInView + getGlobalState().noteDetails.startOfContentLineOffset,
|
||||
scrolledPercentage: scrollState.scrolledPercentage
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import { useMemo } from 'react'
|
|||
* @return the adjusted scroll state without the line offset
|
||||
*/
|
||||
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 scrollState === undefined
|
||||
? undefined
|
||||
|
|
|
@ -32,7 +32,7 @@ export const useSetCheckboxInEditor = () => {
|
|||
return useCallback(
|
||||
({ lineInMarkdown, newCheckedState }: TaskCheckedEventPayload): void => {
|
||||
changeEditorContent?.(({ markdownContent }) => {
|
||||
const correctedLineIndex = lineInMarkdown + store.getState().noteDetails.frontmatterRendererInfo.lineOffset
|
||||
const correctedLineIndex = lineInMarkdown + store.getState().noteDetails.startOfContentLineOffset
|
||||
const edits = findCheckBox(markdownContent, correctedLineIndex)
|
||||
.map(([startIndex, endIndex]) => createCheckboxContentEdit(startIndex, endIndex, newCheckedState))
|
||||
.orElse([])
|
||||
|
|
|
@ -18,7 +18,7 @@ export const useTrimmedNoteMarkdownContentWithoutFrontmatter = (): string[] => {
|
|||
lines: state.noteDetails.markdownContent.lines,
|
||||
content: state.noteDetails.markdownContent.plain
|
||||
}))
|
||||
const lineOffset = useApplicationState((state) => state.noteDetails.frontmatterRendererInfo.lineOffset)
|
||||
const lineOffset = useApplicationState((state) => state.noteDetails.startOfContentLineOffset)
|
||||
|
||||
const trimmedLines = useMemo(() => {
|
||||
if (markdownContent.content.length > maxLength) {
|
||||
|
|
|
@ -60,10 +60,10 @@ const buildStateFromMarkdownContentAndLines = (
|
|||
lines: markdownContentLines,
|
||||
lineStartIndexes
|
||||
},
|
||||
startOfContentLineOffset: 0,
|
||||
rawFrontmatter: '',
|
||||
title: generateNoteTitle(initialState.frontmatter, state.firstHeading),
|
||||
frontmatter: initialState.frontmatter,
|
||||
frontmatterRendererInfo: initialState.frontmatterRendererInfo
|
||||
frontmatter: initialState.frontmatter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,11 +88,7 @@ const buildStateFromFrontmatterUpdate = (
|
|||
rawFrontmatter: frontmatterExtraction.rawText,
|
||||
frontmatter: frontmatter,
|
||||
title: generateNoteTitle(frontmatter, state.firstHeading),
|
||||
frontmatterRendererInfo: {
|
||||
lineOffset: frontmatterExtraction.lineOffset,
|
||||
frontmatterInvalid: false,
|
||||
slideOptions: frontmatter.slideOptions
|
||||
}
|
||||
startOfContentLineOffset: frontmatterExtraction.lineOffset
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
|
@ -100,11 +96,7 @@ const buildStateFromFrontmatterUpdate = (
|
|||
title: generateNoteTitle(initialState.frontmatter, state.firstHeading),
|
||||
rawFrontmatter: frontmatterExtraction.rawText,
|
||||
frontmatter: initialState.frontmatter,
|
||||
frontmatterRendererInfo: {
|
||||
lineOffset: frontmatterExtraction.lineOffset,
|
||||
frontmatterInvalid: true,
|
||||
slideOptions: initialState.frontmatterRendererInfo.slideOptions
|
||||
}
|
||||
startOfContentLineOffset: frontmatterExtraction.lineOffset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,7 @@ export const initialState: NoteDetails = {
|
|||
},
|
||||
selection: { from: 0 },
|
||||
rawFrontmatter: '',
|
||||
frontmatterRendererInfo: {
|
||||
frontmatterInvalid: false,
|
||||
lineOffset: 0,
|
||||
slideOptions: initialSlideOptions
|
||||
},
|
||||
startOfContentLineOffset: 0,
|
||||
id: '',
|
||||
createdAt: 0,
|
||||
updatedAt: 0,
|
||||
|
@ -52,8 +48,6 @@ export const initialState: NoteDetails = {
|
|||
lang: 'en',
|
||||
dir: NoteTextDirection.LTR,
|
||||
newlinesAreBreaks: true,
|
||||
GA: '',
|
||||
disqus: '',
|
||||
license: '',
|
||||
type: NoteType.DOCUMENT,
|
||||
opengraph: {},
|
||||
|
|
|
@ -39,8 +39,6 @@ const parseRawNoteFrontmatter = (rawData: RawNoteFrontmatter): NoteFrontmatter =
|
|||
description: rawData.description ?? initialState.frontmatter.description,
|
||||
robots: rawData.robots ?? initialState.frontmatter.robots,
|
||||
newlinesAreBreaks: parseBoolean(rawData.breaks) ?? initialState.frontmatter.newlinesAreBreaks,
|
||||
GA: rawData.GA ?? initialState.frontmatter.GA,
|
||||
disqus: rawData.disqus ?? initialState.frontmatter.disqus,
|
||||
lang: parseLanguage(rawData),
|
||||
type: parseNoteType(rawData),
|
||||
dir: parseTextDirection(rawData),
|
||||
|
|
|
@ -12,8 +12,6 @@ export interface RawNoteFrontmatter {
|
|||
lang: string | undefined
|
||||
dir: string | undefined
|
||||
breaks: boolean | undefined
|
||||
GA: string | undefined
|
||||
disqus: string | undefined
|
||||
license: string | undefined
|
||||
type: string | undefined
|
||||
slideOptions: { [key: string]: string } | null
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
import type { Note } from '../../../api/notes/types'
|
||||
import * as buildStateFromUpdatedMarkdownContentModule from '../build-state-from-updated-markdown-content'
|
||||
import { initialSlideOptions } from '../initial-state'
|
||||
import type { NoteDetails } from '../types/note-details'
|
||||
import { buildStateFromServerDto } from './build-state-from-set-note-data-from-server'
|
||||
import { NoteTextDirection, NoteType } from '@hedgedoc/commons'
|
||||
|
@ -88,8 +87,6 @@ describe('build state from set note data from server', () => {
|
|||
license: '',
|
||||
dir: NoteTextDirection.LTR,
|
||||
newlinesAreBreaks: true,
|
||||
GA: '',
|
||||
disqus: '',
|
||||
type: NoteType.DOCUMENT,
|
||||
opengraph: {},
|
||||
slideOptions: {
|
||||
|
@ -100,11 +97,7 @@ describe('build state from set note data from server', () => {
|
|||
slideNumber: false
|
||||
}
|
||||
},
|
||||
frontmatterRendererInfo: {
|
||||
frontmatterInvalid: false,
|
||||
lineOffset: 0,
|
||||
slideOptions: initialSlideOptions
|
||||
},
|
||||
startOfContentLineOffset: 0,
|
||||
title: 'title',
|
||||
selection: { from: 0 },
|
||||
markdownContent: {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
import type { NoteMetadata } from '../../../api/notes/types'
|
||||
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'
|
||||
|
||||
type UnnecessaryNoteAttributes = 'updatedAt' | 'createdAt' | 'tags' | 'description'
|
||||
|
@ -25,11 +24,5 @@ export interface NoteDetails extends Omit<NoteMetadata, UnnecessaryNoteAttribute
|
|||
firstHeading?: string
|
||||
rawFrontmatter: string
|
||||
frontmatter: NoteFrontmatter
|
||||
frontmatterRendererInfo: RendererFrontmatterInfo
|
||||
}
|
||||
|
||||
export interface RendererFrontmatterInfo {
|
||||
lineOffset: number
|
||||
frontmatterInvalid: boolean
|
||||
slideOptions: SlideOptions
|
||||
startOfContentLineOffset: number
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue