Skip to content

Commit

Permalink
fix: apply strings review
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Jun 27, 2022
1 parent 28b47d5 commit a4c94e3
Show file tree
Hide file tree
Showing 31 changed files with 169 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const __domain__ContextProvider: React.FC = ({ children }) => {

return (
<ProviderLayout>
<__domain__Context.Fragment.Provider value={{ headerTitle: 'LABEL.DOMAIN.HEADER_TITLE' }}>
<__domain__Context.Fragment.Provider value={{ headerTitle: 'STRINGS.DOMAIN.HEADER_TITLE' }}>
{children}
</__domain__Context.Fragment.Provider>
</ProviderLayout>
Expand Down
20 changes: 10 additions & 10 deletions packages/uikit-react-native-core/src/contexts/Localization.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import React, { useContext, useState } from 'react';

import type { LabelLocale, LabelSet } from '../localization/label.type';
import type { StringsLocale, StringSet } from '../localization/StringSet.type';

type Props<T extends string = LabelLocale['locale']> = {
type Props<T extends string = StringsLocale['locale']> = {
defaultLocale: T;
labelSet: Record<T, LabelSet>;
stringSets: Record<T, StringSet>;
children?: React.ReactNode;
};

type Context<T extends string = LabelLocale['locale']> = {
LABEL: LabelSet;
type Context<T extends string = StringsLocale['locale']> = {
STRINGS: StringSet;
locale: T;
setLocale: React.Dispatch<T>;
};

export const LocalizationContext = React.createContext<Context | null>(null);
export const LocalizationProvider = ({ children, labelSet, defaultLocale }: Props) => {
export const LocalizationProvider = ({ children, stringSets, defaultLocale }: Props) => {
const [locale, setLocale] = useState(defaultLocale);
const LABEL = labelSet[locale];
if (!LABEL) throw new Error(`Invalid Locale(${locale}) or LabelSet(${Object.keys(labelSet).join()})`);
return <LocalizationContext.Provider value={{ LABEL, locale, setLocale }}>{children}</LocalizationContext.Provider>;
const STRINGS = stringSets[locale];
if (!STRINGS) throw new Error(`Invalid Locale(${locale}) or StringSet(${Object.keys(stringSets).join()})`);
return <LocalizationContext.Provider value={{ STRINGS, locale, setLocale }}>{children}</LocalizationContext.Provider>;
};

export const useLocalization = <T extends string = LabelLocale['locale']>() => {
export const useLocalization = <T extends string = StringsLocale['locale']>() => {
const value = useContext<Context<T> | null>(LocalizationContext as React.Context<Context<T> | null>);
if (!value) throw new Error('LocalizationContext is not provided');
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const GroupChannelHeader: React.FC<GroupChannelProps['Header']> = ({
}) => {
const { headerTitle, channel } = useContext(GroupChannelContext.Fragment);
const { typingUsers } = useContext(GroupChannelContext.TypingIndicator);
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const { currentUser } = useSendbirdChat();

if (!Header) return null;

const subtitle = LABEL.STRINGS.TYPING_INDICATOR_TYPINGS(typingUsers);
const subtitle = STRINGS.LABELS.TYPING_INDICATOR_TYPINGS(typingUsers);
return (
<Header
clearTitleMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type EditInputProps = GroupChannelProps['Input'] & {

const AUTO_FOCUS = Platform.select({ ios: false, android: true, default: false });
const EditInput: React.FC<EditInputProps> = ({ text, setText, editMessage, setEditMessage, onUpdateUserMessage }) => {
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const inputRef = useRef<RNTextInput>(null);
const toast = useToast();

Expand All @@ -35,7 +35,7 @@ const EditInput: React.FC<EditInputProps> = ({ text, setText, editMessage, setEd

const onPressSave = () => {
if (editMessage.isUserMessage()) {
onUpdateUserMessage(text, editMessage).catch(() => toast.show(LABEL.TOAST.UPDATE_MSG_ERROR, 'error'));
onUpdateUserMessage(text, editMessage).catch(() => toast.show(STRINGS.TOAST.UPDATE_MSG_ERROR, 'error'));
}
setEditMessage();
setText('');
Expand All @@ -51,16 +51,16 @@ const EditInput: React.FC<EditInputProps> = ({ text, setText, editMessage, setEd
value={text}
onChangeText={setText}
style={styles.input}
placeholder={LABEL.GROUP_CHANNEL.INPUT_PLACEHOLDER_ACTIVE}
placeholder={STRINGS.GROUP_CHANNEL.INPUT_PLACEHOLDER_ACTIVE}
/>
</View>
<View style={{ marginTop: 8, flexDirection: 'row' }}>
<Button variant={'text'} onPress={onPressCancel}>
{LABEL.GROUP_CHANNEL.INPUT_EDIT_CANCEL}
{STRINGS.GROUP_CHANNEL.INPUT_EDIT_CANCEL}
</Button>
<View style={styles.space} />
<Button variant={'contained'} onPress={onPressSave}>
{LABEL.GROUP_CHANNEL.INPUT_EDIT_OK}
{STRINGS.GROUP_CHANNEL.INPUT_EDIT_OK}
</Button>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,58 @@ type SendInputProps = GroupChannelProps['Input'] & {
disabled: boolean;
};
const SendInput: React.FC<SendInputProps> = ({ onSendUserMessage, onSendFileMessage, text, setText, disabled }) => {
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const { openSheet } = useBottomSheet();
const { fileService } = usePlatformService();
const { colors } = useUIKitTheme();
const toast = useToast();

const onPressSend = () => {
onSendUserMessage(text).catch(() => toast.show(LABEL.TOAST.SEND_MSG_ERROR, 'error'));
onSendUserMessage(text).catch(() => toast.show(STRINGS.TOAST.SEND_MSG_ERROR, 'error'));
setText('');
};
const onPressAttachment = () => {
openSheet({
sheetItems: [
{
title: LABEL.GROUP_CHANNEL.DIALOG_ATTACHMENT_CAMERA,
title: STRINGS.GROUP_CHANNEL.DIALOG_ATTACHMENT_CAMERA,
icon: 'camera',
onPress: async () => {
const photo = await fileService.openCamera({
mediaType: 'photo',
onError: () => toast.show(LABEL.TOAST.OPEN_CAMERA_ERROR, 'error'),
onError: () => toast.show(STRINGS.TOAST.OPEN_CAMERA_ERROR, 'error'),
});

if (photo) {
onSendFileMessage(photo).catch(() => toast.show(LABEL.TOAST.SEND_MSG_ERROR, 'error'));
onSendFileMessage(photo).catch(() => toast.show(STRINGS.TOAST.SEND_MSG_ERROR, 'error'));
}
},
},
{
title: LABEL.GROUP_CHANNEL.DIALOG_ATTACHMENT_PHOTO_LIBRARY,
title: STRINGS.GROUP_CHANNEL.DIALOG_ATTACHMENT_PHOTO_LIBRARY,
icon: 'photo',
onPress: async () => {
const photo = await fileService.openMediaLibrary({
selectionLimit: 1,
mediaType: 'photo',
onError: () => toast.show(LABEL.TOAST.OPEN_PHOTO_LIBRARY_ERROR, 'error'),
onError: () => toast.show(STRINGS.TOAST.OPEN_PHOTO_LIBRARY_ERROR, 'error'),
});

if (photo && photo[0]) {
onSendFileMessage(photo[0]).catch(() => toast.show(LABEL.TOAST.SEND_MSG_ERROR, 'error'));
onSendFileMessage(photo[0]).catch(() => toast.show(STRINGS.TOAST.SEND_MSG_ERROR, 'error'));
}
},
},
{
title: LABEL.GROUP_CHANNEL.DIALOG_ATTACHMENT_FILES,
title: STRINGS.GROUP_CHANNEL.DIALOG_ATTACHMENT_FILES,
icon: 'document',
onPress: async () => {
const file = await fileService.openDocument({
onError: () => toast.show(LABEL.TOAST.OPEN_FILES_ERROR, 'error'),
onError: () => toast.show(STRINGS.TOAST.OPEN_FILES_ERROR, 'error'),
});

if (file) {
onSendFileMessage(file).catch(() => toast.show(LABEL.TOAST.SEND_MSG_ERROR, 'error'));
onSendFileMessage(file).catch(() => toast.show(STRINGS.TOAST.SEND_MSG_ERROR, 'error'));
}
},
},
Expand All @@ -98,7 +98,7 @@ const SendInput: React.FC<SendInputProps> = ({ onSendUserMessage, onSendFileMess
style={styles.input}
placeholder={conditionChaining(
[disabled],
[LABEL.GROUP_CHANNEL.INPUT_PLACEHOLDER_DISABLED, LABEL.GROUP_CHANNEL.INPUT_PLACEHOLDER_ACTIVE],
[STRINGS.GROUP_CHANNEL.INPUT_PLACEHOLDER_DISABLED, STRINGS.GROUP_CHANNEL.INPUT_PLACEHOLDER_ACTIVE],
)}
/>
{Boolean(text) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const GroupChannelMessageList: React.FC<GroupChannelProps['MessageList']> = ({
flatListProps,
enableMessageGrouping,
}) => {
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const { colors } = useUIKitTheme();
const { left, right } = useSafeAreaInsets();
const [scrollLeaveBottom, setScrollLeaveBottom] = useState(false);
Expand Down Expand Up @@ -92,7 +92,7 @@ const GroupChannelMessageList: React.FC<GroupChannelProps['MessageList']> = ({
return (
<View style={[{ flex: 1, backgroundColor: colors.background }, safeAreaLayout]}>
{channel.isFrozen && (
<ChannelFrozenBanner style={styles.frozenBanner} text={LABEL.GROUP_CHANNEL.LIST_BANNER_FROZEN} />
<ChannelFrozenBanner style={styles.frozenBanner} text={STRINGS.GROUP_CHANNEL.LIST_BANNER_FROZEN} />
)}
<ChatFlatList
nextMessages={nextMessages}
Expand Down Expand Up @@ -142,7 +142,7 @@ const useGetMessagePressActions = ({
'onDeleteMessage' | 'onResendFailedMessage' | 'onPressImageMessage' | 'currentUserId'
>) => {
const { colors } = useUIKitTheme();
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const toast = useToast();
const { openSheet } = useBottomSheet();
const { alert } = useAlert();
Expand All @@ -153,11 +153,12 @@ const useGetMessagePressActions = ({
openSheet({
sheetItems: [
{
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_FAILED_RETRY,
onPress: () => onResendFailedMessage(message).catch(() => toast.show(LABEL.TOAST.RESEND_MSG_ERROR, 'error')),
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_FAILED_RETRY,
onPress: () =>
onResendFailedMessage(message).catch(() => toast.show(STRINGS.TOAST.RESEND_MSG_ERROR, 'error')),
},
{
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_FAILED_REMOVE,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_FAILED_REMOVE,
titleColor: colors.ui.dialog.default.none.destructive,
onPress: () => confirmDelete(message),
},
Expand All @@ -166,15 +167,15 @@ const useGetMessagePressActions = ({
};
const confirmDelete = (message: HandleableMessage) => {
alert({
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_TITLE,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_TITLE,
buttons: [
{
text: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL,
text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL,
},
{
text: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_OK,
text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_OK,
style: 'destructive',
onPress: () => onDeleteMessage(message).catch(() => toast.show(LABEL.TOAST.DELETE_MSG_ERROR, 'error')),
onPress: () => onDeleteMessage(message).catch(() => toast.show(STRINGS.TOAST.DELETE_MSG_ERROR, 'error')),
},
],
});
Expand All @@ -194,23 +195,23 @@ const useGetMessagePressActions = ({
if (msg.isUserMessage()) {
sheetItems.push({
icon: 'copy',
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_COPY,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_COPY,
onPress: () => {
clipboardService.setString(msg.message || '');
toast.show(LABEL.TOAST.COPY_OK, 'success');
toast.show(STRINGS.TOAST.COPY_OK, 'success');
},
});

if (isMyMessage(msg, currentUserId) && msg.sendingStatus === 'succeeded') {
sheetItems.push(
{
icon: 'edit',
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_EDIT,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_EDIT,
onPress: () => setEditMessage(msg),
},
{
icon: 'delete',
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE,
onPress: () => confirmDelete(msg),
},
);
Expand All @@ -220,20 +221,20 @@ const useGetMessagePressActions = ({
if (msg.isFileMessage()) {
sheetItems.push({
icon: 'download',
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_SAVE,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_SAVE,
onPress: async () => {
if (toMegabyte(msg.size) > 4) {
toast.show(LABEL.TOAST.DOWNLOAD_START, 'success');
toast.show(STRINGS.TOAST.DOWNLOAD_START, 'success');
}

fileService
.save(msg.url, msg.name)
.then((response) => {
toast.show(LABEL.TOAST.DOWNLOAD_OK, 'success');
toast.show(STRINGS.TOAST.DOWNLOAD_OK, 'success');
Logger.log('File saved to', response);
})
.catch((err) => {
toast.show(LABEL.TOAST.DOWNLOAD_ERROR, 'error');
toast.show(STRINGS.TOAST.DOWNLOAD_ERROR, 'error');
Logger.log('File save failure', err);
});
},
Expand All @@ -242,7 +243,7 @@ const useGetMessagePressActions = ({
if (isMyMessage(msg, currentUserId) && msg.sendingStatus === 'succeeded') {
sheetItems.push({
icon: 'delete',
title: LABEL.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE,
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE,
onPress: () => confirmDelete(msg),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const GroupChannelContextProvider: GroupChannelModule['Provider'] = ({
if (!channel) throw new Error('GroupChannel is not provided to GroupChannelModule');

const id = useUniqId('GroupChannelContextProvider');
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const { currentUser, sdk } = useSendbirdChat();

const [typingUsers, setTypingUsers] = useState<Sendbird.User[]>([]);
Expand All @@ -52,7 +52,7 @@ export const GroupChannelContextProvider: GroupChannelModule['Provider'] = ({
<ProviderLayout>
<GroupChannelContext.Fragment.Provider
value={{
headerTitle: LABEL.GROUP_CHANNEL.HEADER_TITLE(currentUser?.userId ?? '', channel),
headerTitle: STRINGS.GROUP_CHANNEL.HEADER_TITLE(currentUser?.userId ?? '', channel),
channel,
editMessage,
setEditMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { GroupChannelListProps } from '../types';

const GroupChannelListChannelMenu: React.FC<GroupChannelListProps['ChannelMenu']> = () => {
const channelMenu = useContext(GroupChannelListContext.ChannelMenu);
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const { currentUser } = useSendbirdChat();

const [visible, setVisible] = useState(false);
Expand All @@ -25,11 +25,11 @@ const GroupChannelListChannelMenu: React.FC<GroupChannelListProps['ChannelMenu']
onDismiss={channelMenu.selectChannel}
title={
channelMenu.selectedChannel &&
LABEL.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_TITLE(currentUser?.userId ?? '', channelMenu.selectedChannel)
STRINGS.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_TITLE(currentUser?.userId ?? '', channelMenu.selectedChannel)
}
menuItems={[
{
title: LABEL.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_NOTIFICATION(channelMenu.selectedChannel),
title: STRINGS.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_NOTIFICATION(channelMenu.selectedChannel),
onPress: async () => {
if (channelMenu.selectedChannel?.myPushTriggerOption === 'off') {
await channelMenu.selectedChannel?.setMyPushTriggerOption('default');
Expand All @@ -39,7 +39,7 @@ const GroupChannelListChannelMenu: React.FC<GroupChannelListProps['ChannelMenu']
},
},
{
title: LABEL.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_LEAVE,
title: STRINGS.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_LEAVE,
onPress: async () => {
await channelMenu.selectedChannel?.leave();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ const DefaultTypeIcon: React.FC<{ type: GroupChannelType }> = ({ type }) => {
};

const DefaultTypeText: React.FC<{ type: GroupChannelType }> = ({ type }) => {
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();
const { colors } = useUIKitTheme();
return (
<Text caption2 color={colors.onBackground01}>
{LABEL.GROUP_CHANNEL_LIST[`TYPE_SELECTOR_${type}`]}
{STRINGS.GROUP_CHANNEL_LIST[`TYPE_SELECTOR_${type}`]}
</Text>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const GroupChannelListContext: GroupChannelListContextType = {
};

export const GroupChannelListContextProvider: React.FC = ({ children }) => {
const { LABEL } = useLocalization();
const { STRINGS } = useLocalization();

// Type selector
const [visible, setVisible] = useState(false);
Expand All @@ -36,9 +36,9 @@ export const GroupChannelListContextProvider: React.FC = ({ children }) => {
return (
<ProviderLayout>
<GroupChannelListContext.TypeSelector.Provider
value={{ headerTitle: LABEL.GROUP_CHANNEL_LIST.TYPE_SELECTOR_HEADER_TITLE, visible, show, hide }}
value={{ headerTitle: STRINGS.GROUP_CHANNEL_LIST.TYPE_SELECTOR_HEADER_TITLE, visible, show, hide }}
>
<GroupChannelListContext.Fragment.Provider value={{ headerTitle: LABEL.GROUP_CHANNEL_LIST.HEADER_TITLE }}>
<GroupChannelListContext.Fragment.Provider value={{ headerTitle: STRINGS.GROUP_CHANNEL_LIST.HEADER_TITLE }}>
<GroupChannelListContext.ChannelMenu.Provider value={{ selectChannel, selectedChannel }}>
{children}
</GroupChannelListContext.ChannelMenu.Provider>
Expand Down
Loading

0 comments on commit a4c94e3

Please sign in to comment.