-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
34 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { useSelector } from '../WebChatReduxContext'; | ||
import WebChatUIContext from '../WebChatUIContext'; | ||
|
||
export default function useSuggestedActions() { | ||
const value = useSelector(({ suggestedActions }) => suggestedActions); | ||
const { clearSuggestedActions } = useContext(WebChatUIContext); | ||
|
||
return [ | ||
value, | ||
value => { | ||
if (value && value.length) { | ||
throw new Error('SuggestedActions cannot be set to values other than empty.'); | ||
} | ||
|
||
clearSuggestedActions(); | ||
} | ||
]; | ||
} |
31 changes: 18 additions & 13 deletions
31
samples/21.customization-plain-ui/src/SuggestedActions.js
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,21 +1,26 @@ | ||
import { connectToWebChat } from 'botframework-webchat-component'; | ||
import { hooks } from 'botframework-webchat-component'; | ||
import React from 'react'; | ||
|
||
import CardActionButton from './CardActionButton'; | ||
|
||
const { useSuggestedActions } = hooks; | ||
|
||
// Web Chat cleaned up the suggestedActions for us. | ||
// If the last activity is from the bot and contains "suggestedActions", Web Chat will send it to us thru "suggestedActions". | ||
const SuggestedActions = ({ suggestedActions }) => | ||
!!suggestedActions.length && ( | ||
<ul> | ||
{suggestedActions.map((cardAction, index) => ( | ||
<li key={index}> | ||
<CardActionButton cardAction={cardAction} /> | ||
</li> | ||
))} | ||
</ul> | ||
const SuggestedActions = () => { | ||
const [suggestedActions] = useSuggestedActions(); | ||
|
||
return ( | ||
!!suggestedActions.length && ( | ||
<ul> | ||
{suggestedActions.map((cardAction, index) => ( | ||
<li key={index}> | ||
<CardActionButton cardAction={cardAction} /> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
); | ||
}; | ||
|
||
export default connectToWebChat(({ suggestedActions }) => ({ | ||
suggestedActions | ||
}))(SuggestedActions); | ||
export default SuggestedActions; |