diff --git a/moon/apps/web/components/Issues/IssueDetailPage.tsx b/moon/apps/web/components/Issues/IssueDetailPage.tsx index e2d236b8f..f8f1bdf69 100644 --- a/moon/apps/web/components/Issues/IssueDetailPage.tsx +++ b/moon/apps/web/components/Issues/IssueDetailPage.tsx @@ -41,7 +41,7 @@ import { useLabelsSelector, useMemberMap } from './utils/sideEffect' -import { idAtom } from './utils/store' +import { editIdAtom, FALSE_EDIT_VAL, idAtom, refreshAtom } from './utils/store' export default function IssueDetailPage({ link }: { link: string }) { const [id] = useAtom(idAtom) @@ -107,6 +107,19 @@ export default function IssueDetailPage({ link }: { link: string }) { fetchDetail() }, [fetchDetail, link]) + const [refresh, setRefresh] = useAtom(refreshAtom) + const [_, setEditId] = useAtom(editIdAtom) + + useEffect(() => { + const load = async () => { + await refetch() + setEditId(FALSE_EDIT_VAL) + setRefresh(0) + } + + load() + }, [refresh, refetch, setEditId, setRefresh]) + const [_loadings, setLoadings] = useState([]) const router = useRouter() @@ -306,12 +319,14 @@ export default function IssueDetailPage({ link }: { link: string }) {
{info?.title && (
-
+
{!isEdit && ( <>
{`${issueDetail?.title || ''}`} +   + ${issueDetail?.id} + +
+ + )}
) } +const EditInput = forwardRef(({ comment }: { comment: ConversationItem }, ref) => { + const editorRef = useRef(null) + const onKeyDownScrollHandler = useHandleBottomScrollOffset({ + editor: editorRef.current?.editor + }) + const { dropzone } = useUploadHelpers({ + upload: editorRef.current?.uploadAndAppendAttachments + }) + const { handleChange } = useChange({}) + const [isReactionPickerOpen, setIsReactionPickerOpen] = useState(false) + const { mutateAsync: updateComment } = usePostComment() + + const [_refresh, setRefresh] = useAtom(refreshAtom) + + const handleUpdate = async () => { + const currentContentHTML = editorRef.current?.editor?.getHTML() ?? '

' + + if (trimHtml(currentContentHTML) === '') { + toast.error('comment can not be empty!') + setRefresh(0) + return + } + + try { + await updateComment({ commentId: comment.id, data: { content: currentContentHTML } }) + toast.success('update successfully!') + } catch (err: any) { + apiErrorToast(new Error(err.message)) + } + // finally { + // setRefresh(Date.now()) + // } + } + + useImperativeHandle(ref, () => ({ + handleUpdate + })) + + return ( + <> +
+ +
+ handleChange(html)} + /> +
+
+ + ) +}) + +EditInput.displayName = 'EditInput' + export default Comment diff --git a/moon/apps/web/components/MrView/components/Checks/index.tsx b/moon/apps/web/components/MrView/components/Checks/index.tsx index 65fa8b017..d6eb08279 100644 --- a/moon/apps/web/components/MrView/components/Checks/index.tsx +++ b/moon/apps/web/components/MrView/components/Checks/index.tsx @@ -9,10 +9,13 @@ enum Status { Rejected = 'rejected' } +const root = '/sse/' + const Checks = () => { const serverStream = useRef('') const es = useRef() - const baseUrl = useRef('http://47.79.95.33:3000/logs?follow=true') + // const baseUrl = useRef('http://47.79.95.33:3000/logs?follow=true') + const baseUrl = useRef(`${root}logs?follow=true`) const status = useRef(Status.Pending) const [displayTest, setDisplayText] = useState('') const { createEventSource } = useSSM() @@ -40,7 +43,7 @@ const Checks = () => { serverStream.current = '' setDisplayText('') } - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return ( diff --git a/moon/apps/web/hooks/issues/usePostComment.ts b/moon/apps/web/hooks/issues/usePostComment.ts new file mode 100644 index 000000000..916b2c48a --- /dev/null +++ b/moon/apps/web/hooks/issues/usePostComment.ts @@ -0,0 +1,16 @@ +import { useMutation } from '@tanstack/react-query' + +import { ContentPayload, PostApiConversationByCommentIdData, RequestParams } from '@gitmono/types/generated' + +import { legacyApiClient } from '@/utils/queryClient' + +export function usePostComment() { + return useMutation< + PostApiConversationByCommentIdData, + Error, + { commentId: number; data: ContentPayload; params?: RequestParams } + >({ + mutationFn: ({ commentId, data, params }) => + legacyApiClient.v1.postApiConversationByCommentId().request(commentId, data, params) + }) +} diff --git a/moon/apps/web/next.config.js b/moon/apps/web/next.config.js index ce2ba1ee1..dd4206b4b 100644 --- a/moon/apps/web/next.config.js +++ b/moon/apps/web/next.config.js @@ -62,7 +62,8 @@ const cspResourcesByDirective = { process.env.NODE_ENV !== 'production' && 'https://campsite-dev.imgix.net', 'https://react-tweet.vercel.app', // for react-tweet embeds 'https://media.tenor.com', // used for Tenor gifs - 'http://47.79.95.33:3000' + // 'http://47.79.95.33:3000' + 'https://orion.gitmega.com' ], 'font-src': ["'self'"], 'img-src': [ @@ -221,6 +222,10 @@ const moduleExports = { { source: '/ingest/decide', destination: 'https://us.i.posthog.com/decide' + }, + { + source: '/sse/:path*', + destination: `https://orion.gitmega.com/:path*` } ] }, diff --git a/moon/apps/web/pages/[org]/mr/[link]/index.tsx b/moon/apps/web/pages/[org]/mr/[link]/index.tsx index b996aab14..c50c930f0 100644 --- a/moon/apps/web/pages/[org]/mr/[link]/index.tsx +++ b/moon/apps/web/pages/[org]/mr/[link]/index.tsx @@ -1,6 +1,6 @@ 'use client' -import React, { useRef, useState } from 'react' +import React, { useEffect, useRef, useState } from 'react' import { ChecklistIcon, CommentDiscussionIcon, FileDiffIcon } from '@primer/octicons-react' import { BaseStyles, TextInput, ThemeProvider } from '@primer/react' import { useAtom } from 'jotai' @@ -25,7 +25,7 @@ import { useLabelsSelector, useMemberMap } from '@/components/Issues/utils/sideEffect' -import { mridAtom } from '@/components/Issues/utils/store' +import { editIdAtom, FALSE_EDIT_VAL, mridAtom, refreshAtom } from '@/components/Issues/utils/store' import { AppLayout } from '@/components/Layout/AppLayout' import { MemberAvatar } from '@/components/MemberAvatar' import Checks from '@/components/MrView/components/Checks' @@ -90,6 +90,19 @@ const MRDetailPage: PageWithLayout = () => { }) } + const [_, setEditId] = useAtom(editIdAtom) + const [refresh, setRefresh] = useAtom(refreshAtom) + + useEffect(() => { + const load = async () => { + await refetch() + setEditId(FALSE_EDIT_VAL) + setRefresh(0) + } + + load() + }, [refresh, refetch, setEditId, setRefresh]) + const { mutate: closeMr, isPending: mrCloseIsPending } = usePostMrClose(id) const handleMrClose = () => { if (closeHint === 'Close with comment') { diff --git a/moon/apps/web/tsconfig.json b/moon/apps/web/tsconfig.json index f046db93b..3370dd324 100644 --- a/moon/apps/web/tsconfig.json +++ b/moon/apps/web/tsconfig.json @@ -2,22 +2,54 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "@/components/*": ["components/*"], - "@/contexts/*": ["contexts/*"], - "@/atoms/*": ["atoms/*"], - "@/hooks/*": ["hooks/*"], - "@/pages/*": ["pages/*"], - "@/utils/*": ["utils/*"], - "@gitmono/editor/*": ["../../packages/editor/src/*"], - "@gitmono/editor": ["../../packages/editor/src/index"], - "@gitmono/config/*": ["../../packages/config/src/*"], - "@gitmono/config": ["../../packages/config/src/index"], - "@gitmono/ui/*": ["../../packages/ui/src/*"], - "@gitmono/ui": ["../../packages/ui/src/index"], - "@gitmono/types/*": ["../../packages/types/*"], - "@gitmono/types": ["../../packages/types/index"], - "@gitmono/regex/*": ["../../packages/regex/*"], - "@gitmono/regex": ["../../packages/regex/src/index.ts"] + "@/components/*": [ + "components/*" + ], + "@/contexts/*": [ + "contexts/*" + ], + "@/atoms/*": [ + "atoms/*" + ], + "@/hooks/*": [ + "hooks/*" + ], + "@/pages/*": [ + "pages/*" + ], + "@/utils/*": [ + "utils/*" + ], + "@gitmono/editor/*": [ + "../../packages/editor/src/*" + ], + "@gitmono/editor": [ + "../../packages/editor/src/index" + ], + "@gitmono/config/*": [ + "../../packages/config/src/*" + ], + "@gitmono/config": [ + "../../packages/config/src/index" + ], + "@gitmono/ui/*": [ + "../../packages/ui/src/*" + ], + "@gitmono/ui": [ + "../../packages/ui/src/index" + ], + "@gitmono/types/*": [ + "../../packages/types/*" + ], + "@gitmono/types": [ + "../../packages/types/index" + ], + "@gitmono/regex/*": [ + "../../packages/regex/*" + ], + "@gitmono/regex": [ + "../../packages/regex/src/index.ts" + ] }, "plugins": [ { @@ -36,6 +68,10 @@ ".next/types/**/*.ts" ], "exclude": [ - "node_modules" + "node_modules", + "dist", + "build", + ".next", + "out" ] } \ No newline at end of file