mirror of
https://github.com/usememos/memos.git
synced 2024-11-11 07:24:18 +03:00
fix: editor resource list (#445)
This commit is contained in:
parent
79af7e8abf
commit
d1aa6aa7f8
@ -40,8 +40,8 @@ interface State {
|
|||||||
|
|
||||||
const MemoEditor: React.FC = () => {
|
const MemoEditor: React.FC = () => {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const user = useAppSelector((state) => state.user.user);
|
const user = useAppSelector((state) => state.user.user as User);
|
||||||
const { setting } = useAppSelector((state) => state.user.user as User);
|
const setting = user.setting;
|
||||||
const editorState = useAppSelector((state) => state.editor);
|
const editorState = useAppSelector((state) => state.editor);
|
||||||
const tags = useAppSelector((state) => state.memo.tags);
|
const tags = useAppSelector((state) => state.memo.tags);
|
||||||
const [state, setState] = useState<State>({
|
const [state, setState] = useState<State>({
|
||||||
@ -85,33 +85,29 @@ const MemoEditor: React.FC = () => {
|
|||||||
}, [editorState.markMemoId]);
|
}, [editorState.markMemoId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (editorState.editMemoId) {
|
||||||
editorState.editMemoId &&
|
|
||||||
editorState.editMemoId !== UNKNOWN_ID &&
|
|
||||||
editorState.editMemoId !== prevGlobalStateRef.current.editMemoId
|
|
||||||
) {
|
|
||||||
memoService.getMemoById(editorState.editMemoId ?? UNKNOWN_ID).then((memo) => {
|
memoService.getMemoById(editorState.editMemoId ?? UNKNOWN_ID).then((memo) => {
|
||||||
if (memo) {
|
if (memo) {
|
||||||
setState({
|
handleEditorFocus();
|
||||||
...state,
|
|
||||||
resourceList: memo.resourceList,
|
|
||||||
});
|
|
||||||
editorStateService.setMemoVisibility(memo.visibility);
|
editorStateService.setMemoVisibility(memo.visibility);
|
||||||
editorRef.current?.setContent(memo.content ?? "");
|
editorRef.current?.setContent(memo.content ?? "");
|
||||||
editorRef.current?.focus();
|
setState((state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
resourceList: memo.resourceList,
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
prevGlobalStateRef.current = editorState;
|
|
||||||
if (editorState.editMemoId) {
|
|
||||||
storage.set({
|
storage.set({
|
||||||
editingMemoIdCache: editorState.editMemoId,
|
editingMemoIdCache: editorState.editMemoId,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
storage.remove(["editingMemoIdCache"]);
|
storage.remove(["editingMemoIdCache"]);
|
||||||
}
|
}
|
||||||
}, [state, editorState.editMemoId]);
|
|
||||||
|
prevGlobalStateRef.current = editorState;
|
||||||
|
}, [editorState.editMemoId]);
|
||||||
|
|
||||||
const handleKeyDown = (event: React.KeyboardEvent) => {
|
const handleKeyDown = (event: React.KeyboardEvent) => {
|
||||||
if (event.key === "Escape" && state.fullscreen) {
|
if (event.key === "Escape" && state.fullscreen) {
|
||||||
@ -241,7 +237,6 @@ const MemoEditor: React.FC = () => {
|
|||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
resourceList: [],
|
resourceList: [],
|
||||||
});
|
});
|
||||||
editorStateService.setMemoVisibility(setting.memoVisibility);
|
|
||||||
setEditorContentCache("");
|
setEditorContentCache("");
|
||||||
storage.remove(["editingMemoVisibilityCache"]);
|
storage.remove(["editingMemoVisibilityCache"]);
|
||||||
editorRef.current?.setContent("");
|
editorRef.current?.setContent("");
|
||||||
@ -338,7 +333,7 @@ const MemoEditor: React.FC = () => {
|
|||||||
const handleTagSeletorClick = useCallback((event: React.MouseEvent) => {
|
const handleTagSeletorClick = useCallback((event: React.MouseEvent) => {
|
||||||
if (tagSeletorRef.current !== event.target && tagSeletorRef.current?.contains(event.target as Node)) {
|
if (tagSeletorRef.current !== event.target && tagSeletorRef.current?.contains(event.target as Node)) {
|
||||||
editorRef.current?.insertText(`#${(event.target as HTMLElement).textContent} ` ?? "");
|
editorRef.current?.insertText(`#${(event.target as HTMLElement).textContent} ` ?? "");
|
||||||
editorRef.current?.focus();
|
handleEditorFocus();
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { useAppSelector } from "../store";
|
|||||||
import { locationService, shortcutService } from "../services";
|
import { locationService, shortcutService } from "../services";
|
||||||
import * as utils from "../helpers/utils";
|
import * as utils from "../helpers/utils";
|
||||||
import { getTextWithMemoType } from "../helpers/filter";
|
import { getTextWithMemoType } from "../helpers/filter";
|
||||||
|
import Icon from "./Icon";
|
||||||
import "../less/memo-filter.less";
|
import "../less/memo-filter.less";
|
||||||
|
|
||||||
const MemoFilter = () => {
|
const MemoFilter = () => {
|
||||||
@ -16,28 +17,28 @@ const MemoFilter = () => {
|
|||||||
<div className={`filter-query-container ${showFilter ? "" : "!hidden"}`}>
|
<div className={`filter-query-container ${showFilter ? "" : "!hidden"}`}>
|
||||||
<span className="tip-text">{t("common.filter")}:</span>
|
<span className="tip-text">{t("common.filter")}:</span>
|
||||||
<div
|
<div
|
||||||
className={"filter-item-container " + (shortcut ? "" : "hidden")}
|
className={"filter-item-container " + (shortcut ? "" : "!hidden")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
locationService.setMemoShortcut(undefined);
|
locationService.setMemoShortcut(undefined);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">🎯</span> {shortcut?.title}
|
<Icon.Target className="icon-text" /> {shortcut?.title}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={"filter-item-container " + (tagQuery ? "" : "hidden")}
|
className={"filter-item-container " + (tagQuery ? "" : "!hidden")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
locationService.setTagQuery(undefined);
|
locationService.setTagQuery(undefined);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">🏷️</span> {tagQuery}
|
<Icon.Tag className="icon-text" /> {tagQuery}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={"filter-item-container " + (memoType ? "" : "hidden")}
|
className={"filter-item-container " + (memoType ? "" : "!hidden")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
locationService.setMemoTypeQuery(undefined);
|
locationService.setMemoTypeQuery(undefined);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">📦</span> {t(getTextWithMemoType(memoType as MemoSpecType))}
|
<Icon.Box className="icon-text" /> {t(getTextWithMemoType(memoType as MemoSpecType))}
|
||||||
</div>
|
</div>
|
||||||
{duration && duration.from < duration.to ? (
|
{duration && duration.from < duration.to ? (
|
||||||
<div
|
<div
|
||||||
@ -46,16 +47,16 @@ const MemoFilter = () => {
|
|||||||
locationService.setFromAndToQuery();
|
locationService.setFromAndToQuery();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">🗓️</span> {utils.getDateString(duration.from)} to {utils.getDateString(duration.to)}
|
<Icon.Calendar className="icon-text" /> {utils.getDateString(duration.from)} to {utils.getDateString(duration.to)}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<div
|
<div
|
||||||
className={"filter-item-container " + (textQuery ? "" : "hidden")}
|
className={"filter-item-container " + (textQuery ? "" : "!hidden")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
locationService.setTextQuery("");
|
locationService.setTextQuery("");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">🔍</span> {textQuery}
|
<Icon.Search className="icon-text" /> {textQuery}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -68,8 +68,10 @@ const SystemSection = () => {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
sx={{
|
sx={{
|
||||||
fontFamily: "monospace",
|
fontFamily: "monospace",
|
||||||
|
fontSize: "14px",
|
||||||
}}
|
}}
|
||||||
minRows={5}
|
minRows={5}
|
||||||
|
maxRows={10}
|
||||||
defaultValue={state.additionalStyle}
|
defaultValue={state.additionalStyle}
|
||||||
onChange={(event) => handleAdditionalStyleChanged(event.target.value)}
|
onChange={(event) => handleAdditionalStyleChanged(event.target.value)}
|
||||||
/>
|
/>
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
@apply rounded-full;
|
@apply rounded-full;
|
||||||
|
|
||||||
> .value-text {
|
> .value-text {
|
||||||
@apply text-sm w-full;
|
@apply text-xs w-full;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
> .filter-item-container {
|
> .filter-item-container {
|
||||||
@apply px-2 mr-2 cursor-pointer bg-gray-200 rounded whitespace-nowrap truncate hover:line-through;
|
@apply flex flex-row justify-start items-center px-2 mr-2 cursor-pointer bg-gray-200 rounded whitespace-nowrap truncate hover:line-through;
|
||||||
max-width: 256px;
|
max-width: 256px;
|
||||||
|
|
||||||
|
> .icon-text {
|
||||||
|
@apply w-4 h-auto mr-1 text-gray-500;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
> .images-wrapper {
|
> .images-wrapper {
|
||||||
@apply flex flex-row justify-start items-start mt-2 w-full overflow-x-auto overflow-y-hidden pb-1;
|
@apply flex flex-row justify-start items-start mt-2 w-full overflow-x-auto overflow-y-hidden pb-1;
|
||||||
.pretty-scroll-bar(0, 2px);
|
|
||||||
|
|
||||||
> .memo-img {
|
> .memo-img {
|
||||||
@apply mr-2 last:mr-0 w-auto h-auto shrink-0 grow-0 overflow-y-hidden;
|
@apply mr-2 last:mr-0 w-auto h-auto shrink-0 grow-0 overflow-y-hidden;
|
||||||
|
@ -3,7 +3,6 @@ import store from "../store";
|
|||||||
import { setQuery, setPathname, Query, updateStateWithLocation } from "../store/modules/location";
|
import { setQuery, setPathname, Query, updateStateWithLocation } from "../store/modules/location";
|
||||||
|
|
||||||
const updateLocationUrl = (method: "replace" | "push" = "replace") => {
|
const updateLocationUrl = (method: "replace" | "push" = "replace") => {
|
||||||
store.dispatch(updateStateWithLocation());
|
|
||||||
const { query, pathname, hash } = store.getState().location;
|
const { query, pathname, hash } = store.getState().location;
|
||||||
let queryString = stringify(query);
|
let queryString = stringify(query);
|
||||||
if (queryString) {
|
if (queryString) {
|
||||||
@ -17,6 +16,7 @@ const updateLocationUrl = (method: "replace" | "push" = "replace") => {
|
|||||||
} else {
|
} else {
|
||||||
window.history.pushState(null, "", pathname + hash + queryString);
|
window.history.pushState(null, "", pathname + hash + queryString);
|
||||||
}
|
}
|
||||||
|
store.dispatch(updateStateWithLocation());
|
||||||
};
|
};
|
||||||
|
|
||||||
const locationService = {
|
const locationService = {
|
||||||
|
Loading…
Reference in New Issue
Block a user