From 77f858bff8a6438de65bf88c4d9eca7ba7fdcd15 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Mon, 15 May 2023 21:29:28 +0200 Subject: [PATCH] fix: remove redundant note detail props Signed-off-by: Tilman Vatteroth --- .../title-extraction/generate-note-title.spec.ts | 2 -- .../src/title-extraction/types/frontmatter.ts | 2 -- .../use-on-image-upload-from-renderer.ts | 2 +- .../hooks/use-on-scroll-with-line-offset.ts | 3 +-- .../use-scroll-state-without-line-offset.ts | 2 +- .../task-list/set-checkbox-in-editor.tsx | 2 +- ...-note-markdown-content-without-frontmatter.ts | 2 +- .../build-state-from-updated-markdown-content.ts | 16 ++++------------ frontend/src/redux/note-details/initial-state.ts | 8 +------- .../raw-note-frontmatter-parser/parser.ts | 2 -- .../raw-note-frontmatter-parser/types.d.ts | 2 -- ...-state-from-set-note-data-from-server.spec.ts | 9 +-------- .../src/redux/note-details/types/note-details.ts | 9 +-------- 13 files changed, 12 insertions(+), 49 deletions(-) diff --git a/commons/src/title-extraction/generate-note-title.spec.ts b/commons/src/title-extraction/generate-note-title.spec.ts index 12ee67fe4..7abb3ad12 100644 --- a/commons/src/title-extraction/generate-note-title.spec.ts +++ b/commons/src/title-extraction/generate-note-title.spec.ts @@ -16,8 +16,6 @@ const testFrontmatter: NoteFrontmatter = { lang: 'en', dir: NoteTextDirection.LTR, newlinesAreBreaks: true, - GA: '', - disqus: '', license: '', type: NoteType.DOCUMENT, opengraph: {}, diff --git a/commons/src/title-extraction/types/frontmatter.ts b/commons/src/title-extraction/types/frontmatter.ts index f20b507e7..adcc2bf35 100644 --- a/commons/src/title-extraction/types/frontmatter.ts +++ b/commons/src/title-extraction/types/frontmatter.ts @@ -27,8 +27,6 @@ export interface NoteFrontmatter { lang: Iso6391Language dir: NoteTextDirection newlinesAreBreaks: boolean - GA: string - disqus: string license: string type: NoteType opengraph: OpenGraph diff --git a/frontend/src/components/editor-page/editor-pane/hooks/image-upload-from-renderer/use-on-image-upload-from-renderer.ts b/frontend/src/components/editor-page/editor-pane/hooks/image-upload-from-renderer/use-on-image-upload-from-renderer.ts index a4d4c35c0..5c8cc2098 100644 --- a/frontend/src/components/editor-page/editor-pane/hooks/image-upload-from-renderer/use-on-image-upload-from-renderer.ts +++ b/frontend/src/components/editor-page/editor-pane/hooks/image-upload-from-renderer/use-on-image-upload-from-renderer.ts @@ -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) diff --git a/frontend/src/components/editor-page/renderer-pane/hooks/use-on-scroll-with-line-offset.ts b/frontend/src/components/editor-page/renderer-pane/hooks/use-on-scroll-with-line-offset.ts index a86ebacc1..201a29133 100644 --- a/frontend/src/components/editor-page/renderer-pane/hooks/use-on-scroll-with-line-offset.ts +++ b/frontend/src/components/editor-page/renderer-pane/hooks/use-on-scroll-with-line-offset.ts @@ -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 }) } diff --git a/frontend/src/components/editor-page/renderer-pane/hooks/use-scroll-state-without-line-offset.ts b/frontend/src/components/editor-page/renderer-pane/hooks/use-scroll-state-without-line-offset.ts index d9f192773..02647b2cf 100644 --- a/frontend/src/components/editor-page/renderer-pane/hooks/use-scroll-state-without-line-offset.ts +++ b/frontend/src/components/editor-page/renderer-pane/hooks/use-scroll-state-without-line-offset.ts @@ -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 diff --git a/frontend/src/extensions/essential-app-extensions/task-list/set-checkbox-in-editor.tsx b/frontend/src/extensions/essential-app-extensions/task-list/set-checkbox-in-editor.tsx index 92b4e96a3..979939188 100644 --- a/frontend/src/extensions/essential-app-extensions/task-list/set-checkbox-in-editor.tsx +++ b/frontend/src/extensions/essential-app-extensions/task-list/set-checkbox-in-editor.tsx @@ -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([]) diff --git a/frontend/src/hooks/common/use-trimmed-note-markdown-content-without-frontmatter.ts b/frontend/src/hooks/common/use-trimmed-note-markdown-content-without-frontmatter.ts index b38566126..26f27a21b 100644 --- a/frontend/src/hooks/common/use-trimmed-note-markdown-content-without-frontmatter.ts +++ b/frontend/src/hooks/common/use-trimmed-note-markdown-content-without-frontmatter.ts @@ -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) { diff --git a/frontend/src/redux/note-details/build-state-from-updated-markdown-content.ts b/frontend/src/redux/note-details/build-state-from-updated-markdown-content.ts index 347c10cff..2fa4ba719 100644 --- a/frontend/src/redux/note-details/build-state-from-updated-markdown-content.ts +++ b/frontend/src/redux/note-details/build-state-from-updated-markdown-content.ts @@ -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 } } } diff --git a/frontend/src/redux/note-details/initial-state.ts b/frontend/src/redux/note-details/initial-state.ts index 105c8554f..d5024444e 100644 --- a/frontend/src/redux/note-details/initial-state.ts +++ b/frontend/src/redux/note-details/initial-state.ts @@ -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: {}, diff --git a/frontend/src/redux/note-details/raw-note-frontmatter-parser/parser.ts b/frontend/src/redux/note-details/raw-note-frontmatter-parser/parser.ts index 322ab6f94..2c69092ff 100644 --- a/frontend/src/redux/note-details/raw-note-frontmatter-parser/parser.ts +++ b/frontend/src/redux/note-details/raw-note-frontmatter-parser/parser.ts @@ -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), diff --git a/frontend/src/redux/note-details/raw-note-frontmatter-parser/types.d.ts b/frontend/src/redux/note-details/raw-note-frontmatter-parser/types.d.ts index 470c9d5e4..db478af6a 100644 --- a/frontend/src/redux/note-details/raw-note-frontmatter-parser/types.d.ts +++ b/frontend/src/redux/note-details/raw-note-frontmatter-parser/types.d.ts @@ -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 diff --git a/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts b/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts index 9338fab1d..70ff50c4b 100644 --- a/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts +++ b/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts @@ -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: { diff --git a/frontend/src/redux/note-details/types/note-details.ts b/frontend/src/redux/note-details/types/note-details.ts index 44be345f7..e78f72628 100644 --- a/frontend/src/redux/note-details/types/note-details.ts +++ b/frontend/src/redux/note-details/types/note-details.ts @@ -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