Skip to content

feat: allow comments to be pinned #4772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions web/src/components/MemoActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,13 @@ const MemoActionMenu = observer((props: Props) => {

const handleTogglePinMemoBtnClick = async () => {
try {
if (memo.pinned) {
await memoStore.updateMemo(
{
name: memo.name,
pinned: false,
},
["pinned"],
);
} else {
await memoStore.updateMemo(
{
name: memo.name,
pinned: true,
},
["pinned"],
);
}
await memoStore.updateMemo(
{
name: memo.name,
pinned: !memo.pinned,
},
["pinned"],
);
} catch {
// do nth
}
Expand Down Expand Up @@ -173,15 +163,13 @@ const MemoActionMenu = observer((props: Props) => {
<div className="flex flex-col text-sm gap-0.5">
{!readonly && !isArchived && (
<>
{!isComment && (
<button
onClick={handleTogglePinMemoBtnClick}
className="flex items-center gap-2 px-2 py-1 text-left dark:text-zinc-300 hover:bg-gray-100 dark:hover:bg-zinc-700 outline-none rounded"
>
{memo.pinned ? <BookmarkMinusIcon className="w-4 h-auto" /> : <BookmarkPlusIcon className="w-4 h-auto" />}
{memo.pinned ? t("common.unpin") : t("common.pin")}
</button>
)}
<button
onClick={handleTogglePinMemoBtnClick}
className="flex items-center gap-2 px-2 py-1 text-left dark:text-zinc-300 hover:bg-gray-100 dark:hover:bg-zinc-700 outline-none rounded"
>
{memo.pinned ? <BookmarkMinusIcon className="w-4 h-auto" /> : <BookmarkPlusIcon className="w-4 h-auto" />}
{memo.pinned ? t("common.unpin") : t("common.pin")}
</button>
<button
onClick={handleEditMemoClick}
className="flex items-center gap-2 px-2 py-1 text-left dark:text-zinc-300 hover:bg-gray-100 dark:hover:bg-zinc-700 outline-none rounded"
Expand All @@ -202,7 +190,7 @@ const MemoActionMenu = observer((props: Props) => {
)}
{!readonly && (
<>
{!isArchived && !isComment && hasCompletedTaskList && (
{!isArchived && hasCompletedTaskList && (
<button
onClick={handleRemoveCompletedTaskListItemsClick}
className="flex items-center gap-2 px-2 py-1 text-left text-amber-600 dark:text-amber-400 hover:bg-gray-100 dark:hover:bg-zinc-700 outline-none rounded"
Expand Down
21 changes: 12 additions & 9 deletions web/src/pages/MemoDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,18 @@ const MemoDetail = observer(() => {
</Button>
)}
</div>
{comments.map((comment) => (
<MemoView
key={`${comment.name}-${comment.displayTime}`}
memo={comment}
parentPage={locationState?.from}
showCreator
compact
/>
))}
{comments
.sort((a, b) => Number(b.pinned) - Number(a.pinned))
.map((comment) => (
<MemoView
key={`${comment.name}-${comment.displayTime}`}
memo={comment}
parentPage={locationState?.from}
showCreator
showPinned
compact
/>
))}
</>
)}
</div>
Expand Down