Skip to content

Commit 792d58b

Browse files
committed
refactor: consolidate and update type definitions across MemoEditor components
1 parent 4058560 commit 792d58b

File tree

17 files changed

+147
-187
lines changed

17 files changed

+147
-187
lines changed

web/src/components/MemoEditor/Editor/SlashCommands.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import type { EditorRefActions } from ".";
2-
import type { Command } from "./commands";
1+
import type { SlashCommandsProps } from "../types";
32
import { SuggestionsPopup } from "./SuggestionsPopup";
43
import { useSuggestions } from "./useSuggestions";
54

6-
interface SlashCommandsProps {
7-
editorRef: React.RefObject<HTMLTextAreaElement>;
8-
editorActions: React.ForwardedRef<EditorRefActions>;
9-
commands: Command[];
10-
}
11-
125
const SlashCommands = ({ editorRef, editorActions, commands }: SlashCommandsProps) => {
136
const { position, suggestions, selectedIndex, isVisible, handleItemSelect } = useSuggestions({
147
editorRef,

web/src/components/MemoEditor/Editor/TagSuggestions.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ import { matchPath } from "react-router-dom";
33
import OverflowTip from "@/components/kit/OverflowTip";
44
import { useTagCounts } from "@/hooks/useUserQueries";
55
import { Routes } from "@/router";
6-
import type { EditorRefActions } from ".";
6+
import type { TagSuggestionsProps } from "../types";
77
import { SuggestionsPopup } from "./SuggestionsPopup";
88
import { useSuggestions } from "./useSuggestions";
99

10-
interface TagSuggestionsProps {
11-
editorRef: React.RefObject<HTMLTextAreaElement>;
12-
editorActions: React.ForwardedRef<EditorRefActions>;
13-
}
14-
1510
export default function TagSuggestions({ editorRef, editorActions }: TagSuggestionsProps) {
1611
// On explore page, show all users' tags; otherwise show current user's tags
1712
const isExplorePage = Boolean(matchPath(Routes.EXPLORE, window.location.pathname));

web/src/components/MemoEditor/Editor/index.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from "react";
22
import { cn } from "@/lib/utils";
33
import { EDITOR_HEIGHT } from "../constants";
4+
import type { EditorProps } from "../types";
45
import { editorCommands } from "./commands";
56
import SlashCommands from "./SlashCommands";
67
import TagSuggestions from "./TagSuggestions";
@@ -22,19 +23,7 @@ export interface EditorRefActions {
2223
setLine: (lineNumber: number, text: string) => void;
2324
}
2425

25-
interface Props {
26-
className: string;
27-
initialContent: string;
28-
placeholder: string;
29-
onContentChange: (content: string) => void;
30-
onPaste: (event: React.ClipboardEvent) => void;
31-
isFocusMode?: boolean;
32-
isInIME?: boolean;
33-
onCompositionStart?: () => void;
34-
onCompositionEnd?: () => void;
35-
}
36-
37-
const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<EditorRefActions>) {
26+
const Editor = forwardRef(function Editor(props: EditorProps, ref: React.ForwardedRef<EditorRefActions>) {
3827
const {
3928
className,
4029
initialContent,

web/src/components/MemoEditor/Toolbar/InsertMenu.tsx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LatLng } from "leaflet";
22
import { uniqBy } from "lodash-es";
33
import { FileIcon, LinkIcon, LoaderIcon, MapPinIcon, Maximize2Icon, MoreHorizontalIcon, PlusIcon } from "lucide-react";
4-
import { useContext, useState } from "react";
4+
import { useState } from "react";
55
import type { LocalFile } from "@/components/memo-metadata";
66
import { Button } from "@/components/ui/button";
77
import {
@@ -14,24 +14,17 @@ import {
1414
DropdownMenuTrigger,
1515
useDropdownMenuSubHoverDelay,
1616
} from "@/components/ui/dropdown-menu";
17-
import type { Location, MemoRelation } from "@/types/proto/api/v1/memo_service_pb";
17+
import type { MemoRelation } from "@/types/proto/api/v1/memo_service_pb";
1818
import { useTranslate } from "@/utils/i18n";
1919
import { LinkMemoDialog, LocationDialog } from "../components";
2020
import { GEOCODING } from "../constants";
21-
import { useFileUpload, useLinkMemo, useLocation } from "../hooks";
22-
import { useAbortController } from "../hooks/useAbortController";
23-
import { MemoEditorContext } from "../types";
24-
25-
interface Props {
26-
isUploading?: boolean;
27-
location?: Location;
28-
onLocationChange: (location?: Location) => void;
29-
onToggleFocusMode?: () => void;
30-
}
31-
32-
const InsertMenu = (props: Props) => {
21+
import { useAbortController, useFileUpload, useLinkMemo, useLocation } from "../hooks";
22+
import { useEditorContext } from "../state";
23+
import type { InsertMenuProps } from "../types";
24+
25+
const InsertMenu = (props: InsertMenuProps) => {
3326
const t = useTranslate();
34-
const context = useContext(MemoEditorContext);
27+
const { state, actions, dispatch } = useEditorContext();
3528

3629
const [linkDialogOpen, setLinkDialogOpen] = useState(false);
3730
const [locationDialogOpen, setLocationDialogOpen] = useState(false);
@@ -46,17 +39,15 @@ const InsertMenu = (props: Props) => {
4639
);
4740

4841
const { fileInputRef, selectingFlag, handleFileInputChange, handleUploadClick } = useFileUpload((newFiles: LocalFile[]) => {
49-
if (context.addLocalFiles) {
50-
context.addLocalFiles(newFiles);
51-
}
42+
newFiles.forEach((file) => dispatch(actions.addLocalFile(file)));
5243
});
5344

5445
const linkMemo = useLinkMemo({
5546
isOpen: linkDialogOpen,
56-
currentMemoName: context.memoName,
57-
existingRelations: context.relationList,
47+
currentMemoName: props.memoName,
48+
existingRelations: state.metadata.relations,
5849
onAddRelation: (relation: MemoRelation) => {
59-
context.setRelationList(uniqBy([...context.relationList, relation], (r) => r.relatedMemo?.name));
50+
dispatch(actions.setMetadata({ relations: uniqBy([...state.metadata.relations, relation], (r) => r.relatedMemo?.name) }));
6051
setLinkDialogOpen(false);
6152
},
6253
});

web/src/components/MemoEditor/Toolbar/VisibilitySelector.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigge
33
import VisibilityIcon from "@/components/VisibilityIcon";
44
import { Visibility } from "@/types/proto/api/v1/memo_service_pb";
55
import { useTranslate } from "@/utils/i18n";
6+
import type { VisibilitySelectorProps } from "../types";
67

7-
interface Props {
8-
value: Visibility;
9-
onChange: (visibility: Visibility) => void;
10-
onOpenChange?: (open: boolean) => void;
11-
}
12-
13-
const VisibilitySelector = (props: Props) => {
8+
const VisibilitySelector = (props: VisibilitySelectorProps) => {
149
const { value, onChange } = props;
1510
const t = useTranslate();
1611

web/src/components/MemoEditor/components/EditorContent.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import type { LocalFile } from "@/components/memo-metadata";
33
import Editor, { type EditorRefActions } from "../Editor";
44
import { useBlobUrls, useDragAndDrop } from "../hooks";
55
import { useEditorContext } from "../state";
6-
7-
interface EditorContentProps {
8-
placeholder?: string;
9-
autoFocus?: boolean;
10-
}
6+
import type { EditorContentProps } from "../types";
117

128
export const EditorContent = forwardRef<EditorRefActions, EditorContentProps>(({ placeholder }, ref) => {
139
const { state, actions, dispatch } = useEditorContext();

web/src/components/MemoEditor/components/EditorMetadata.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { FC } from "react";
22
import { AttachmentList, LocationDisplay, RelationList } from "@/components/memo-metadata";
33
import { useEditorContext } from "../state";
4+
import type { EditorMetadataProps } from "../types";
45

5-
export const EditorMetadata: FC = () => {
6+
export const EditorMetadata: FC<EditorMetadataProps> = () => {
67
const { state, actions, dispatch } = useEditorContext();
78

89
return (

web/src/components/MemoEditor/components/EditorToolbar.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import { validationService } from "../services";
44
import { useEditorContext } from "../state";
55
import InsertMenu from "../Toolbar/InsertMenu";
66
import VisibilitySelector from "../Toolbar/VisibilitySelector";
7+
import type { EditorToolbarProps } from "../types";
78

8-
interface EditorToolbarProps {
9-
onSave: () => void;
10-
onCancel?: () => void;
11-
}
12-
13-
export const EditorToolbar: FC<EditorToolbarProps> = ({ onSave, onCancel }) => {
9+
export const EditorToolbar: FC<EditorToolbarProps> = ({ onSave, onCancel, memoName }) => {
1410
const { state, actions, dispatch } = useEditorContext();
1511
const { valid } = validationService.canSave(state);
1612

@@ -36,6 +32,7 @@ export const EditorToolbar: FC<EditorToolbarProps> = ({ onSave, onCancel }) => {
3632
location={state.metadata.location}
3733
onLocationChange={handleLocationChange}
3834
onToggleFocusMode={handleToggleFocusMode}
35+
memoName={memoName}
3936
/>
4037
</div>
4138

web/src/components/MemoEditor/components/FocusModeOverlay.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { Minimize2Icon } from "lucide-react";
22
import { Button } from "@/components/ui/button";
33
import { FOCUS_MODE_STYLES } from "../constants";
4-
5-
interface FocusModeOverlayProps {
6-
isActive: boolean;
7-
onToggle: () => void;
8-
}
4+
import type { FocusModeExitButtonProps, FocusModeOverlayProps } from "../types";
95

106
export function FocusModeOverlay({ isActive, onToggle }: FocusModeOverlayProps) {
117
if (!isActive) return null;
@@ -21,12 +17,6 @@ export function FocusModeOverlay({ isActive, onToggle }: FocusModeOverlayProps)
2117
);
2218
}
2319

24-
interface FocusModeExitButtonProps {
25-
isActive: boolean;
26-
onToggle: () => void;
27-
title: string;
28-
}
29-
3020
export function FocusModeExitButton({ isActive, onToggle, title }: FocusModeExitButtonProps) {
3121
if (!isActive) return null;
3222

web/src/components/MemoEditor/components/LinkMemoDialog.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { timestampDate } from "@bufbuild/protobuf/wkt";
22
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
33
import { Input } from "@/components/ui/input";
4-
import { Memo } from "@/types/proto/api/v1/memo_service_pb";
54
import { useTranslate } from "@/utils/i18n";
5+
import type { LinkMemoDialogProps } from "../types";
66

77
function highlightSearchText(content: string, searchText: string): React.ReactNode {
88
if (!searchText) return content;
@@ -29,16 +29,6 @@ function highlightSearchText(content: string, searchText: string): React.ReactNo
2929
);
3030
}
3131

32-
interface LinkMemoDialogProps {
33-
open: boolean;
34-
onOpenChange: (open: boolean) => void;
35-
searchText: string;
36-
onSearchChange: (text: string) => void;
37-
filteredMemos: Memo[];
38-
isFetching: boolean;
39-
onSelectMemo: (memo: Memo) => void;
40-
}
41-
4232
export const LinkMemoDialog = ({
4333
open,
4434
onOpenChange,

0 commit comments

Comments
 (0)