Skip to content

Commit 47d7020

Browse files
feat: save quick replies to the userpref
1 parent e1af190 commit 47d7020

File tree

7 files changed

+98
-0
lines changed

7 files changed

+98
-0
lines changed

app/i18n/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"abac_removed_user_from_the_room": "was removed by ABAC",
1919
"ABAC_room_attributes": "Room attributes",
2020
"accept": "Accept",
21+
"WatchOS_Quick_Replies_Description":"Enter Quick Replies to Display on Apple Watch",
2122
"Accessibility": "Accessibility",
2223
"Accessibility_and_Appearance": "Accessibility & appearance",
2324
"Accessibility_statement": "Accessibility statement",
@@ -33,6 +34,7 @@
3334
"Add_server": "Add workspace",
3435
"Add_thread_reply": "Add thread reply",
3536
"Add_users": "Add users",
37+
"Add_Quick_Reply":"Add Quick Reply",
3638
"added__roomName__to_this_team": "added #{{roomName}} to this team",
3739
"Added__username__to_this_team": "added @{{user_added}} to this team",
3840
"Admin_Panel": "Admin panel",
@@ -977,6 +979,7 @@
977979
"Waiting_for_answer": "Waiting for answer",
978980
"Waiting_for_network": "Waiting for network...",
979981
"Waiting_for_server_connection": "Waiting for server connection",
982+
"WatchOS_Quick_Replies":"WatchOS Quick Replies",
980983
"Websocket_disabled": "Websocket is disabled for this workspace.\n{{contact}}",
981984
"What_are_you_doing_right_now": "What are you doing right now?",
982985
"Whats_the_password_for_your_certificate": "What's the password for your certificate?",

app/lib/constants/keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export const ANALYTICS_EVENTS_KEY = 'RC_ANALYTICS_EVENTS_KEY';
2525
export const TOKEN_KEY = 'reactnativemeteor_usertoken';
2626
export const CURRENT_SERVER = 'currentServer';
2727
export const CERTIFICATE_KEY = 'RC_CERTIFICATE_KEY';
28+
export const WATCHOS_QUICKREPLIES = 'RC_WATCHOS_QUICKREPIES';

app/lib/methods/userPreferences.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ class UserPreferences {
149149
this.mmkv.set(key, value);
150150
}
151151

152+
getArray<T = unknown>(key: string): T[] | null {
153+
try {
154+
const jsonString = this.mmkv.getString(key);
155+
return jsonString ? (JSON.parse(jsonString) as T[]) : null;
156+
} catch {
157+
return null;
158+
}
159+
}
160+
161+
setArray<T>(key: string, value: T[]): void {
162+
this.mmkv.set(key, JSON.stringify(value));
163+
}
164+
152165
getAllKeys(): string[] {
153166
return this.mmkv.getAllKeys();
154167
}

app/stacks/InsideStack.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import CannedResponseDetail from '../views/CannedResponseDetail';
3636
import ProfileView from '../views/ProfileView';
3737
import UserPreferencesView from '../views/UserPreferencesView';
3838
import UserNotificationPrefView from '../views/UserNotificationPreferencesView';
39+
import UserWatchOSQuickRepliesView from '../views/UserWatchOSQuickRepliesView';
3940
import ChangePasswordView from '../views/ChangePasswordView';
4041
// Display Preferences View
4142
import DisplayPrefsView from '../views/DisplayPrefsView';
@@ -171,6 +172,7 @@ const ProfileStackNavigator = () => {
171172
<ProfileStack.Screen name='UserPreferencesView' component={UserPreferencesView} />
172173
<ProfileStack.Screen name='ChangeAvatarView' component={ChangeAvatarView} />
173174
<ProfileStack.Screen name='UserNotificationPrefView' component={UserNotificationPrefView} />
175+
<ProfileStack.Screen name='UserWatchOSQuickRepliesView' component={UserWatchOSQuickRepliesView} />
174176
<ProfileStack.Screen name='PushTroubleshootView' component={PushTroubleshootView} />
175177
<ProfileStack.Screen name='PickerView' component={PickerView} />
176178
</ProfileStack.Navigator>

app/stacks/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export type ProfileStackParamList = {
191191
ProfileView: undefined;
192192
UserPreferencesView: undefined;
193193
UserNotificationPrefView: undefined;
194+
UserWatchOSQuickRepliesView: undefined;
194195
PushTroubleshootView: undefined;
195196
ChangeAvatarView: {
196197
context: TChangeAvatarViewContext;

app/views/UserPreferencesView/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Ele
116116
/>
117117
<List.Separator />
118118
</List.Section>
119+
<List.Section title='WatchOS_Quick_Replies'>
120+
<List.Separator />
121+
<List.Item
122+
title='WatchOS_Quick_Replies'
123+
onPress={() => navigateToScreen('UserWatchOSQuickRepliesView')}
124+
showActionIndicator
125+
testID='preferences-view-watchos-quickreplies'
126+
/>
127+
<List.Separator />
128+
</List.Section>
119129
</List.Container>
120130
</SafeAreaView>
121131
);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { type NativeStackNavigationProp } from '@react-navigation/native-stack';
2+
import React, { useEffect, useState } from 'react';
3+
import { ScrollView } from 'react-native-gesture-handler';
4+
5+
import I18n from '../../i18n';
6+
import SafeAreaView from '../../containers/SafeAreaView';
7+
import * as List from '../../containers/List';
8+
import { type ProfileStackParamList } from '../../stacks/types';
9+
import { FormTextInput } from '../../containers/TextInput';
10+
import Chip from '../../containers/Chip';
11+
import { useUserPreferences } from '../../lib/methods/userPreferences';
12+
import { WATCHOS_QUICKREPLIES } from '../../lib/constants/keys';
13+
14+
interface IUserPreferencesViewProps {
15+
navigation: NativeStackNavigationProp<ProfileStackParamList, 'UserPreferencesView'>;
16+
}
17+
18+
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
19+
const [quickreplies, setQuickreplies] = useUserPreferences<string[]>(WATCHOS_QUICKREPLIES, []);
20+
const [input, setInput] = useState<string>('');
21+
22+
useEffect(() => {
23+
navigation.setOptions({
24+
title: I18n.t('Preferences')
25+
});
26+
}, [navigation]);
27+
28+
const removeQuickReply = (reply: string) => {
29+
const newReplies = quickreplies?.filter(quickreply => quickreply !== reply);
30+
setQuickreplies(newReplies);
31+
};
32+
33+
const addQuickReply = () => {
34+
const value = input.trim();
35+
if (!value) return;
36+
if (!quickreplies?.includes(input.trim())) setQuickreplies([...(quickreplies ?? []), value]);
37+
setInput('');
38+
};
39+
40+
return (
41+
<SafeAreaView testID='preferences-view'>
42+
<List.Container>
43+
<List.Section title='WatchOS_Quick_Replies'>
44+
<>
45+
{quickreplies && quickreplies.length !== 0 && (
46+
<ScrollView horizontal style={{ marginVertical: 8, paddingHorizontal: 4 }}>
47+
{quickreplies.map((reply, index) => (
48+
<Chip key={index} text={reply} onPress={() => removeQuickReply(reply)} />
49+
))}
50+
</ScrollView>
51+
)}
52+
</>
53+
<List.Separator />
54+
<FormTextInput
55+
value={input}
56+
onChangeText={text => setInput(text)}
57+
placeholder={I18n.t('Add_Quick_Reply')}
58+
onSubmitEditing={addQuickReply}
59+
/>
60+
<List.Separator />
61+
<List.Info info='WatchOS_Quick_Replies_Description' />
62+
</List.Section>
63+
</List.Container>
64+
</SafeAreaView>
65+
);
66+
};
67+
68+
export default UserPreferencesView;

0 commit comments

Comments
 (0)