Repository navigation
docs(examples): build the poll recipe on the composer preview set #3374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
7 changes: 0 additions & 7 deletions
7
examples/cookbook/src/recipes/composer/poll-with-text-and-attachments/AddPollDialog.css
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
examples/cookbook/src/recipes/composer/poll-with-text-and-attachments/AddPollDialog.tsx
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
examples/cookbook/src/recipes/composer/poll-with-text-and-attachments/AttachPollControls.tsx
This file contains hidden or 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,62 @@ | ||
| import { useState } from 'react'; | ||
| import { flushSync } from 'react-dom'; | ||
| import type { PollCreationDialogControlsProps } from 'stream-chat-react'; | ||
| import { | ||
| Prompt, | ||
| useCanCreatePoll, | ||
| useMessageComposerContext, | ||
| useMessageComposerController, | ||
| } from 'stream-chat-react'; | ||
|
|
||
| /** | ||
| * The Create poll dialog's footer. "Add to message" creates the poll and adds it to the composer, | ||
| * without sending anything. The message goes out when the user sends it from the composer. | ||
| */ | ||
| export const AttachPollControls = ({ close }: PollCreationDialogControlsProps) => { | ||
| const { textareaRef } = useMessageComposerContext(); | ||
| const messageComposer = useMessageComposerController(); | ||
| const canCreatePoll = useCanCreatePoll(); | ||
|
|
||
| const [isCreating, setIsCreating] = useState(false); | ||
|
|
||
| const addPoll = async () => { | ||
| setIsCreating(true); | ||
|
MartinCupela marked this conversation as resolved.
Resolved
|
||
| try { | ||
| // Creates the poll on the server and sets `messageComposer.state.pollId`, so a new poll | ||
| // replaces one already waiting in the composer. | ||
| await messageComposer.createPoll(); | ||
| } catch { | ||
| // `createPoll()` already reported the failure as a notification. | ||
| } finally { | ||
| setIsCreating(false); | ||
| // Closed only once the poll is attached: a message sent from the composer while the poll | ||
| // is still being created would go out without it. Closing and focusing the composer in one | ||
| // step keeps focus from passing through the attachment button that opened the dialog. | ||
| flushSync(() => close()); | ||
| textareaRef?.current?.focus(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Prompt.Footer> | ||
| <Prompt.FooterControls> | ||
| {/* Disabled while the poll is being created: the poll would still be attached after a | ||
| Cancel. */} | ||
| <Prompt.FooterControlsButtonSecondary | ||
| disabled={isCreating} | ||
| onClick={close} | ||
| type='button' | ||
| > | ||
| Cancel | ||
| </Prompt.FooterControlsButtonSecondary> | ||
| <Prompt.FooterControlsButtonPrimary | ||
| disabled={!canCreatePoll || isCreating} | ||
| onClick={() => void addPoll()} | ||
| type='submit' | ||
| > | ||
| Add to message | ||
| </Prompt.FooterControlsButtonPrimary> | ||
| </Prompt.FooterControls> | ||
| </Prompt.Footer> | ||
| ); | ||
| }; | ||
5 changes: 0 additions & 5 deletions
5
...ples/cookbook/src/recipes/composer/poll-with-text-and-attachments/ComposerPollPreview.css
This file contains hidden or 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 hidden or 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
8 changes: 4 additions & 4 deletions
8
examples/cookbook/src/recipes/composer/poll-with-text-and-attachments/WithPollWithText.tsx
This file contains hidden or 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
30 changes: 12 additions & 18 deletions
30
examples/cookbook/src/recipes/composer/poll-with-text-and-attachments/installPollWithText.ts
This file contains hidden or 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
6 changes: 2 additions & 4 deletions
6
examples/cookbook/src/recipes/composer/poll-with-text-and-attachments/removePendingPoll.ts
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.