-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Show drafted message [WPB-10991] (#18574)
* feat: Show drafted message [WPB-10991] * improvements * draft message improvements * implementation * feat(InputBar): enhance RichTextEditor with draft saving and emoji transformation * refactor(InputBar): remove unnecessary key prop from RichTextEditor component --------- Co-authored-by: Olaf Sulich <olafsulich@gmail.com>
- Loading branch information
1 parent
105b1e2
commit 549fed0
Showing
14 changed files
with
318 additions
and
37 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
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
25 changes: 25 additions & 0 deletions
25
...cript/components/ConversationListCell/components/CellDescription/CellDescription.style.ts
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,25 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {CSSObject} from '@emotion/react'; | ||
|
||
export const iconStyle: CSSObject = { | ||
verticalAlign: 'middle', | ||
marginRight: '8px', | ||
}; |
66 changes: 66 additions & 0 deletions
66
src/script/components/ConversationListCell/components/CellDescription/CellDescription.tsx
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,66 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {useMemo} from 'react'; | ||
|
||
import cx from 'classnames'; | ||
|
||
import * as Icon from 'Components/Icon'; | ||
import {DraftState, generateConversationInputStorageKey} from 'Components/InputBar/util/DraftStateUtil'; | ||
import {useLocalStorage} from 'Hooks/useLocalStorage'; | ||
|
||
import {iconStyle} from './CellDescription.style'; | ||
|
||
import {generateCellState} from '../../../../conversation/ConversationCellState'; | ||
import {Conversation, UnreadState} from '../../../../entity/Conversation'; | ||
|
||
interface Props { | ||
conversation: Conversation; | ||
mutedState: number; | ||
isActive: boolean; | ||
isRequest: boolean; | ||
unreadState: UnreadState; | ||
} | ||
|
||
export const CellDescription = ({conversation, mutedState, isActive, isRequest, unreadState}: Props) => { | ||
const cellState = useMemo(() => generateCellState(conversation), [unreadState, mutedState, isRequest]); | ||
|
||
const storageKey = generateConversationInputStorageKey(conversation); | ||
// Hardcoded __amplify__ because of StorageUtil saving as __amplify__<storage_key> | ||
const [store] = useLocalStorage<{data?: DraftState}>(`__amplify__${storageKey}`); | ||
|
||
const draftMessage = store?.data?.plainMessage; | ||
const currentConversationDraftMessage = isActive ? '' : draftMessage; | ||
|
||
if (!cellState.description && !currentConversationDraftMessage) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<span | ||
className={cx('conversation-list-cell-description', { | ||
'conversation-list-cell-description--active': isActive, | ||
})} | ||
data-uie-name="secondary-line" | ||
> | ||
{!cellState.description && currentConversationDraftMessage && <Icon.DraftMessageIcon css={iconStyle} />} | ||
{cellState.description || currentConversationDraftMessage} | ||
</span> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
src/script/components/ConversationListCell/components/CellDescription/index.tsx
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,20 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
export * from './CellDescription'; |
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
24 changes: 24 additions & 0 deletions
24
src/script/components/InputBar/components/RichTextEditor/utils/transformMessage.ts
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,24 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {findAndTransformEmoji} from '../plugins/InlineEmojiReplacementPlugin'; | ||
|
||
export const transformMessage = ({replaceEmojis, markdown}: {replaceEmojis: boolean; markdown: string}) => { | ||
return replaceEmojis ? findAndTransformEmoji(markdown) : markdown; | ||
}; |
61 changes: 61 additions & 0 deletions
61
src/script/components/InputBar/components/RichTextEditor/utils/useEditorDraftState.ts
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,61 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {useEffect, RefObject, useCallback} from 'react'; | ||
|
||
import {$convertToMarkdownString} from '@lexical/markdown'; | ||
import {LexicalEditor} from 'lexical'; | ||
import {useDebouncedCallback} from 'use-debounce'; | ||
|
||
import {markdownTransformers} from './markdownTransformers'; | ||
import {transformMessage} from './transformMessage'; | ||
|
||
const DRAFT_SAVE_DELAY = 800; | ||
|
||
interface UseEditorDraftStateProps { | ||
editorRef: RefObject<LexicalEditor | null>; | ||
saveDraftState: (editorState: string, plainMessage: string) => void; | ||
replaceEmojis: boolean; | ||
} | ||
|
||
export const useEditorDraftState = ({editorRef, saveDraftState, replaceEmojis}: UseEditorDraftStateProps) => { | ||
const saveDraft = useCallback(() => { | ||
const editor = editorRef.current; | ||
if (!editor) { | ||
return; | ||
} | ||
|
||
editor.getEditorState().read(() => { | ||
const markdown = $convertToMarkdownString(markdownTransformers); | ||
saveDraftState(JSON.stringify(editor.getEditorState().toJSON()), transformMessage({replaceEmojis, markdown})); | ||
}); | ||
}, [editorRef, saveDraftState, replaceEmojis]); | ||
|
||
const debouncedSaveDraftState = useDebouncedCallback(saveDraft, DRAFT_SAVE_DELAY); | ||
|
||
useEffect(() => { | ||
return () => { | ||
debouncedSaveDraftState.flush(); | ||
}; | ||
}, [debouncedSaveDraftState, saveDraft]); | ||
|
||
return { | ||
saveDraft: debouncedSaveDraftState, | ||
}; | ||
}; |
Oops, something went wrong.