Skip to content

Commit

Permalink
[Comment] Comments VQA Round 2 updates (#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
finnar-bin authored Jul 9, 2024
1 parent 2b43ce7 commit 13365f1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 41 deletions.
74 changes: 40 additions & 34 deletions src/apps/content-editor/src/app/views/ItemEdit/ItemEdit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment, useEffect, useState, useMemo } from "react";
import { Fragment, useEffect, useState, useMemo, createContext } from "react";
import {
Switch,
Route,
Expand Down Expand Up @@ -64,6 +64,8 @@ const selectItemHeadTags = createSelector(
})
);

export const ItemLockContext = createContext();

export default function ItemEdit() {
const dispatch = useDispatch();
const history = useHistory();
Expand Down Expand Up @@ -359,19 +361,21 @@ export default function ItemEdit() {
}
>
{isLocked && (
<LockedItem
timestamp={lockState.timestamp}
userFirstName={lockState.firstName}
userLastName={lockState.lastName}
userEmail={lockState.email}
itemName={item?.web?.metaLinkText}
handleUnlock={forceUnlock}
handleCancel={(evt) => {
evt.stopPropagation();
history.goBack();
}}
isLocked={isLocked}
/>
<Box sx={{ zIndex: (theme) => theme.zIndex.modal + 1 }}>
<LockedItem
timestamp={lockState.timestamp}
userFirstName={lockState.firstName}
userLastName={lockState.lastName}
userEmail={lockState.email}
itemName={item?.web?.metaLinkText}
handleUnlock={forceUnlock}
handleCancel={(evt) => {
evt.stopPropagation();
history.goBack();
}}
isLocked={isLocked}
/>
</Box>
)}

<PendingEditsModal
Expand Down Expand Up @@ -491,26 +495,28 @@ export default function ItemEdit() {
"/content/:modelZUID/:itemZUID/comment/:resourceZUID/:commentZUID",
]}
render={() => (
<Content
instance={instance}
modelZUID={modelZUID}
model={model}
fields={fields}
itemZUID={itemZUID}
item={item}
items={items}
user={user}
onSave={save}
dispatch={dispatch}
loading={loading}
saving={saving}
saveClicked={saveClicked}
onUpdateFieldErrors={(errors) => {
setFieldErrors(errors);
}}
fieldErrors={fieldErrors}
hasErrors={hasErrors}
/>
<ItemLockContext.Provider value={isLocked}>
<Content
instance={instance}
modelZUID={modelZUID}
model={model}
fields={fields}
itemZUID={itemZUID}
item={item}
items={items}
user={user}
onSave={save}
dispatch={dispatch}
loading={loading}
saving={saving}
saveClicked={saveClicked}
onUpdateFieldErrors={(errors) => {
setFieldErrors(errors);
}}
fieldErrors={fieldErrors}
hasErrors={hasErrors}
/>
</ItemLockContext.Provider>
)}
/>
<Route
Expand Down
27 changes: 20 additions & 7 deletions src/shell/components/Comment/CommentsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { User } from "../../services/types";
import { useSelector } from "react-redux";
import { AppState } from "../../store/types";
import { MD5 } from "../../../utility/md5";
import { ItemLockContext } from "../../../apps/content-editor/src/app/views/ItemEdit/ItemEdit";

type PathParams = {
modelZUID: string;
Expand All @@ -33,27 +34,33 @@ type CommentsListProps = {
onClose: () => void;
isResolved: boolean;
parentCommentZUID: string;
isLoadingParentCommentZUID: boolean;
};
export const CommentsList = ({
anchorEl,
onClose,
isResolved,
parentCommentZUID,
isLoadingParentCommentZUID,
}: CommentsListProps) => {
const { resourceZUID, commentZUID } = useParams<PathParams>();
const [_, __, commentZUIDtoEdit] = useContext(CommentContext);
const isLocked = useContext<boolean>(ItemLockContext);
const [popperTopOffset, setPopperTopOffset] = useState(0);
const [popperBottomOffset, setPopperBottomOffset] = useState(0);
const [placement, setPlacement] =
useState<PopperPlacementType>("bottom-start");
const topOffsetRef = useRef<HTMLDivElement>();
const loggedInUser: User = useSelector((state: AppState) => state.user);

const { data: commentThread, isLoading: isLoadingCommentThread } =
useGetCommentThreadQuery(
{ commentZUID: parentCommentZUID },
{ skip: !parentCommentZUID }
);
const {
data: commentThread,
isLoading: isLoadingCommentThread,
isUninitialized: isCommentThreadUninitialized,
} = useGetCommentThreadQuery(
{ commentZUID: parentCommentZUID },
{ skip: !parentCommentZUID }
);

useEffect(() => {
if (
Expand Down Expand Up @@ -119,6 +126,7 @@ export const CommentsList = ({
>
<Popper
open
disablePortal={isLocked}
anchorEl={anchorEl}
placement={placement}
sx={{
Expand Down Expand Up @@ -146,7 +154,9 @@ export const CommentsList = ({
boxSizing: "border-box",
}}
>
{isLoadingCommentThread && <CommentItemLoading />}
{(isLoadingCommentThread || isLoadingParentCommentZUID) && (
<CommentItemLoading />
)}
{commentThread?.map((comment, index) => (
<Fragment key={comment.ZUID}>
<CommentItem
Expand All @@ -168,7 +178,10 @@ export const CommentsList = ({
)}
</Fragment>
))}
{!commentThread?.length && !isLoadingCommentThread && (
{((!isLoadingCommentThread &&
!isCommentThreadUninitialized &&
!commentThread?.length) ||
(!isLoadingParentCommentZUID && !parentCommentZUID)) && (
<Stack flex={1} direction="row" gap={1.5} alignItems="center">
<Avatar
sx={{ width: 32, height: 32 }}
Expand Down
5 changes: 5 additions & 0 deletions src/shell/components/Comment/MentionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const MentionList = forwardRef(

return (
<Popper
disablePortal
open
placement={placement}
anchorEl={anchorEl}
Expand All @@ -140,6 +141,10 @@ export const MentionList = forwardRef(
offset: [0, 1],
},
},
{
name: "flip",
enabled: false,
},
],
}}
>
Expand Down
1 change: 1 addition & 0 deletions src/shell/components/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const Comment = ({ resourceZUID }: CommentProps) => {
</Box>
{isCommentListOpen && (
<CommentsList
isLoadingParentCommentZUID={isLoadingComment}
parentCommentZUID={parentComment?.ZUID}
anchorEl={buttonContainerRef.current}
onClose={() => {
Expand Down

0 comments on commit 13365f1

Please sign in to comment.