Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/693f3576-eaf4-8011-9c02-8476c83275fd
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Paste this below AdminScreen (or anywhere in the file beneath imports) : ==== <syntaxhighlight lang="js">function AdminUsersPanel() { const [emailQuery, setEmailQuery] = useState(""); const [loading, setLoading] = useState(false); const [results, setResults] = useState([]); // [{id, email, role}] const searchByExactEmail = async () => { const q = emailQuery.trim().toLowerCase(); if (!q) { Alert.alert("Enter an email", "Type the user's email address to search."); return; } setLoading(true); try { // exact-match query (fast + index-free) const qy = query(collection(db, "users"), where("email", "==", q)); const snap = await getDocs(qy); const found = snap.docs.map((d) => ({ id: d.id, ...d.data() })); setResults(found); if (!found.length) { Alert.alert("No match", "No user found with that email.\n\nThey must create an account first."); } } catch (e) { Alert.alert("Search error", e?.message ?? "Could not search users."); } finally { setLoading(false); } }; const setRoleForUser = async (uid, newRole) => { try { await updateDoc(doc(db, "users", uid), { role: newRole }); setResults((prev) => prev.map((u) => (u.id === uid ? { ...u, role: newRole } : u))); Alert.alert("Updated", <code>Role set to "${newRole}".</code>); } catch (e) { Alert.alert("Update failed", e?.message ?? "Could not update role."); } }; return ( <View style={{ flex: 1 }}> <Text style={[styles.sectionTitle, { marginTop: 14 }]}>User promotion</Text> <View style={styles.card}> <Text style={styles.hint}> Search by exact email (the same email they used to sign up). Then promote/demote. </Text> <Text style={styles.label}>User email</Text> <TextInput value={emailQuery} onChangeText={setEmailQuery} placeholder="umpire@example.com" autoCapitalize="none" keyboardType="email-address" style={styles.input} /> <Button title={loading ? "Searching…" : "Search"} onPress={searchByExactEmail} disabled={loading} /> </View> <Text style={[styles.sectionTitle, { marginTop: 14 }]}>Results</Text> <FlatList data={results} keyExtractor={(item) => item.id} ListEmptyComponent={<Text style={styles.hint}>No results yet.</Text>} renderItem={({ item }) => ( <View style={styles.listRow}> <Text style={styles.listRowTitle}>{item.email || item.id}</Text> <Text style={styles.listRowSub}>Current role: {item.role || "umpire"}</Text> <View style={styles.roleButtonRow}> <Pressable onPress={() => setRoleForUser(item.id, "admin")} style={[styles.roleButton, styles.roleButtonPrimary]} > <Text style={styles.roleButtonTextPrimary}>Make Admin</Text> </Pressable> <Pressable onPress={() => setRoleForUser(item.id, "umpire")} style={[styles.roleButton, styles.roleButtonSecondary]} > <Text style={styles.roleButtonTextSecondary}>Make Umpire</Text> </Pressable> </View> </View> )} /> </View> ); } </syntaxhighlight>
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)