-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change UI to use TipTap for checkinquestion
Signed-off-by: Matt Krick <[email protected]>
- Loading branch information
Showing
6 changed files
with
100 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Mention from '@tiptap/extension-mention' | ||
import Placeholder from '@tiptap/extension-placeholder' | ||
import {Extension, generateText, useEditor} from '@tiptap/react' | ||
import StarterKit from '@tiptap/starter-kit' | ||
import {serverTipTapExtensions} from '../shared/tiptap/serverTipTapExtensions' | ||
import {tiptapEmojiConfig} from '../utils/tiptapEmojiConfig' | ||
import {useTipTapEditorContent} from './useTipTapEditorContent' | ||
|
||
export const useTipTapIcebreakerEditor = (content: string, options: {readOnly?: boolean}) => { | ||
const {readOnly} = options | ||
const [contentJSON, editorRef] = useTipTapEditorContent(content) | ||
editorRef.current = useEditor( | ||
{ | ||
content: contentJSON, | ||
extensions: [ | ||
StarterKit, | ||
Placeholder.configure({ | ||
showOnlyWhenEditable: false, | ||
placeholder: 'e.g. How are you?' | ||
}), | ||
Mention.extend({name: 'emojiMention'}).configure(tiptapEmojiConfig), | ||
Extension.create({ | ||
name: 'blurOnSubmit', | ||
addKeyboardShortcuts(this) { | ||
const submit = () => { | ||
this.editor.commands.blur() | ||
return true | ||
} | ||
return { | ||
Enter: submit, | ||
Tab: submit | ||
} | ||
} | ||
}) | ||
], | ||
editable: !readOnly, | ||
autofocus: generateText(contentJSON, serverTipTapExtensions).length === 0 | ||
}, | ||
[contentJSON, readOnly] | ||
) | ||
return {editor: editorRef.current} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import {isDraftJSContent} from '../../../../client/shared/tiptap/isDraftJSContent' | ||
import {convertKnownDraftToTipTap} from '../../../utils/convertToTipTap' | ||
import {CheckInPhaseResolvers} from '../resolverTypes' | ||
|
||
const CheckInPhase: CheckInPhaseResolvers = { | ||
__isTypeOf: ({phaseType}) => phaseType === 'checkin' | ||
__isTypeOf: ({phaseType}) => phaseType === 'checkin', | ||
checkInQuestion: async ({checkInQuestion}) => { | ||
const contentJSON = JSON.parse(checkInQuestion) | ||
if (!isDraftJSContent(contentJSON)) return checkInQuestion | ||
// this is Draft-JS Content. convert it and send it down | ||
// We can get rid of this resolver once we migrate legacy draft-js content to TipTap | ||
const tipTapContent = convertKnownDraftToTipTap(contentJSON) | ||
return JSON.stringify(tipTapContent) | ||
} | ||
} | ||
|
||
export default CheckInPhase |