From fb3d6d518ede62ba5006127580ebce655a925c1c Mon Sep 17 00:00:00 2001 From: Markus Doggweiler Date: Sat, 13 Jul 2024 15:03:19 +0200 Subject: [PATCH] Better again... --- .../details/scraps/ScrapContextProvider.tsx | 97 +++++++++++++------ .../details/scraps/list/ScrapList.tsx | 6 +- .../details/scraps/markdown/ScrapMarkdown.tsx | 6 +- 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/app/src/components/details/scraps/ScrapContextProvider.tsx b/app/src/components/details/scraps/ScrapContextProvider.tsx index a86eb9ac..fd51113c 100644 --- a/app/src/components/details/scraps/ScrapContextProvider.tsx +++ b/app/src/components/details/scraps/ScrapContextProvider.tsx @@ -157,6 +157,66 @@ export const ScrapContextProvider: React.FC<{ setNotes(currentScrap.notes); } + function changeScrapTypeInternal( + genericNotes: string[], + targetType: ScrapType, + ) { + setAppAlert({ + message: ( + <> +
+ Would you like to change the type? Certain formatting might be lost. +
+
+ + + +
+ + ), + type: "info", + hideDurationSec: 2, + title: "Change scrap type to " + targetType, + }); + } + const contextValue = useMemo( () => { return { @@ -200,21 +260,7 @@ export const ScrapContextProvider: React.FC<{ giveFocus, hasTitleFocus, setHasTitleFocus, - changeScrapType: (genericNotes, targetType) => { - console.log("change to " + targetType, genericNotes); - - const newNotes = toTargetType(targetType, genericNotes); - - console.log("new notes:", newNotes); - - setNotes(newNotes); - - setScrapToRender({ - ...scrapToRender, - notes: newNotes, - scrapType: targetType, - }); - }, + changeScrapType: changeScrapTypeInternal, }; }, // eslint-disable-next-line react-hooks/exhaustive-deps @@ -278,21 +324,16 @@ export const ScrapContextProvider: React.FC<{ ); }; -function toList(genericNotes: string[]) { - return JSON.stringify( - genericNotes.map((n) => ({ label: n }) as IScrapListItem), - ); -} - -function toMarkdown(genericNotes: string[]) { - return genericNotes.map((n) => "- " + n).join("\n"); -} - -function toTargetType(targetType: ScrapType, genericNotes: string[]) { +function convertNotesToTargetType( + targetType: ScrapType, + genericNotes: string[], +) { switch (targetType) { case ScrapType.List: - return toList(genericNotes); + return JSON.stringify( + genericNotes.map((n) => ({ label: n }) as IScrapListItem), + ); case ScrapType.Markdown: - return toMarkdown(genericNotes); + return genericNotes.map((n) => "- " + n).join("\n"); } } diff --git a/app/src/components/details/scraps/list/ScrapList.tsx b/app/src/components/details/scraps/list/ScrapList.tsx index a71997f2..2ac48db8 100644 --- a/app/src/components/details/scraps/list/ScrapList.tsx +++ b/app/src/components/details/scraps/list/ScrapList.tsx @@ -20,9 +20,9 @@ import { useScrapContext } from "../ScrapContext"; import { ScrapBody } from "../ScrapBody"; import { AddOutlined, + AutoFixHigh, MoveDownOutlined, RemoveCircleOutline, - StarHalf, SyncAltOutlined, } from "@mui/icons-material"; import { IAction } from "../../../common/actions/IAction"; @@ -142,8 +142,8 @@ export const ScrapList: React.FC = () => { ); }, key: "toggle-type", - icon: , - label: "Toggle type", + icon: , + label: "Change type to markdown", }, { key: "add", diff --git a/app/src/components/details/scraps/markdown/ScrapMarkdown.tsx b/app/src/components/details/scraps/markdown/ScrapMarkdown.tsx index 49ad93c3..7c0a7357 100644 --- a/app/src/components/details/scraps/markdown/ScrapMarkdown.tsx +++ b/app/src/components/details/scraps/markdown/ScrapMarkdown.tsx @@ -7,7 +7,7 @@ import { ActionFactory } from "../../../common/actions/ActionFactory"; import { ScrapBody } from "../ScrapBody"; import { useAppContext } from "../../../../AppContext"; import { useScrapContext } from "../ScrapContext"; -import { StarHalf } from "@mui/icons-material"; +import { AutoFixHigh } from "@mui/icons-material"; import { ScrapType } from "../../../../serverApi/IScrapEntry"; import { getRawRowValues } from "./getRawRowValues"; @@ -31,8 +31,8 @@ export const ScrapMarkdown: React.FC = () => { changeScrapType(getRawRowValues(notes), ScrapType.List); }, key: "toggle-type", - icon: , - label: "Toggle type", + icon: , + label: "Change type to list", }, ]} actions={[ActionFactory.copyValueToClipboard(notes, setAppAlert)]}