Skip to content

Commit

Permalink
feat: Export useLocalization hook & ThreadReplySelectType (#1227)
Browse files Browse the repository at this point in the history
[CLNP-5330](https://sendbird.atlassian.net/browse/CLNP-5330)
[SBISSUE-17397](https://sendbird.atlassian.net/browse/SBISSUE-17397)

### ChangeLog
Features:
- Exported `useLocalization` Hook:
  - Provided access to stringSet and dateLocale.
- Note: Required SendbirdProvider to wrap your component for proper
usage.
  - Import Path: `"@sendbird/uikit-react/hooks/useLocalization"`
- Exported `ThreadReplySelectType`:
  - Import Paths:
    - `"@sendbird/uikit-react/Channel/context"`
    - `"@sendbird/uikit-react/GroupChannel/context"`
  • Loading branch information
HoonBaek authored Oct 10, 2024
1 parent 578faa9 commit e17c99e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions rollup.module-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default {
'pubSub/topics': 'src/lib/pubSub/topics.ts',
// hooks
'hooks/useModal': 'src/hooks/useModal/index.tsx',
'hooks/useLocalization': 'src/hooks/useLocalization.ts',
// utils
'utils/message/getOutgoingMessageState': 'src/utils/exports/getOutgoingMessageState.ts',
'utils/message/isVoiceMessage': 'src/utils/isVoiceMessage.ts',
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useLocalization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* This file is only for re-exporting the `useLocalization` hook.
* It should not be used internally within the project.
*/
import { useLocalization } from '../lib/LocalizationContext';

export { useLocalization } from '../lib/LocalizationContext';
export default useLocalization;
8 changes: 7 additions & 1 deletion src/lib/LocalizationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ const LocalizationProvider = (props: LocalizationProviderProps): React.ReactElem
return <LocalizationContext.Provider value={{ ...LocalizationContextDefault, ...props }}>{children}</LocalizationContext.Provider>;
};

const useLocalization = () => React.useContext(LocalizationContext);
const useLocalization = () => {
const context = React.useContext(LocalizationContext);
if (!context) {
throw new Error('`useLocalization` hook must be used within `SendbirdProvider` that includes `LocalizationProvider`.');
}
return context;
};
export { LocalizationContext, LocalizationProvider, useLocalization };
2 changes: 2 additions & 0 deletions src/modules/Channel/context/ChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import { PublishingModuleType } from '../../internalInterfaces';
import { ChannelActionTypes } from './dux/actionTypes';
import { useMessageLayoutDirection } from '../../../hooks/useHTMLTextDirection';

export { ThreadReplySelectType } from './const'; // export for external usage

export interface MessageListParams extends Partial<SDKMessageListParams> { // make `prevResultSize` and `nextResultSize` to optional
/** @deprecated It won't work even if you activate this props */
reverse?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/GroupChannel/context/GroupChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { useMessageActions } from './hooks/useMessageActions';
import { getIsReactionEnabled } from '../../../utils/getIsReactionEnabled';
import { useMessageLayoutDirection } from '../../../hooks/useHTMLTextDirection';

export { ThreadReplySelectType } from './const'; // export for external usage

type OnBeforeHandler<T> = (params: T) => T | Promise<T>;
type MessageListQueryParamsType = Omit<MessageCollectionParams, 'filter'> & MessageFilterParams;
type MessageActions = ReturnType<typeof useMessageActions>;
Expand Down

0 comments on commit e17c99e

Please sign in to comment.