Skip to content

Commit

Permalink
chore: fix memo compact mode
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyjoygh committed Jan 10, 2025
1 parent 972ebba commit 1caaef1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
10 changes: 7 additions & 3 deletions server/router/api/v1/memo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}

currentTs := time.Now().Unix()
update := &store.UpdateMemo{
ID: id,
UpdatedTs: &currentTs,
ID: id,
}
for _, path := range request.UpdateMask.Paths {
if path == "content" {
Expand Down Expand Up @@ -279,6 +277,12 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
} else if path == "create_time" {
createdTs := request.Memo.CreateTime.AsTime().Unix()
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" {
displayTs := request.Memo.DisplayTime.AsTime().Unix()
memoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/MemoContent/TaskListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Props {
const TaskListItem: React.FC<Props> = ({ node, complete, children }: Props) => {
const context = useContext(RendererContext);
const memoStore = useMemoStore();
const [checked] = useState(complete);
const [checked, setChecked] = useState(complete);

const handleCheckboxChange = async (on: boolean) => {
if (context.readonly || !context.memoName) {
Expand All @@ -35,6 +35,7 @@ const TaskListItem: React.FC<Props> = ({ node, complete, children }: Props) => {
},
["content"],
);
setChecked(on);
};

return (
Expand Down
13 changes: 4 additions & 9 deletions web/src/components/MemoContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
onClick(e);
}
};

const handleMemoContentDoubleClick = async (e: React.MouseEvent) => {
const onMemoContentDoubleClick = async (e: React.MouseEvent) => {
if (onDoubleClick) {
onDoubleClick(e);
}
Expand All @@ -72,10 +72,6 @@ const MemoContent: React.FC<Props> = (props: Props) => {
SNIPPET: { text: t("memo.show-less"), nextState: "ALL" },
};

useEffect(() => {
sessionStorage.getItem(`${memoName}`) && setShowCompactMode(sessionStorage.getItem(`${memoName}`) as ContentCompactView);
}, []);

return (
<RendererContext.Provider
value={{
Expand All @@ -95,8 +91,8 @@ const MemoContent: React.FC<Props> = (props: Props) => {
showCompactMode == "ALL" && "line-clamp-6 max-h-60",
contentClassName,
)}
onClick={handleMemoContentClick}
onDoubleClick={handleMemoContentDoubleClick}
onClick={onMemoContentClick}
onDoubleClick={onMemoContentDoubleClick}
>
{nodes.map((node, index) => {
if (prevNode?.type !== NodeType.LINE_BREAK && node.type === NodeType.LINE_BREAK && skipNextLineBreakFlag) {
Expand All @@ -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"
onClick={() => {
setShowCompactMode(compactStates[showCompactMode].nextState as ContentCompactView);
sessionStorage.setItem(`${memoName}`, compactStates[showCompactMode].nextState);
}}
>
{compactStates[showCompactMode].text}
Expand Down
28 changes: 19 additions & 9 deletions web/src/components/MemoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,39 @@ const MemoEditor = (props: Props) => {
if (memoName) {
const prevMemo = await memoStore.getOrFetchMemoByName(memoName);
if (prevMemo) {
const updateMask = ["content", "visibility"];
const updateMask = new Set<string>();
const memoPatch: Partial<Memo> = {
name: prevMemo.name,
content,
visibility: state.memoVisibility,
};
if (!isEqual(displayTime, prevMemo.displayTime)) {
updateMask.push("display_time");
memoPatch.displayTime = displayTime;
if (!isEqual(content, prevMemo.content)) {
updateMask.add("content");
memoPatch.content = content;
}
if (!isEqual(state.memoVisibility, prevMemo.visibility)) {
updateMask.add("visibility");
memoPatch.visibility = state.memoVisibility;
}
if (!isEqual(state.resourceList, prevMemo.resources)) {
updateMask.push("resources");
updateMask.add("resources");
memoPatch.resources = state.resourceList;
}
if (!isEqual(state.relationList, prevMemo.relations)) {
updateMask.push("relations");
updateMask.add("relations");
memoPatch.relations = state.relationList;
}
if (!isEqual(state.location, prevMemo.location)) {
updateMask.push("location");
updateMask.add("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) {
onConfirm(memo.name);
}
Expand Down

0 comments on commit 1caaef1

Please sign in to comment.