Skip to content

Commit

Permalink
changeScrapType
Browse files Browse the repository at this point in the history
  • Loading branch information
PzYon committed Jul 10, 2024
1 parent 869b6e2 commit a94cbcc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/src/components/details/scraps/ScrapContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext } from "react";
import { IScrapEntry } from "../../../serverApi/IScrapEntry";
import { IScrapEntry, ScrapType } from "../../../serverApi/IScrapEntry";
import { EntryPropsRenderStyle } from "../../common/entries/Entry";
import { IParsedDate } from "../edit/parseDate";
import { IAction } from "../../common/actions/IAction";
Expand Down Expand Up @@ -28,6 +28,7 @@ export interface IScrapContext {
giveFocus?: () => void;
hasTitleFocus: boolean;
setHasTitleFocus: (value: boolean) => void;
changeScrapType: (rows: string[], targetType: ScrapType) => void;
}

export const ScrapContext = createContext<IScrapContext>({
Expand All @@ -51,6 +52,7 @@ export const ScrapContext = createContext<IScrapContext>({
giveFocus: null,
hasTitleFocus: null,
setHasTitleFocus: null,
changeScrapType: null,
});

export const useScrapContext = () => {
Expand Down
3 changes: 3 additions & 0 deletions app/src/components/details/scraps/ScrapContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ export const ScrapContextProvider: React.FC<{
giveFocus,
hasTitleFocus,
setHasTitleFocus,
changeScrapType: (genericNotes, targetType) => {
console.log("change to " + targetType, genericNotes);
},
};
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
4 changes: 3 additions & 1 deletion app/src/components/details/scraps/list/ScrapList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
SyncAltOutlined,
} from "@mui/icons-material";
import { IAction } from "../../../common/actions/IAction";
import { ScrapType } from "../../../../serverApi/IScrapEntry";

export const ScrapList: React.FC = () => {
const { palette } = useTheme();
Expand All @@ -37,6 +38,7 @@ export const ScrapList: React.FC = () => {
upsertScrap,
scrapToRender,
hasTitleFocus,
changeScrapType,
} = useScrapContext();

const listItemCollection = useMemo(() => {
Expand Down Expand Up @@ -132,7 +134,7 @@ export const ScrapList: React.FC = () => {
return [
{
onClick: () => {
alert("toggle type");
changeScrapType([], ScrapType.Markdown);
},
key: "toggle-type",
icon: <StarHalf />,
Expand Down
14 changes: 11 additions & 3 deletions app/src/components/details/scraps/markdown/ScrapMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ import { ScrapBody } from "../ScrapBody";
import { useAppContext } from "../../../../AppContext";
import { useScrapContext } from "../ScrapContext";
import { StarHalf } from "@mui/icons-material";
import { ScrapType } from "../../../../serverApi/IScrapEntry";
import { getRawRowValues } from "./getRawRowValues";

export const ScrapMarkdown: React.FC = () => {
const { setAppAlert } = useAppContext();

const { notes, setNotes, isEditMode, cancelEditingAction, upsertScrap } =
useScrapContext();
const {
notes,
setNotes,
isEditMode,
cancelEditingAction,
upsertScrap,
changeScrapType,
} = useScrapContext();

return (
<ScrapBody
editModeActions={[
{
onClick: () => {
alert("toggle type");
changeScrapType(getRawRowValues(notes), ScrapType.List);
},
key: "toggle-type",
icon: <StarHalf />,
Expand Down

0 comments on commit a94cbcc

Please sign in to comment.