Make added text go after img instead of replacing (#725)
This commit is contained in:
		
							parent
							
								
									5892ccee97
								
							
						
					
					
						commit
						da977f62a9
					
				|  | @ -13,6 +13,7 @@ import { TextEditor, useTextEditor } from 'web/components/editor' | |||
| import { Button } from '../button' | ||||
| import { Spacer } from '../layout/spacer' | ||||
| import { Editor, Content as ContentType } from '@tiptap/react' | ||||
| import { appendToEditor } from '../editor/utils' | ||||
| 
 | ||||
| export function ContractDescription(props: { | ||||
|   contract: Contract | ||||
|  | @ -94,12 +95,7 @@ function RichEditContract(props: { contract: Contract; isAdmin?: boolean }) { | |||
|           size="xs" | ||||
|           onClick={() => { | ||||
|             setEditing(true) | ||||
|             editor | ||||
|               ?.chain() | ||||
|               .setContent(contract.description) | ||||
|               .focus('end') | ||||
|               .insertContent(`<p>${editTimestamp()}</p>`) | ||||
|               .run() | ||||
|             appendToEditor(editor, `<p>${editTimestamp()}</p>`) | ||||
|           }} | ||||
|         > | ||||
|           Edit description | ||||
|  | @ -131,7 +127,7 @@ function EditQuestion(props: { | |||
| 
 | ||||
|   function joinContent(oldContent: ContentType, newContent: string) { | ||||
|     const editor = new Editor({ content: oldContent, extensions: exhibitExts }) | ||||
|     editor.chain().focus('end').insertContent(newContent).run() | ||||
|     appendToEditor(editor, newContent) | ||||
|     return editor.getJSON() | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,6 +33,7 @@ import { Col } from 'web/components/layout/col' | |||
| import { ContractGroupsList } from 'web/components/groups/contract-groups-list' | ||||
| import { SiteLink } from 'web/components/site-link' | ||||
| import { groupPath } from 'web/lib/firebase/groups' | ||||
| import { appendToEditor } from '../editor/utils' | ||||
| 
 | ||||
| export type ShowTime = 'resolve-date' | 'close-date' | ||||
| 
 | ||||
|  | @ -282,12 +283,10 @@ function EditableCloseDate(props: { | |||
|       const formattedCloseDate = dayjs(newCloseTime).format('YYYY-MM-DD h:mm a') | ||||
| 
 | ||||
|       const editor = new Editor({ content, extensions: exhibitExts }) | ||||
|       editor | ||||
|         .chain() | ||||
|         .focus('end') | ||||
|         .insertContent('<br /><br />') | ||||
|         .insertContent(`Close date updated to ${formattedCloseDate}`) | ||||
|         .run() | ||||
|       appendToEditor( | ||||
|         editor, | ||||
|         `<br><p>Close date updated to ${formattedCloseDate}</p>` | ||||
|       ) | ||||
| 
 | ||||
|       updateContract(contract.id, { | ||||
|         closeTime: newCloseTime, | ||||
|  |  | |||
							
								
								
									
										10
									
								
								web/components/editor/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								web/components/editor/utils.ts
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| import { Editor, Content } from '@tiptap/react' | ||||
| 
 | ||||
| export function appendToEditor(editor: Editor | null, content: Content) { | ||||
|   editor | ||||
|     ?.chain() | ||||
|     .focus('end') | ||||
|     .createParagraphNear() | ||||
|     .insertContent(content) | ||||
|     .run() | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user