mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix ui
This commit is contained in:
@@ -208,6 +208,9 @@
|
|||||||
"Reply...": "Reply...",
|
"Reply...": "Reply...",
|
||||||
"Error loading comments.": "Error loading comments.",
|
"Error loading comments.": "Error loading comments.",
|
||||||
"No comments yet.": "No comments yet.",
|
"No comments yet.": "No comments yet.",
|
||||||
|
"No open comments.": "No open comments.",
|
||||||
|
"No resolved comments.": "No resolved comments.",
|
||||||
|
"Add a comment...": "Add a comment...",
|
||||||
"Edit comment": "Edit comment",
|
"Edit comment": "Edit comment",
|
||||||
"Delete comment": "Delete comment",
|
"Delete comment": "Delete comment",
|
||||||
"Are you sure you want to delete this comment?": "Are you sure you want to delete this comment?",
|
"Are you sure you want to delete this comment?": "Are you sure you want to delete this comment?",
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export default function AvatarUploader({
|
|||||||
top: "50%",
|
top: "50%",
|
||||||
left: "50%",
|
left: "50%",
|
||||||
transform: "translate(-50%, -50%)",
|
transform: "translate(-50%, -50%)",
|
||||||
zIndex: 1000,
|
zIndex: 200,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Loader size="sm" />
|
<Loader size="sm" />
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default function Aside() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p="md">
|
<Box p="md" style={{ height: "100%", display: "flex", flexDirection: "column" }}>
|
||||||
{component && (
|
{component && (
|
||||||
<>
|
<>
|
||||||
<Text mb="md" fw={500}>
|
<Text mb="md" fw={500}>
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ const EditorAiMenu = ({ editor }: EditorAiMenuProps): JSX.Element | null => {
|
|||||||
return createPortal(
|
return createPortal(
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
zIndex: 200,
|
zIndex: 199,
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: menuPlacement.top,
|
top: menuPlacement.top,
|
||||||
left: menuPlacement.left,
|
left: menuPlacement.left,
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ function CommentDialog({ editor, pageId }: CommentDialogProps) {
|
|||||||
pageId: pageId,
|
pageId: pageId,
|
||||||
content: JSON.stringify(comment),
|
content: JSON.stringify(comment),
|
||||||
selection: selectedText,
|
selection: selectedText,
|
||||||
|
type: "inline",
|
||||||
};
|
};
|
||||||
|
|
||||||
const createdComment =
|
const createdComment =
|
||||||
@@ -103,6 +104,7 @@ function CommentDialog({ editor, pageId }: CommentDialogProps) {
|
|||||||
size="lg"
|
size="lg"
|
||||||
radius="md"
|
radius="md"
|
||||||
w={300}
|
w={300}
|
||||||
|
zIndex={180}
|
||||||
position={{ bottom: 500, right: 50 }}
|
position={{ bottom: 500, right: 50 }}
|
||||||
withCloseButton
|
withCloseButton
|
||||||
withBorder
|
withBorder
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useRef, useCallback, memo, useMemo } from "react";
|
import React, { useState, useRef, useCallback, memo, useMemo } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { Divider, Paper, Tabs, Badge, Text, ScrollArea } from "@mantine/core";
|
import { ActionIcon, Center, Divider, Group, Paper, Stack, Tabs, Badge, Text, ScrollArea } from "@mantine/core";
|
||||||
import CommentListItem from "@/features/comment/components/comment-list-item";
|
import CommentListItem from "@/features/comment/components/comment-list-item";
|
||||||
import {
|
import {
|
||||||
useCommentsQuery,
|
useCommentsQuery,
|
||||||
@@ -17,6 +17,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { useQueryEmit } from "@/features/websocket/use-query-emit";
|
import { useQueryEmit } from "@/features/websocket/use-query-emit";
|
||||||
import { useIsCloudEE } from "@/hooks/use-is-cloud-ee";
|
import { useIsCloudEE } from "@/hooks/use-is-cloud-ee";
|
||||||
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query.ts";
|
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query.ts";
|
||||||
|
import { IconArrowUp, IconMessageOff } from "@tabler/icons-react";
|
||||||
|
|
||||||
function CommentListWithTabs() {
|
function CommentListWithTabs() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -55,6 +56,36 @@ function CommentListWithTabs() {
|
|||||||
return { activeComments: active, resolvedComments: resolved };
|
return { activeComments: active, resolvedComments: resolved };
|
||||||
}, [comments]);
|
}, [comments]);
|
||||||
|
|
||||||
|
const [isPageCommentLoading, setIsPageCommentLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleAddPageComment = useCallback(
|
||||||
|
async (_commentId: string, content: string) => {
|
||||||
|
try {
|
||||||
|
setIsPageCommentLoading(true);
|
||||||
|
const createdComment = await createCommentMutation.mutateAsync({
|
||||||
|
pageId: page?.id,
|
||||||
|
content: JSON.stringify(content),
|
||||||
|
});
|
||||||
|
|
||||||
|
emit({
|
||||||
|
operation: "invalidateComment",
|
||||||
|
pageId: page?.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
const selector = `div[data-comment-id="${createdComment.id}"]`;
|
||||||
|
const commentElement = document.querySelector(selector);
|
||||||
|
commentElement?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
|
}, 400);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to post comment:", error);
|
||||||
|
} finally {
|
||||||
|
setIsPageCommentLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[createCommentMutation, page?.id],
|
||||||
|
);
|
||||||
|
|
||||||
const handleAddReply = useCallback(
|
const handleAddReply = useCallback(
|
||||||
async (commentId: string, content: string) => {
|
async (commentId: string, content: string) => {
|
||||||
try {
|
try {
|
||||||
@@ -132,70 +163,76 @@ function CommentListWithTabs() {
|
|||||||
|
|
||||||
const totalComments = activeComments.length + resolvedComments.length;
|
const totalComments = activeComments.length + resolvedComments.length;
|
||||||
|
|
||||||
|
const pageCommentInput = canComment ? (
|
||||||
|
<PageCommentInput
|
||||||
|
onSave={handleAddPageComment}
|
||||||
|
isLoading={isPageCommentLoading}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
|
|
||||||
// If not cloud/enterprise, show simple list without tabs
|
// If not cloud/enterprise, show simple list without tabs
|
||||||
if (!isCloudEE) {
|
if (!isCloudEE) {
|
||||||
if (totalComments === 0) {
|
|
||||||
return <>{t("No comments yet.")}</>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollArea style={{ height: "85vh" }} scrollbarSize={5} type="scroll">
|
<div style={{ flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }}>
|
||||||
<div style={{ paddingBottom: "200px" }}>
|
<ScrollArea style={{ flex: "1 1 auto" }} scrollbarSize={5} type="scroll">
|
||||||
{comments?.items
|
<div style={{ paddingBottom: "8px" }}>
|
||||||
.filter((comment: IComment) => comment.parentCommentId === null)
|
{comments?.items
|
||||||
.map((comment) => (
|
.filter((comment: IComment) => comment.parentCommentId === null)
|
||||||
<Paper
|
.map((comment) => (
|
||||||
shadow="sm"
|
<Paper
|
||||||
radius="md"
|
shadow="sm"
|
||||||
p="sm"
|
radius="md"
|
||||||
mb="sm"
|
p="sm"
|
||||||
withBorder
|
mb="sm"
|
||||||
key={comment.id}
|
withBorder
|
||||||
data-comment-id={comment.id}
|
key={comment.id}
|
||||||
>
|
data-comment-id={comment.id}
|
||||||
<div>
|
>
|
||||||
<CommentListItem
|
<div>
|
||||||
comment={comment}
|
<CommentListItem
|
||||||
pageId={page?.id}
|
comment={comment}
|
||||||
canComment={canComment}
|
pageId={page?.id}
|
||||||
userSpaceRole={space?.membership?.role}
|
canComment={canComment}
|
||||||
/>
|
userSpaceRole={space?.membership?.role}
|
||||||
<MemoizedChildComments
|
|
||||||
comments={comments}
|
|
||||||
parentId={comment.id}
|
|
||||||
pageId={page?.id}
|
|
||||||
canComment={canComment}
|
|
||||||
userSpaceRole={space?.membership?.role}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{canComment && (
|
|
||||||
<>
|
|
||||||
<Divider my={4} />
|
|
||||||
<CommentEditorWithActions
|
|
||||||
commentId={comment.id}
|
|
||||||
onSave={handleAddReply}
|
|
||||||
isLoading={isLoading}
|
|
||||||
/>
|
/>
|
||||||
</>
|
<MemoizedChildComments
|
||||||
)}
|
comments={comments}
|
||||||
</Paper>
|
parentId={comment.id}
|
||||||
))}
|
pageId={page?.id}
|
||||||
</div>
|
canComment={canComment}
|
||||||
</ScrollArea>
|
userSpaceRole={space?.membership?.role}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{canComment && (
|
||||||
|
<>
|
||||||
|
<Divider my={4} />
|
||||||
|
<CommentEditorWithActions
|
||||||
|
commentId={comment.id}
|
||||||
|
onSave={handleAddReply}
|
||||||
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Paper>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
{pageCommentInput}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
height: "85vh",
|
flex: 1,
|
||||||
|
minHeight: 0,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
marginTop: "-15px",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Tabs defaultValue="open" variant="default" style={{ flex: "0 0 auto" }}>
|
<Tabs defaultValue="open" variant="default" style={{ flex: "1 1 auto", display: "flex", flexDirection: "column", overflow: "hidden" }}>
|
||||||
<Tabs.List justify="center">
|
<Tabs.List justify="center">
|
||||||
<Tabs.Tab
|
<Tabs.Tab
|
||||||
value="open"
|
value="open"
|
||||||
@@ -220,16 +257,21 @@ function CommentListWithTabs() {
|
|||||||
</Tabs.List>
|
</Tabs.List>
|
||||||
|
|
||||||
<ScrollArea
|
<ScrollArea
|
||||||
style={{ flex: "1 1 auto", height: "calc(85vh - 60px)" }}
|
style={{ flex: "1 1 auto" }}
|
||||||
scrollbarSize={5}
|
scrollbarSize={5}
|
||||||
type="scroll"
|
type="scroll"
|
||||||
>
|
>
|
||||||
<div style={{ paddingBottom: "200px" }}>
|
<div style={{ paddingBottom: "8px" }}>
|
||||||
<Tabs.Panel value="open" pt="xs">
|
<Tabs.Panel value="open" pt="xs">
|
||||||
{activeComments.length === 0 ? (
|
{activeComments.length === 0 ? (
|
||||||
<Text size="sm" c="dimmed" ta="center" py="md">
|
<Center py="xl">
|
||||||
{t("No open comments.")}
|
<Stack align="center" gap="xs">
|
||||||
</Text>
|
<IconMessageOff size={32} stroke={1.5} color="var(--mantine-color-dimmed)" />
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{t("No open comments.")}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
) : (
|
) : (
|
||||||
activeComments.map(renderComments)
|
activeComments.map(renderComments)
|
||||||
)}
|
)}
|
||||||
@@ -237,16 +279,23 @@ function CommentListWithTabs() {
|
|||||||
|
|
||||||
<Tabs.Panel value="resolved" pt="xs">
|
<Tabs.Panel value="resolved" pt="xs">
|
||||||
{resolvedComments.length === 0 ? (
|
{resolvedComments.length === 0 ? (
|
||||||
<Text size="sm" c="dimmed" ta="center" py="md">
|
<Center py="xl">
|
||||||
{t("No resolved comments.")}
|
<Stack align="center" gap="xs">
|
||||||
</Text>
|
<IconMessageOff size={32} stroke={1.5} color="var(--mantine-color-dimmed)" />
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{t("No resolved comments.")}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
) : (
|
) : (
|
||||||
resolvedComments.map(renderComments)
|
resolvedComments.map(renderComments)
|
||||||
)}
|
)}
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
{pageCommentInput}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -298,7 +347,7 @@ const ChildComments = ({
|
|||||||
|
|
||||||
const MemoizedChildComments = memo(ChildComments);
|
const MemoizedChildComments = memo(ChildComments);
|
||||||
|
|
||||||
const CommentEditorWithActions = ({ commentId, onSave, isLoading }) => {
|
const CommentEditorWithActions = ({ commentId, onSave, isLoading, placeholder = undefined }) => {
|
||||||
const [content, setContent] = useState("");
|
const [content, setContent] = useState("");
|
||||||
const { ref, focused } = useFocusWithin();
|
const { ref, focused } = useFocusWithin();
|
||||||
const commentEditorRef = useRef(null);
|
const commentEditorRef = useRef(null);
|
||||||
@@ -316,10 +365,48 @@ const CommentEditorWithActions = ({ commentId, onSave, isLoading }) => {
|
|||||||
onUpdate={setContent}
|
onUpdate={setContent}
|
||||||
onSave={handleSave}
|
onSave={handleSave}
|
||||||
editable={true}
|
editable={true}
|
||||||
|
placeholder={placeholder}
|
||||||
/>
|
/>
|
||||||
{focused && <CommentActions onSave={handleSave} isLoading={isLoading} />}
|
{focused && <CommentActions onSave={handleSave} isLoading={isLoading} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PageCommentInput = ({ onSave, isLoading }) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [content, setContent] = useState("");
|
||||||
|
const { ref, focused } = useFocusWithin();
|
||||||
|
const commentEditorRef = useRef(null);
|
||||||
|
|
||||||
|
const handleSave = useCallback(() => {
|
||||||
|
onSave(null, content);
|
||||||
|
setContent("");
|
||||||
|
commentEditorRef.current?.clearContent();
|
||||||
|
}, [content, onSave]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={ref} style={{ flex: "0 0 auto", borderTop: "1px solid var(--mantine-color-default-border)", paddingTop: "var(--mantine-spacing-sm)", paddingBottom: 25, position: "relative" }}>
|
||||||
|
<CommentEditor
|
||||||
|
ref={commentEditorRef}
|
||||||
|
onUpdate={setContent}
|
||||||
|
onSave={handleSave}
|
||||||
|
editable={true}
|
||||||
|
placeholder={t("Add a comment...")}
|
||||||
|
/>
|
||||||
|
{focused && (
|
||||||
|
<ActionIcon
|
||||||
|
variant="filled"
|
||||||
|
radius="xl"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleSave}
|
||||||
|
loading={isLoading}
|
||||||
|
style={{ position: "absolute", right: 8, bottom: 30 }}
|
||||||
|
>
|
||||||
|
<IconArrowUp size={16} />
|
||||||
|
</ActionIcon>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default CommentListWithTabs;
|
export default CommentListWithTabs;
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ export const EditorBubbleMenu: FC<EditorBubbleMenuProps> = (props) => {
|
|||||||
return (
|
return (
|
||||||
<BubbleMenu
|
<BubbleMenu
|
||||||
{...bubbleMenuProps}
|
{...bubbleMenuProps}
|
||||||
style={{ zIndex: 200, position: "relative" }}
|
style={{ zIndex: 199, position: "relative" }}
|
||||||
>
|
>
|
||||||
<div className={classes.bubbleMenu}>
|
<div className={classes.bubbleMenu}>
|
||||||
{isGenerativeAiEnabled && (
|
{isGenerativeAiEnabled && (
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const mentionRenderItems = () => {
|
|||||||
left: `${x}px`,
|
left: `${x}px`,
|
||||||
top: `${y}px`,
|
top: `${y}px`,
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
zIndex: "100",
|
zIndex: "190",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ export class CommentService {
|
|||||||
const comment = await this.commentRepo.insertComment({
|
const comment = await this.commentRepo.insertComment({
|
||||||
pageId: page.id,
|
pageId: page.id,
|
||||||
content: commentContent,
|
content: commentContent,
|
||||||
selection: createCommentDto?.selection?.substring(0, 250),
|
selection: createCommentDto?.selection?.substring(0, 250) ?? null,
|
||||||
type: 'inline',
|
type: createCommentDto.type ?? 'page',
|
||||||
parentCommentId: createCommentDto?.parentCommentId,
|
parentCommentId: createCommentDto?.parentCommentId,
|
||||||
creatorId: userId,
|
creatorId: userId,
|
||||||
workspaceId: workspaceId,
|
workspaceId: workspaceId,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IsJSON, IsOptional, IsString, IsUUID } from 'class-validator';
|
import { IsIn, IsJSON, IsOptional, IsString, IsUUID } from 'class-validator';
|
||||||
|
|
||||||
export class CreateCommentDto {
|
export class CreateCommentDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -11,6 +11,10 @@ export class CreateCommentDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
selection: string;
|
selection: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsIn(['inline', 'page'])
|
||||||
|
type: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
parentCommentId: string;
|
parentCommentId: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user