Skip to content

Commit 4a0e7c4

Browse files
committed
feat: clear list button and disabled buttons logic for apps/text-embeddings
1 parent 62bbdad commit 4a0e7c4

2 files changed

Lines changed: 97 additions & 24 deletions

File tree

apps/text-embeddings/App.tsx

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export default function App() {
100100
setTopMatches([]);
101101
};
102102

103+
const clearList = async () => {
104+
if (!model.isReady) return;
105+
try {
106+
setSentencesWithEmbeddings([]);
107+
} catch (error) {
108+
console.error('Error clearing the list:', error);
109+
}
110+
};
103111
const getModelStatusText = () => {
104112
if (model.error) {
105113
return `Oops! Error: ${model.error}`;
@@ -118,18 +126,16 @@ export default function App() {
118126
>
119127
<ScrollView contentContainerStyle={styles.scrollContainer}>
120128
<Text style={styles.heading}>Text Embeddings Playground</Text>
121-
122129
<Text style={styles.sectionTitle}>{getModelStatusText()}</Text>
123130

124131
<View style={styles.card}>
125-
<Text style={styles.sectionTitle}>Existing Sentences</Text>
132+
<Text style={styles.sectionTitle}>List of Existing Sentences</Text>
126133
{sentencesWithEmbeddings.map((item, index) => (
127134
<Text key={index} style={styles.sentenceText}>
128135
- {item.sentence}
129136
</Text>
130137
))}
131138
</View>
132-
133139
<View style={styles.card}>
134140
<Text style={styles.sectionTitle}>Try Your Sentence</Text>
135141
<TextInput
@@ -139,24 +145,80 @@ export default function App() {
139145
onChangeText={setInputSentence}
140146
multiline
141147
/>
142-
143-
<View style={styles.buttonGroup}>
148+
<View style={styles.buttonContainer}>
144149
<TouchableOpacity
145150
onPress={checkSimilarities}
146-
style={styles.buttonPrimary}
147-
>
148-
<Ionicons name="search" size={16} color="white" />
149-
<Text style={styles.buttonText}> Find Similar</Text>
150-
</TouchableOpacity>
151-
<TouchableOpacity
152-
onPress={addToSentences}
153-
style={styles.buttonSecondary}
151+
style={[
152+
styles.buttonPrimary,
153+
!inputSentence && styles.buttonDisabled,
154+
]}
155+
disabled={!inputSentence}
154156
>
155-
<Ionicons name="add-circle-outline" size={16} color="navy" />
156-
<Text style={styles.buttonTextOutline}> Add to List</Text>
157+
<Ionicons
158+
name="search"
159+
size={16}
160+
color={!inputSentence ? 'gray' : 'white'}
161+
/>
162+
<Text
163+
style={[
164+
styles.buttonText,
165+
!inputSentence && styles.buttonTextDisabled,
166+
]}
167+
>
168+
Find Similar
169+
</Text>
157170
</TouchableOpacity>
171+
<View style={styles.buttonGroup}>
172+
<TouchableOpacity
173+
onPress={addToSentences}
174+
style={[
175+
styles.buttonSecondary,
176+
!inputSentence && styles.buttonDisabled,
177+
]}
178+
disabled={!inputSentence}
179+
>
180+
<Ionicons
181+
name="add-circle-outline"
182+
size={16}
183+
color={!inputSentence ? 'gray' : 'navy'}
184+
/>
185+
<Text
186+
style={[
187+
styles.buttonTextOutline,
188+
!inputSentence && styles.buttonTextDisabled,
189+
]}
190+
>
191+
Add to List
192+
</Text>
193+
</TouchableOpacity>
194+
<TouchableOpacity
195+
onPress={clearList}
196+
style={[
197+
styles.buttonSecondary,
198+
sentencesWithEmbeddings.length === 0 &&
199+
styles.buttonDisabled,
200+
]}
201+
disabled={sentencesWithEmbeddings.length === 0}
202+
>
203+
<Ionicons
204+
name="close-outline"
205+
size={16}
206+
color={
207+
sentencesWithEmbeddings.length === 0 ? 'gray' : 'navy'
208+
}
209+
/>
210+
<Text
211+
style={[
212+
styles.buttonTextOutline,
213+
sentencesWithEmbeddings.length === 0 &&
214+
styles.buttonTextDisabled,
215+
]}
216+
>
217+
Clear List
218+
</Text>
219+
</TouchableOpacity>
220+
</View>
158221
</View>
159-
160222
{topMatches.length > 0 && (
161223
<View style={styles.topMatchesContainer}>
162224
<Text style={styles.sectionTitle}>Top Matches</Text>
@@ -220,6 +282,10 @@ const styles = StyleSheet.create({
220282
minHeight: 40,
221283
textAlignVertical: 'top',
222284
},
285+
buttonContainer: {
286+
width: '100%',
287+
gap: 10,
288+
},
223289
buttonGroup: {
224290
flexDirection: 'row',
225291
justifyContent: 'space-between',
@@ -245,6 +311,10 @@ const styles = StyleSheet.create({
245311
alignItems: 'center',
246312
justifyContent: 'center',
247313
},
314+
buttonDisabled: {
315+
backgroundColor: '#f0f0f0',
316+
borderColor: '#d3d3d3',
317+
},
248318
buttonText: {
249319
color: 'white',
250320
textAlign: 'center',
@@ -255,6 +325,9 @@ const styles = StyleSheet.create({
255325
textAlign: 'center',
256326
fontWeight: '500',
257327
},
328+
buttonTextDisabled: {
329+
color: 'gray',
330+
},
258331
topMatchesContainer: {
259332
marginTop: 20,
260333
},

apps/text-embeddings/ios/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PODS:
22
- boost (1.84.0)
33
- DoubleConversion (1.1.6)
4-
- EXConstants (17.1.5):
4+
- EXConstants (17.1.6):
55
- ExpoModulesCore
6-
- Expo (53.0.9):
6+
- Expo (53.0.11):
77
- DoubleConversion
88
- ExpoModulesCore
99
- glog
@@ -38,7 +38,7 @@ PODS:
3838
- ExpoModulesCore
3939
- ExpoKeepAwake (14.1.4):
4040
- ExpoModulesCore
41-
- ExpoModulesCore (2.3.13):
41+
- ExpoModulesCore (2.4.0):
4242
- DoubleConversion
4343
- glog
4444
- hermes-engine
@@ -1999,19 +1999,19 @@ EXTERNAL SOURCES:
19991999
SPEC CHECKSUMS:
20002000
boost: 7e761d76ca2ce687f7cc98e698152abd03a18f90
20012001
DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb
2002-
EXConstants: a1112af878fddfe6acc0399473ac56a07ced0f47
2003-
Expo: a9fc723f6c8f673f0e7e036c9021772d3a1a0707
2002+
EXConstants: 9f310f44bfedba09087042756802040e464323c0
2003+
Expo: 4e8bda07d30b024b1732f87843a5349a3ecc1316
20042004
ExpoAsset: 3bc9adb7dbbf27ae82c18ca97eb988a3ae7e73b1
20052005
ExpoFileSystem: c36eb8155eb2381c83dda7dc210e3eec332368b6
20062006
ExpoFont: abbb91a911eb961652c2b0a22eef801860425ed6
20072007
ExpoKeepAwake: bf0811570c8da182bfb879169437d4de298376e7
2008-
ExpoModulesCore: 5d37821c36f3781dcd0ea9a393800c90eaa6259d
2008+
ExpoModulesCore: d431ffe83c8673d02cb38425594a5f5480fd3061
20092009
fast_float: 06eeec4fe712a76acc9376682e4808b05ce978b6
20102010
FBLazyVector: 84b955f7b4da8b895faf5946f73748267347c975
20112011
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
20122012
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
20132013
hermes-engine: 314be5250afa5692b57b4dd1705959e1973a8ebe
2014-
opencv-rne: 2305807573b6e29c8c87e3416ab096d09047a7a0
2014+
opencv-rne: 63e933ae2373fc91351f9a348dc46c3f523c2d3f
20152015
RCT-Folly: e78785aa9ba2ed998ea4151e314036f6c49e6d82
20162016
RCTDeprecation: 83ffb90c23ee5cea353bd32008a7bca100908f8c
20172017
RCTRequired: eb7c0aba998009f47a540bec9e9d69a54f68136e
@@ -2043,7 +2043,7 @@ SPEC CHECKSUMS:
20432043
React-logger: 8edfcedc100544791cd82692ca5a574240a16219
20442044
React-Mapbuffer: c3f4b608e4a59dd2f6a416ef4d47a14400194468
20452045
React-microtasksnativemodule: 054f34e9b82f02bd40f09cebd4083828b5b2beb6
2046-
react-native-executorch: 4ee7537b9840b13ff8ee178affba1b2c73b5dc2a
2046+
react-native-executorch: a8c94a990bfdd03caf0f468948c0d5efdca0e1be
20472047
React-NativeModulesApple: 2c4377e139522c3d73f5df582e4f051a838ff25e
20482048
React-oscompat: ef5df1c734f19b8003e149317d041b8ce1f7d29c
20492049
React-perflogger: 9a151e0b4c933c9205fd648c246506a83f31395d

0 commit comments

Comments
 (0)