diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 2e8aeb72..027bdefc 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -1,4 +1,4 @@ -import { memo } from "react"; +import { memo, useEffect, useRef, useState } from "react"; import { escape } from "lodash-es"; import { IMAGE_URL_REG, LINK_REG, MEMO_LINK_REG, TAG_REG, UNKNOWN_ID } from "../helpers/consts"; import { parseMarkedToHtml, parseRawTextToHtml } from "../helpers/marked"; @@ -12,19 +12,44 @@ import showShareMemoImageDialog from "./ShareMemoImageDialog"; import toastHelper from "./Toast"; import "../less/memo.less"; +const MAX_MEMO_CONTAINER_HEIGHT = 384; + interface Props { memo: Memo; } +type ExpandButtonStatus = -1 | 0 | 1; + +interface State { + expandButtonStatus: ExpandButtonStatus; +} + const Memo: React.FC = (props: Props) => { const { memo: propsMemo } = props; const memo = { ...propsMemo, createdAtStr: utils.getDateTimeString(propsMemo.createdTs), }; + const [state, setState] = useState({ + expandButtonStatus: -1, + }); + const memoContainerRef = useRef(null); const [showConfirmDeleteBtn, toggleConfirmDeleteBtn] = useToggle(false); const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1")); + useEffect(() => { + if (!memoContainerRef) { + return; + } + + if (Number(memoContainerRef.current?.clientHeight) > MAX_MEMO_CONTAINER_HEIGHT) { + setState({ + ...state, + expandButtonStatus: 0, + }); + } + }, []); + const handleShowMemoStoryDialog = () => { showMemoCardDialog(memo); }; @@ -96,6 +121,13 @@ const Memo: React.FC = (props: Props) => { } }; + const handleShowMoreBtnClick = () => { + setState({ + ...state, + expandButtonStatus: Number(Boolean(!state.expandButtonStatus)) as ExpandButtonStatus, + }); + }; + return (
@@ -139,10 +171,19 @@ const Memo: React.FC = (props: Props) => {
+ {state.expandButtonStatus !== -1 && ( +
+ + {state.expandButtonStatus === 0 ? "Expand" : "Fold"} + + +
+ )} 0}>
{imageUrls.map((imgUrl, idx) => ( diff --git a/web/src/components/MemoTrashDialog.tsx b/web/src/components/MemoTrashDialog.tsx index c631a419..8597a7f9 100644 --- a/web/src/components/MemoTrashDialog.tsx +++ b/web/src/components/MemoTrashDialog.tsx @@ -28,8 +28,9 @@ const MemoTrashDialog: React.FC = (props: Props) => { locationService.clearQuery(); }, []); - const handleDeletedMemoAction = useCallback((memoId: MemoId) => { + const handleDeletedMemoAction = useCallback(async (memoId: MemoId) => { setDeletedMemos((deletedMemos) => deletedMemos.filter((memo) => memo.id !== memoId)); + await memoService.fetchAllMemos(); }, []); return ( diff --git a/web/src/less/memo.less b/web/src/less/memo.less index f776fe02..b039c1cd 100644 --- a/web/src/less/memo.less +++ b/web/src/less/memo.less @@ -86,7 +86,33 @@ } > .memo-content-text { - @apply w-full h-auto; + @apply w-full h-auto transition-all; + } + + > .expand-btn-container { + @apply w-full relative flex flex-row justify-start items-center; + + > .btn { + @apply flex flex-row justify-start items-center px-2 py-1 my-1 text-xs rounded-lg border bg-gray-100 border-gray-200 opacity-80 shadow hover:opacity-60; + + &.expand-btn { + @apply mt-2; + + > .icon-img { + @apply rotate-90; + } + } + + &.fold-btn { + > .icon-img { + @apply -rotate-90; + } + } + + > .icon-img { + @apply w-4 h-auto transition-all; + } + } } > .images-wrapper {