Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib/MediaQueryContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import type { Logger } from './SendbirdState';

const DEFAULT_MOBILE = '0px';
const DEFAULT_MOBILE = '768px';
const MOBILE_CLASSNAME = 'sendbird--mobile-mode';

const MediaQueryContext = React.createContext({
Expand All @@ -11,14 +11,14 @@ const MediaQueryContext = React.createContext({

export interface MediaQueryProviderProps {
children: React.ReactElement;
mediaQueryBreakPoint?: string | boolean;
mediaQueryBreakPoint?: string;
logger?: Logger;
}

const addClassNameToBody = () => {
try {
const body = document.querySelector('body');
body.classList.add(MOBILE_CLASSNAME);
body?.classList.add(MOBILE_CLASSNAME);
} catch {
// noop
}
Expand All @@ -27,7 +27,7 @@ const addClassNameToBody = () => {
const removeClassNameFromBody = () => {
try {
const body = document.querySelector('body');
body.classList.remove(MOBILE_CLASSNAME);
body?.classList.remove(MOBILE_CLASSNAME);
} catch {
// noop
}
Expand Down Expand Up @@ -67,10 +67,10 @@ const MediaQueryProvider = (props: MediaQueryProviderProps): React.ReactElement
};
updateSize();
window.addEventListener('resize', updateSize);
logger?.info?.('MediaQueryProvider: addEventListener', updateSize);
logger?.info?.('MediaQueryProvider: addEventListener', { updateSize });
return () => {
window.removeEventListener('resize', updateSize);
logger?.info?.('MediaQueryProvider: removeEventListener', updateSize);
logger?.info?.('MediaQueryProvider: removeEventListener', { updateSize });
};
}, [mediaQueryBreakPoint]);
return (
Expand Down
8 changes: 5 additions & 3 deletions src/modules/App/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const AppLayout: React.FC<AppLayoutProps> = (
setCurrentChannel,
} = props;
const [showThread, setShowThread] = useState(false);
const [threadTargetMessage, setThreadTargetMessage] = useState<UserMessage | FileMessage>(null);
const [threadTargetMessage, setThreadTargetMessage] = useState<UserMessage | FileMessage | null>(null);
const [showSettings, setShowSettings] = useState(false);
const [showSearch, setShowSearch] = useState(false);
const [highlightedMessage, setHighlightedMessage] = useState<number>(null);
const [startingPoint, setStartingPoint] = useState<number>(null);
const [highlightedMessage, setHighlightedMessage] = useState<number | null>(null);
const [startingPoint, setStartingPoint] = useState<number | null>(null);
const { isMobile } = useMediaQueryContext();
return (
<>
Expand All @@ -46,6 +46,8 @@ export const AppLayout: React.FC<AppLayoutProps> = (
setHighlightedMessage={setHighlightedMessage}
startingPoint={startingPoint}
setStartingPoint={setStartingPoint}
threadTargetMessage={threadTargetMessage}
setThreadTargetMessage={setThreadTargetMessage}
/>
)
: (
Expand Down
18 changes: 9 additions & 9 deletions src/modules/App/DesktopLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (
threadTargetMessage,
setThreadTargetMessage,
} = props;
const [animatedMessageId, setAnimatedMessageId] = useState(null);
const [animatedMessageId, setAnimatedMessageId] = useState<number | null>(null);
return (
<div className="sendbird-app__wrap">
<div className="sendbird-app__channellist-wrap">
Expand All @@ -44,8 +44,8 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (
onProfileEditSuccess={onProfileEditSuccess}
disableAutoSelect={disableAutoSelect}
onChannelSelect={(channel) => {
setStartingPoint(null);
setHighlightedMessage(null);
setStartingPoint?.(null);
setHighlightedMessage?.(null);
Comment on lines +47 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleander would be to make these two fns. not nullable
ie: setStartingPoint(null); instead of setStartingPoint?.(null);

Copy link
Contributor

@sravan-s sravan-s May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar for other "local setters" than can be shared

Copy link
Contributor

@sravan-s sravan-s May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (channel) {
setCurrentChannel(channel);
} else {
Expand Down Expand Up @@ -93,7 +93,7 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (
setAnimatedMessageId(null);
}}
onMessageHighlighted={() => {
setHighlightedMessage(null);
setHighlightedMessage?.(null);
}}
showSearchIcon={showSearchIcon}
startingPoint={startingPoint}
Expand Down Expand Up @@ -121,13 +121,13 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (
channelUrl={currentChannel?.url || ''}
onResultClick={(message) => {
if (message.messageId === highlightedMessage) {
setHighlightedMessage(null);
setHighlightedMessage?.(null);
setTimeout(() => {
setHighlightedMessage(message.messageId);
setHighlightedMessage?.(message.messageId);
});
} else {
setStartingPoint(message.createdAt);
setHighlightedMessage(message.messageId);
setStartingPoint?.(message.createdAt);
setHighlightedMessage?.(message.messageId);
}
}}
onCloseClick={() => {
Expand All @@ -149,7 +149,7 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (
setCurrentChannel(channel);
}
if (message?.messageId !== animatedMessageId) {
setStartingPoint(message?.createdAt);
setStartingPoint?.(message?.createdAt);
}
setTimeout(() => {
setAnimatedMessageId(message?.messageId);
Expand Down
56 changes: 51 additions & 5 deletions src/modules/App/MobileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ChannelList from '../ChannelList';
import Channel from '../Channel';
import ChannelSettings from '../ChannelSettings';
import MessageSearch from '../MessageSearch';
import Thread from '../Thread';
import useSendbirdStateContext from '../../hooks/useSendbirdStateContext';
import uuidv4 from '../../utils/uuid';

Expand All @@ -19,6 +20,7 @@ enum PANELS {
CHANNEL = 'CHANNEL',
CHANNEL_SETTINGS = 'CHANNEL_SETTINGS',
MESSAGE_SEARCH = 'MESSAGE_SEARCH',
THREAD = 'THREAD',
}

export const MobileLayout: React.FC<MobileLayoutProps> = (
Expand All @@ -37,18 +39,21 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
setHighlightedMessage,
startingPoint,
setStartingPoint,
threadTargetMessage,
setThreadTargetMessage,
} = props;
const [panel, setPanel] = useState(PANELS?.CHANNEL_LIST);
const [animatedMessageId, setAnimatedMessageId] = useState<number | null>(null);

const store = useSendbirdStateContext();
const sdk = store?.stores?.sdkStore?.sdk as SendbirdGroupChat;
const userId = store?.config?.userId;

const goToMessage = (message?: BaseMessage | null) => {
setStartingPoint(message?.createdAt);
const goToMessage = (message?: BaseMessage | null, timeoutCb?: (msgId: number | null) => void) => {
setStartingPoint?.(message?.createdAt || null);
setTimeout(() => {
setHighlightedMessage(message?.messageId);
});
timeoutCb?.(message?.messageId || null);
}, 500);
};

useEffect(() => {
Expand Down Expand Up @@ -118,10 +123,23 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
showSearchIcon={showSearchIcon}
isMessageGroupingEnabled={isMessageGroupingEnabled}
startingPoint={startingPoint}
animatedMessage={animatedMessageId}
highlightedMessage={highlightedMessage}
onChatHeaderActionClick={() => {
setPanel(PANELS.CHANNEL_SETTINGS);
}}
onReplyInThread={({ message }) => {
if (replyType === 'THREAD') {
setPanel(PANELS.THREAD);
setThreadTargetMessage(message);
}
}}
onQuoteMessageClick={({ message }) => { // thread message
if (replyType === 'THREAD') {
setThreadTargetMessage(message);
setPanel(PANELS.THREAD);
}
}}
/>
</div>
)
Expand Down Expand Up @@ -151,7 +169,35 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
}}
onResultClick={(message) => {
setPanel(PANELS.CHANNEL);
goToMessage(message);
goToMessage(message, (messageId) => {
setHighlightedMessage?.(messageId);
});
}}
/>
</div>
)
}
{
panel === PANELS?.THREAD && (
<div className='sb_mobile__panelwrap'>
<Thread
channelUrl={currentChannel?.url || ''}
message={threadTargetMessage}
onHeaderActionClick={() => {
setPanel(PANELS.CHANNEL);
}}
onMoveToParentMessage={({ message, channel }) => {
if (channel?.url !== currentChannel?.url) {
setPanel(PANELS.CHANNEL);
}
if (message?.messageId !== animatedMessageId) {
goToMessage(message, (messageId) => {
setAnimatedMessageId(messageId);
});
}
setTimeout(() => {
setAnimatedMessageId(message?.messageId);
}, 500);
}}
/>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/modules/App/mobile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
.sb-show-main {
padding: 0 !important;
}

.sb_mobile__panelwrap .sendbird-thread {
width: 100%;
height: 100%;
& .sendbird-thread-ui {
max-width: 100%;
& .sendbird-thread-ui__header {
width: 100%;
}
}
}
Comment on lines +10 to +19
Copy link
Contributor

@sravan-s sravan-s May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we have to imagine they should work flawlessly even when used independently (ie.outside App(Mobile)).. Given a proper container

26 changes: 13 additions & 13 deletions src/modules/App/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ export interface AppLayoutProps {
onProfileEditSuccess?(user: User): void;
disableAutoSelect?: boolean;
currentChannel?: GroupChannel;
setCurrentChannel: React.Dispatch<GroupChannel>;
setCurrentChannel: React.Dispatch<GroupChannel | null>;
}

export interface MobileLayoutProps extends AppLayoutProps {
highlightedMessage?: number;
setHighlightedMessage?: React.Dispatch<number>;
startingPoint?: number;
setStartingPoint?: React.Dispatch<number>;
interface SubLayoutCommonProps {
highlightedMessage?: number | null;
setHighlightedMessage?: React.Dispatch<number | null>;
startingPoint?: number | null;
setStartingPoint?: React.Dispatch<number | null>;
threadTargetMessage: UserMessage | FileMessage | null;
setThreadTargetMessage: React.Dispatch<UserMessage | FileMessage>;
}

export interface DesktopLayoutProps extends AppLayoutProps {
export interface MobileLayoutProps extends AppLayoutProps, SubLayoutCommonProps { }

export interface DesktopLayoutProps extends AppLayoutProps, SubLayoutCommonProps {
// modertion pannel
showSettings: boolean;
setShowSettings: React.Dispatch<boolean>;
showSearch: boolean;
setShowSearch: React.Dispatch<boolean>;
highlightedMessage?: number;
setHighlightedMessage?: React.Dispatch<number>;
startingPoint?: number;
setStartingPoint?: React.Dispatch<number>;
// thread
showThread: boolean;
setShowThread: React.Dispatch<boolean>;
threadTargetMessage: UserMessage | FileMessage;
setThreadTargetMessage: React.Dispatch<UserMessage | FileMessage>;
}

export default interface AppProps {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/Channel/context/ChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export type ChannelContextProps = {
isReactionEnabled?: boolean;
isMessageGroupingEnabled?: boolean;
showSearchIcon?: boolean;
animatedMessage?: number;
highlightedMessage?: number;
startingPoint?: number;
animatedMessage?: number | null;
highlightedMessage?: number | null;
startingPoint?: number | null;
onBeforeSendUserMessage?(text: string, quotedMessage?: UserMessage | FileMessage): UserMessageCreateParams;
onBeforeSendFileMessage?(file: File, quotedMessage?: UserMessage | FileMessage): FileMessageCreateParams;
onBeforeUpdateUserMessage?(text: string): UserMessageUpdateParams;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/MessageSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function MessageSearchPannel(props: MessageSearchPannelProps): JSX.Element {
const [loading, setLoading] = useState(false);
const { stringSet } = useContext(LocalizationContext);

let timeout = null;
let timeout: any = null;
useEffect(() => {
if (timeout) {
clearTimeout(timeout);
Expand Down
Loading