Skip to content

Commit 75ff9ff

Browse files
committed
feat: clear list button and disabled buttons logic for apps/text-embeddings
1 parent 97efa7b commit 75ff9ff

File tree

2 files changed

+306
-233
lines changed

2 files changed

+306
-233
lines changed

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
},

0 commit comments

Comments
 (0)