mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: fix memo compact mode
This commit is contained in:
@@ -243,10 +243,8 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
|
|||||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTs := time.Now().Unix()
|
|
||||||
update := &store.UpdateMemo{
|
update := &store.UpdateMemo{
|
||||||
ID: id,
|
ID: id,
|
||||||
UpdatedTs: ¤tTs,
|
|
||||||
}
|
}
|
||||||
for _, path := range request.UpdateMask.Paths {
|
for _, path := range request.UpdateMask.Paths {
|
||||||
if path == "content" {
|
if path == "content" {
|
||||||
@@ -279,6 +277,12 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
|
|||||||
} else if path == "create_time" {
|
} else if path == "create_time" {
|
||||||
createdTs := request.Memo.CreateTime.AsTime().Unix()
|
createdTs := request.Memo.CreateTime.AsTime().Unix()
|
||||||
update.CreatedTs = &createdTs
|
update.CreatedTs = &createdTs
|
||||||
|
} else if path == "update_time" {
|
||||||
|
updatedTs := time.Now().Unix()
|
||||||
|
if request.Memo.UpdateTime != nil {
|
||||||
|
updatedTs = request.Memo.UpdateTime.AsTime().Unix()
|
||||||
|
}
|
||||||
|
update.UpdatedTs = &updatedTs
|
||||||
} else if path == "display_time" {
|
} else if path == "display_time" {
|
||||||
displayTs := request.Memo.DisplayTime.AsTime().Unix()
|
displayTs := request.Memo.DisplayTime.AsTime().Unix()
|
||||||
memoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
|
memoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
|
||||||
|
@@ -19,7 +19,7 @@ interface Props {
|
|||||||
const TaskListItem: React.FC<Props> = ({ node, complete, children }: Props) => {
|
const TaskListItem: React.FC<Props> = ({ node, complete, children }: Props) => {
|
||||||
const context = useContext(RendererContext);
|
const context = useContext(RendererContext);
|
||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
const [checked] = useState(complete);
|
const [checked, setChecked] = useState(complete);
|
||||||
|
|
||||||
const handleCheckboxChange = async (on: boolean) => {
|
const handleCheckboxChange = async (on: boolean) => {
|
||||||
if (context.readonly || !context.memoName) {
|
if (context.readonly || !context.memoName) {
|
||||||
@@ -35,6 +35,7 @@ const TaskListItem: React.FC<Props> = ({ node, complete, children }: Props) => {
|
|||||||
},
|
},
|
||||||
["content"],
|
["content"],
|
||||||
);
|
);
|
||||||
|
setChecked(on);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@@ -53,13 +53,13 @@ const MemoContent: React.FC<Props> = (props: Props) => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleMemoContentClick = async (e: React.MouseEvent) => {
|
const onMemoContentClick = async (e: React.MouseEvent) => {
|
||||||
if (onClick) {
|
if (onClick) {
|
||||||
onClick(e);
|
onClick(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMemoContentDoubleClick = async (e: React.MouseEvent) => {
|
const onMemoContentDoubleClick = async (e: React.MouseEvent) => {
|
||||||
if (onDoubleClick) {
|
if (onDoubleClick) {
|
||||||
onDoubleClick(e);
|
onDoubleClick(e);
|
||||||
}
|
}
|
||||||
@@ -72,10 +72,6 @@ const MemoContent: React.FC<Props> = (props: Props) => {
|
|||||||
SNIPPET: { text: t("memo.show-less"), nextState: "ALL" },
|
SNIPPET: { text: t("memo.show-less"), nextState: "ALL" },
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
sessionStorage.getItem(`${memoName}`) && setShowCompactMode(sessionStorage.getItem(`${memoName}`) as ContentCompactView);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RendererContext.Provider
|
<RendererContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -95,8 +91,8 @@ const MemoContent: React.FC<Props> = (props: Props) => {
|
|||||||
showCompactMode == "ALL" && "line-clamp-6 max-h-60",
|
showCompactMode == "ALL" && "line-clamp-6 max-h-60",
|
||||||
contentClassName,
|
contentClassName,
|
||||||
)}
|
)}
|
||||||
onClick={handleMemoContentClick}
|
onClick={onMemoContentClick}
|
||||||
onDoubleClick={handleMemoContentDoubleClick}
|
onDoubleClick={onMemoContentDoubleClick}
|
||||||
>
|
>
|
||||||
{nodes.map((node, index) => {
|
{nodes.map((node, index) => {
|
||||||
if (prevNode?.type !== NodeType.LINE_BREAK && node.type === NodeType.LINE_BREAK && skipNextLineBreakFlag) {
|
if (prevNode?.type !== NodeType.LINE_BREAK && node.type === NodeType.LINE_BREAK && skipNextLineBreakFlag) {
|
||||||
@@ -117,7 +113,6 @@ const MemoContent: React.FC<Props> = (props: Props) => {
|
|||||||
className="w-auto flex flex-row justify-start items-center cursor-pointer text-sm text-blue-600 dark:text-blue-400 hover:opacity-80"
|
className="w-auto flex flex-row justify-start items-center cursor-pointer text-sm text-blue-600 dark:text-blue-400 hover:opacity-80"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setShowCompactMode(compactStates[showCompactMode].nextState as ContentCompactView);
|
setShowCompactMode(compactStates[showCompactMode].nextState as ContentCompactView);
|
||||||
sessionStorage.setItem(`${memoName}`, compactStates[showCompactMode].nextState);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{compactStates[showCompactMode].text}
|
{compactStates[showCompactMode].text}
|
||||||
|
@@ -302,29 +302,39 @@ const MemoEditor = (props: Props) => {
|
|||||||
if (memoName) {
|
if (memoName) {
|
||||||
const prevMemo = await memoStore.getOrFetchMemoByName(memoName);
|
const prevMemo = await memoStore.getOrFetchMemoByName(memoName);
|
||||||
if (prevMemo) {
|
if (prevMemo) {
|
||||||
const updateMask = ["content", "visibility"];
|
const updateMask = new Set<string>();
|
||||||
const memoPatch: Partial<Memo> = {
|
const memoPatch: Partial<Memo> = {
|
||||||
name: prevMemo.name,
|
name: prevMemo.name,
|
||||||
content,
|
content,
|
||||||
visibility: state.memoVisibility,
|
|
||||||
};
|
};
|
||||||
if (!isEqual(displayTime, prevMemo.displayTime)) {
|
if (!isEqual(content, prevMemo.content)) {
|
||||||
updateMask.push("display_time");
|
updateMask.add("content");
|
||||||
memoPatch.displayTime = displayTime;
|
memoPatch.content = content;
|
||||||
|
}
|
||||||
|
if (!isEqual(state.memoVisibility, prevMemo.visibility)) {
|
||||||
|
updateMask.add("visibility");
|
||||||
|
memoPatch.visibility = state.memoVisibility;
|
||||||
}
|
}
|
||||||
if (!isEqual(state.resourceList, prevMemo.resources)) {
|
if (!isEqual(state.resourceList, prevMemo.resources)) {
|
||||||
updateMask.push("resources");
|
updateMask.add("resources");
|
||||||
memoPatch.resources = state.resourceList;
|
memoPatch.resources = state.resourceList;
|
||||||
}
|
}
|
||||||
if (!isEqual(state.relationList, prevMemo.relations)) {
|
if (!isEqual(state.relationList, prevMemo.relations)) {
|
||||||
updateMask.push("relations");
|
updateMask.add("relations");
|
||||||
memoPatch.relations = state.relationList;
|
memoPatch.relations = state.relationList;
|
||||||
}
|
}
|
||||||
if (!isEqual(state.location, prevMemo.location)) {
|
if (!isEqual(state.location, prevMemo.location)) {
|
||||||
updateMask.push("location");
|
updateMask.add("location");
|
||||||
memoPatch.location = state.location;
|
memoPatch.location = state.location;
|
||||||
}
|
}
|
||||||
const memo = await memoStore.updateMemo(memoPatch, updateMask);
|
if (["content", "resources", "relations", "location"].some((key) => updateMask.has(key))) {
|
||||||
|
updateMask.add("update_time");
|
||||||
|
}
|
||||||
|
if (!isEqual(displayTime, prevMemo.displayTime)) {
|
||||||
|
updateMask.add("display_time");
|
||||||
|
memoPatch.displayTime = displayTime;
|
||||||
|
}
|
||||||
|
const memo = await memoStore.updateMemo(memoPatch, Array.from(updateMask));
|
||||||
if (onConfirm) {
|
if (onConfirm) {
|
||||||
onConfirm(memo.name);
|
onConfirm(memo.name);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user