Skip to content

Commit

Permalink
refactor(react): rename names to not be only bind to imagePreviewer a…
Browse files Browse the repository at this point in the history
…nd to be generic
  • Loading branch information
vanbasten17 committed Dec 22, 2021
1 parent 0b59427 commit 1983638
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/botonic-react/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ export class WebchatApp {
updateLastMessageDate(date: string): void
updateUser(user: core.SessionUser): void
updateWebchatSettings(settings: WebchatSettingsProps): void
openImagePreviewer(customContent: React.ReactNode): void
closeImagePreviewer(): void
renderCustomComponent(customComponent: React.ReactNode): void
unmountCustomComponent(): void
}

export interface WebchatContextProps {
Expand Down
8 changes: 4 additions & 4 deletions packages/botonic-react/src/webchat-app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ export class WebchatApp {
this.webchatRef.current.closeCoverComponent()
}

openImagePreviewer(imagePreviewerContent) {
this.webchatRef.current.openImagePreviewer(imagePreviewerContent)
renderCustomComponent(_customComponent) {
this.webchatRef.current.renderCustomComponent(_customComponent)
}

closeImagePreviewer() {
this.webchatRef.current.closeImagePreviewer()
unmountCustomComponent() {
this.webchatRef.current.unmountCustomComponent()
}

toggleCoverComponent() {
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/webchat/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const TOGGLE_WEBCHAT = 'toggleWebchat'
export const TOGGLE_EMOJI_PICKER = 'toggleEmojiPicker'
export const TOGGLE_PERSISTENT_MENU = 'togglePersistentMenu'
export const TOGGLE_COVER_COMPONENT = 'toggleCoverComponent'
export const TOGGLE_IMAGE_PREVIEWER = 'toggleImagePreviewer'
export const DO_RENDER_CUSTOM_COMPONENT = 'doRenderCustomComponent'
export const SET_ERROR = 'setError'
export const CLEAR_MESSAGES = 'clearMessages'
export const UPDATE_LAST_MESSAGE_DATE = 'updateLastMessageDate'
Expand Down
12 changes: 6 additions & 6 deletions packages/botonic-react/src/webchat/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
ADD_MESSAGE,
ADD_MESSAGE_COMPONENT,
CLEAR_MESSAGES,
DO_RENDER_CUSTOM_COMPONENT,
SET_CURRENT_ATTACHMENT,
SET_ERROR,
SET_ONLINE,
TOGGLE_COVER_COMPONENT,
TOGGLE_EMOJI_PICKER,
TOGGLE_IMAGE_PREVIEWER,
TOGGLE_PERSISTENT_MENU,
TOGGLE_WEBCHAT,
UPDATE_DEV_SETTINGS,
Expand Down Expand Up @@ -60,7 +60,7 @@ export const webchatInitialState = {
isEmojiPickerOpen: false,
isPersistentMenuOpen: false,
isCoverComponentOpen: false,
isImagePreviewerOpened: false,
isCustomComponentRendered: false,
lastMessageUpdate: undefined,
currentAttachment: undefined,
jwt: null,
Expand Down Expand Up @@ -139,9 +139,9 @@ export function useWebchat() {
type: TOGGLE_COVER_COMPONENT,
payload: toggle,
})
const toggleImagePreviewer = toggle =>
const doRenderCustomComponent = toggle =>
webchatDispatch({
type: TOGGLE_IMAGE_PREVIEWER,
type: DO_RENDER_CUSTOM_COMPONENT,
payload: toggle,
})
const setError = error =>
Expand Down Expand Up @@ -199,7 +199,7 @@ export function useWebchat() {
toggleEmojiPicker,
togglePersistentMenu,
toggleCoverComponent,
toggleImagePreviewer,
doRenderCustomComponent,
setError,
setOnline,
clearMessages,
Expand Down Expand Up @@ -227,7 +227,7 @@ export function useTyping({ webchatState, updateTyping, updateMessage, host }) {
updateMessage({ ...nextMsg, display: true })
updateTyping(false)
}, totalDelay * 1000)
} catch (e) { }
} catch (e) {}
return () => {
clearTimeout(delayTimeout)
clearTimeout(typingTimeout)
Expand Down
6 changes: 3 additions & 3 deletions packages/botonic-react/src/webchat/webchat-reducer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
DO_RENDER_CUSTOM_COMPONENT,
SET_CURRENT_ATTACHMENT,
SET_ERROR,
SET_ONLINE,
TOGGLE_COVER_COMPONENT,
TOGGLE_EMOJI_PICKER,
TOGGLE_IMAGE_PREVIEWER,
TOGGLE_PERSISTENT_MENU,
TOGGLE_WEBCHAT,
UPDATE_DEV_SETTINGS,
Expand Down Expand Up @@ -43,8 +43,8 @@ export function webchatReducer(state, action) {
return { ...state, isPersistentMenuOpen: action.payload }
case TOGGLE_COVER_COMPONENT:
return { ...state, isCoverComponentOpen: action.payload }
case TOGGLE_IMAGE_PREVIEWER:
return { ...state, isImagePreviewerOpened: action.payload }
case DO_RENDER_CUSTOM_COMPONENT:
return { ...state, isCustomComponentRendered: action.payload }
case SET_ERROR:
return { ...state, error: action.payload || {} }
case SET_ONLINE:
Expand Down
24 changes: 12 additions & 12 deletions packages/botonic-react/src/webchat/webchat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const Webchat = forwardRef((props, ref) => {
toggleEmojiPicker,
togglePersistentMenu,
toggleCoverComponent,
toggleImagePreviewer,
doRenderCustomComponent,
setError,
setOnline,
clearMessages,
Expand All @@ -201,7 +201,7 @@ export const Webchat = forwardRef((props, ref) => {
const { initialSession, initialDevSettings, onStateChange } = props
const getThemeProperty = _getThemeProperty(theme)

const [imagePreviewerComponent, setImagePreviewerComponent] = useState(null)
const [customComponent, setCustomComponent] = useState(null)
const storage = props.storage === undefined ? localStorage : props.storage
const storageKey =
typeof props.storageKey === 'function'
Expand Down Expand Up @@ -562,11 +562,11 @@ export const Webchat = forwardRef((props, ref) => {
toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),
openCoverComponent: () => toggleCoverComponent(true),
closeCoverComponent: () => toggleCoverComponent(false),
openImagePreviewer: imagePreviewerContent => {
setImagePreviewerComponent(imagePreviewerContent)
toggleImagePreviewer(true)
renderCustomComponent: _customComponent => {
setCustomComponent(_customComponent)
doRenderCustomComponent(true)
},
closeImagePreviewer: () => toggleImagePreviewer(false),
unmountCustomComponent: () => doRenderCustomComponent(false),
toggleCoverComponent: () =>
toggleCoverComponent(!webchatState.isCoverComponentOpen),
openWebviewApi: component => openWebviewT(component),
Expand Down Expand Up @@ -894,9 +894,9 @@ export const Webchat = forwardRef((props, ref) => {
)
}

const imagePreviewer = () => {
if (!imagePreviewerComponent) return <></>
else return imagePreviewerComponent
const _renderCustomComponent = () => {
if (!customComponent) return <></>
else return customComponent
}

const WebchatComponent = (
Expand Down Expand Up @@ -953,9 +953,6 @@ export const Webchat = forwardRef((props, ref) => {
</ErrorMessageContainer>
)}
{webchatMessageList()}
{webchatState.isImagePreviewerOpened &&
imagePreviewerComponent &&
imagePreviewer()}
{webchatState.replies &&
Object.keys(webchatState.replies).length > 0 &&
webchatReplies()}
Expand All @@ -965,6 +962,9 @@ export const Webchat = forwardRef((props, ref) => {
{!webchatState.handoff && userInputArea()}
{webchatState.webview && webchatWebview()}
{webchatState.isCoverComponentOpen && coverComponent()}
{webchatState.isCustomComponentRendered &&
customComponent &&
_renderCustomComponent()}
</StyledWebchat>
)}
</WebchatContext.Provider>
Expand Down

0 comments on commit 1983638

Please sign in to comment.