feat: [code-1316]: add video support in comment box (#965)

This commit is contained in:
Calvin Lee 2024-01-13 00:34:41 +00:00 committed by Harness
parent 123267c918
commit 634a70a833
4 changed files with 7 additions and 5 deletions

View File

@ -79,6 +79,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
const { getString } = useStrings()
const view = useRef<EditorView>()
const ref = useRef<HTMLDivElement>()
const [fileData, setFile] = useState<File>()
const languageConfig = useMemo(() => new Compartment(), [])
const [markdownContent, setMarkdownContent] = useState('')
@ -103,7 +104,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
const updateContentWithoutStateChange = () => {
setUploading(true)
if (view.current && markdownContent && !inGitBlame) {
const markdownInsert = `![image](${markdownContent})`
const markdownInsert = fileData?.type.startsWith('image/') ? `![image](${markdownContent})` : `${markdownContent}`
const range = view.current.state.selection.main
const cursorPos = range.from
const newCursorPos = cursorPos + markdownInsert.length
@ -206,6 +207,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
}, [filename, forMarkdown, view, languageConfig, markdownLanguageSupport])
const handleUploadCallback = (file: File) => {
if (!inGitBlame) {
setFile(file)
handleUpload(file, setMarkdownContent, repoMetadata, showError, standalone, routingId)
}
}

View File

@ -169,6 +169,7 @@ export function MarkdownEditorWithPreview({
}
case ToolbarAction.UPLOAD: {
setFile(undefined)
setOpen(true)
break
@ -303,7 +304,7 @@ export function MarkdownEditorWithPreview({
useEffect(() => {
const view = viewRef.current
if (markdownContent && view) {
const insertText = `![image](${markdownContent})`
const insertText = file?.type.startsWith('image/') ? `![image](${markdownContent})` : `${markdownContent}`
view.dispatch(
view.state.changeByRange(range => ({
changes: [{ from: range.from, insert: insertText }],
@ -384,7 +385,6 @@ export function MarkdownEditorWithPreview({
onClick={() => {
handleUpload(file as File, setMarkdownContent, repoMetadata, showError, standalone, routingId)
setOpen(false)
setFile(undefined)
}}
/>
<Button

View File

@ -852,7 +852,7 @@ enterBitbucketPlaceholder: https://bitbucket.org/
changeRepoVis: Change repository visibility
changeRepoVisContent: Are you sure you want to make this repository {repoVis}? {repoText}
repoVisibility: Repository Visibility
attachText: Attach images by dragging & dropping, selecting or pasting them.
attachText: Attach images & videos by dragging & dropping, selecting or pasting them.
key: Key
setting: Setting
mergeCommit: Merge commit

View File

@ -258,7 +258,7 @@ export const handlePaste = (event: { preventDefault: () => void; clipboardData:
if (items.length > 0) {
const firstItem = items[0]
if (firstItem.type.startsWith('image/')) {
if (firstItem.type.startsWith('image/') || firstItem.type.startsWith('video/')) {
const blob = firstItem.getAsFile()
callback(blob)
}