Repository navigation
feat(ScheduledMessages): scheduled messages built on existing SDK patterns #3426
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
Open
MartinCupela
wants to merge
38
commits into
master
Choose a base branch
from
feat/scheduled-messages-lean
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
d5d7261
feat(ScheduledMessages): scheduled messages built on existing SDK pat…
MartinCupela b38ef1c
fix(ScheduledMessages): list scheduled messages flat, earliest first
MartinCupela 890fdc8
feat(ScheduledMessages): list SDK scheduled-message views, searchable…
MartinCupela ccc40ed
fix(ScheduledMessages): keep the list dialog within narrow screens, a…
MartinCupela 023ee17
fix(ScheduledMessages): load lists only when needed and keep schedule…
MartinCupela 886995d
feat(ScheduledMessages): show the send time with Reschedule while edi…
MartinCupela 497472d
fix(ScheduledMessages): stop treating a shared location as blocking s…
MartinCupela 062d243
fix(ScheduledMessages): address review findings on the list and time …
MartinCupela 826dd6f
fix(examples): guard the freeze switch and detach a poll from a faile…
MartinCupela 91c33b2
docs: restore master's guidance for showing header content beside the…
MartinCupela f8e05e5
fix(ScheduledMessageList): load on past a page that adds nothing to show
MartinCupela 7be01ac
refactor(ScheduledMessages): build the row actions as an action set
MartinCupela 103d357
fix(MessageComposer): scroll the composer previews past their height cap
MartinCupela f5e9c08
Merge branch 'master' of github.com:GetStream/stream-chat-react into …
MartinCupela 1e315f0
Merge branch 'master' into feat/scheduled-messages-lean
NikolaGoranNaumovski 367d015
fix(ScheduledMessages): follow the renamed LLC APIs and keep the time…
NikolaGoranNaumovski 1ec9d75
feat(ScheduledMessages): align the web UI with the Figma designs
NikolaGoranNaumovski c1dea9e
feat(ScheduledMessages): add date, time and delete-confirmation slots
NikolaGoranNaumovski 1f22416
feat(ChannelDetail): open the channel's scheduled messages from the b…
NikolaGoranNaumovski 3d36a66
chore(examples): show the Figma scheduled-message pickers in the vite…
NikolaGoranNaumovski 805d4d0
Merge remote-tracking branch 'origin/master' into feat/scheduled-mess…
NikolaGoranNaumovski 00bf82d
chore(examples): build the examples against stream-chat master
NikolaGoranNaumovski 3b1ed50
fix(ScheduledMessages): follow the merged stream-chat scheduled-messa…
NikolaGoranNaumovski 94310b3
feat(ScheduledMessages): align the remaining web details with the Fig…
NikolaGoranNaumovski db247c9
fix(examples): pick the first matching time on Enter and size the cal…
NikolaGoranNaumovski fa8032d
feat(ScheduledMessages): include thread replies in the channel's bann…
NikolaGoranNaumovski 3bc2817
feat(ScheduledMessages): float the banner over the message list
NikolaGoranNaumovski 88897ea
feat(ScheduledMessages): match the failed row menu to the designs
NikolaGoranNaumovski c1b8039
fix(examples): keep the thread visible while its panel closes
NikolaGoranNaumovski c8bf82b
chore(deps): require stream-chat 10.3.1 for the scheduled-message APIs
MartinCupela 0a8e910
refactor(ScheduledMessages): trim the scheduled-message utils
NikolaGoranNaumovski 0b69e82
refactor(ScheduledMessages): map scheduled-message codes to their cop…
NikolaGoranNaumovski ec12cdf
refactor(ScheduledMessages): render one schedule dialog from the comp…
NikolaGoranNaumovski 722b532
refactor(Form): add a SearchInput shared by the search fields
NikolaGoranNaumovski 35440f9
refactor(ScheduledMessages): reuse the SDK's list slots, capabilities…
NikolaGoranNaumovski 4fae7d1
fix(ScheduledMessages): hide the schedule button once a shared locati…
NikolaGoranNaumovski eef901b
docs: note that scheduled messages need stream-chat ^10.3.1
NikolaGoranNaumovski cb8cb96
chore(examples): drop the scheduledMessages.search key from the vite …
MartinCupela 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
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
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
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
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
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,116 @@ | ||
| import { useEffect, useMemo, useState } from 'react'; | ||
| import type { OwnCapabilitiesState } from 'stream-chat'; | ||
| import { | ||
| asDynamicKey, | ||
| ListItemLayout, | ||
| Switch, | ||
| useNotificationApi, | ||
| useStateStore, | ||
| useTranslationContext, | ||
| } from 'stream-chat-react'; | ||
| import { | ||
| type ChannelManagementActionItem, | ||
| defaultChannelManagementActionSet, | ||
| useChannelDetailContext, | ||
| } from 'stream-chat-react/channel-detail'; | ||
|
|
||
| import { IconLock } from '../icons'; | ||
|
|
||
| const toError = (error: unknown) => | ||
| error instanceof Error ? error : new Error('An unknown error occurred'); | ||
|
|
||
| const selectCanFreeze = ({ ownCapabilities }: OwnCapabilitiesState) => ({ | ||
| canFreeze: !!ownCapabilities?.includes('freeze-channel'), | ||
| }); | ||
|
|
||
| const FreezeActionIcon = () => ( | ||
| <IconLock className='str-chat__channel-detail__action-icon' /> | ||
| ); | ||
|
|
||
| /** | ||
| * Freezes or unfreezes the channel, for a user whose role has the `UpdateChannelFrozen` | ||
| * permission. A frozen channel takes no new messages, which is also how a scheduled message | ||
| * can be made to fail with `channel_frozen`. The SDK ships no freeze action; it is demo code. | ||
| */ | ||
| const ChannelFreezeAction = () => { | ||
| const { channel } = useChannelDetailContext(); | ||
| const { addNotification } = useNotificationApi(); | ||
| const { t } = useTranslationContext(); | ||
| const { canFreeze } = useStateStore(channel.state, selectCanFreeze); | ||
| const [frozen, setFrozen] = useState(!!channel.data?.frozen); | ||
| // one request at a time, so failures cannot roll the switch back out of order | ||
| const [isUpdating, setIsUpdating] = useState(false); | ||
|
|
||
| // follows a freeze made elsewhere, such as in the dashboard | ||
| useEffect(() => { | ||
| setFrozen(!!channel.data?.frozen); | ||
| const { unsubscribe } = channel.on('channel.updated', ({ channel: data }) => { | ||
| if (data?.frozen !== undefined) setFrozen(data.frozen); | ||
| }); | ||
| return unsubscribe; | ||
| }, [channel]); | ||
|
|
||
| const TrailingSlot = useMemo(() => { | ||
| function ChannelFreezeSwitch() { | ||
| return <Switch on={frozen} presentation />; | ||
| } | ||
| return ChannelFreezeSwitch; | ||
| }, [frozen]); | ||
|
|
||
| if (!canFreeze) return null; | ||
|
|
||
| const toggleFrozen = async () => { | ||
| if (isUpdating) return; | ||
| const nextFrozen = !frozen; | ||
| setIsUpdating(true); | ||
| setFrozen(nextFrozen); | ||
| try { | ||
| await channel.updatePartial({ set: { frozen: nextFrozen } }); | ||
| } catch (error) { | ||
| // back to what the channel last confirmed | ||
| setFrozen(!!channel.data?.frozen); | ||
| addNotification({ | ||
| context: { channel }, | ||
| emitter: 'ChannelFreezeAction', | ||
| error: toError(error), | ||
| message: nextFrozen | ||
| ? t( | ||
| asDynamicKey('viteExample.channelFreeze.freezeError.text'), | ||
| "Couldn't freeze the channel", | ||
| ) | ||
| : t( | ||
| asDynamicKey('viteExample.channelFreeze.unfreezeError.text'), | ||
| "Couldn't unfreeze the channel", | ||
| ), | ||
| severity: 'error', | ||
| type: 'api:channel:freeze:failed', | ||
| }); | ||
| } finally { | ||
| setIsUpdating(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <ListItemLayout | ||
| LeadingIcon={FreezeActionIcon} | ||
| RootElement='button' | ||
| rootProps={{ | ||
| 'aria-pressed': frozen, | ||
| className: | ||
| 'str-chat__form__switch-field str-chat__channel-management-view-action', | ||
| disabled: isUpdating, | ||
| onClick: toggleFrozen, | ||
| }} | ||
| title={t(asDynamicKey('viteExample.channelFreeze.title'), 'Freeze channel')} | ||
| TrailingSlot={TrailingSlot} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| /** The SDK's channel actions with the freeze switch after Mute chat. */ | ||
| export const channelManagementActionSetWithFreeze: ChannelManagementActionItem[] = | ||
| defaultChannelManagementActionSet.flatMap((action) => | ||
| action.type === 'muteChannel' | ||
| ? [action, { Component: ChannelFreezeAction, type: 'freezeChannel' }] | ||
| : [action], | ||
| ); | ||
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.