mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 09:00:06 +00:00
added filter param to account listing
This commit is contained in:
parent
889e6b4cc7
commit
af66ac7283
@ -1,12 +1,8 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getListing(server) {
|
export async function getListing(server, filter) {
|
||||||
let host = "";
|
const param = filter ? `?filter=${filter}` : '';
|
||||||
if (server) {
|
let listing = await fetchWithTimeout(`https://${server}/account/listing${param}`, { method: 'GET' });
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let listing = await fetchWithTimeout(`${host}/account/listing`, { method: 'GET' });
|
|
||||||
checkResponse(listing);
|
checkResponse(listing);
|
||||||
return await listing.json();
|
return await listing.json();
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,20 @@ export function RegistryTitle({ state, actions }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.title}>
|
<View style={styles.title}>
|
||||||
|
{ !state.filter && (
|
||||||
|
<TouchableOpacity style={styles.sort} onPress={actions.filter}>
|
||||||
|
<Ionicons style={styles.icon} name="filter" size={18} color={Colors.disabled} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
|
{ state.filter && (
|
||||||
|
<View style={styles.filterwrapper}>
|
||||||
|
<TextInput style={styles.inputfield} value={state.username} onChangeText={actions.setUsername}
|
||||||
|
autoCorrect={false} autoCapitalize="none" placeholderTextColor={Colors.disabled} placeholder="Username" />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
<View style={styles.inputwrapper}>
|
<View style={styles.inputwrapper}>
|
||||||
<TextInput style={styles.inputfield} value={state.server} onChangeText={actions.setServer}
|
<TextInput style={styles.inputfield} value={state.server} onChangeText={actions.setServer}
|
||||||
autoCorrect={false} autoCapitalize="none" placeholderTextColor={Colors.disabled} placeholder="Server" />
|
autoCorrect={false} autoCapitalize="none" placeholderTextColor={Colors.disabled} placeholder="Server" />
|
||||||
<View style={styles.space} />
|
|
||||||
</View>
|
</View>
|
||||||
{ state.busy && (
|
{ state.busy && (
|
||||||
<View style={styles.search}>
|
<View style={styles.search}>
|
||||||
|
@ -40,6 +40,17 @@ export const styles = StyleSheet.create({
|
|||||||
paddingBottom: 8,
|
paddingBottom: 8,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
|
filterwrapper: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
alignItems: 'center',
|
||||||
|
paddingTop: 4,
|
||||||
|
paddingBottom: 4,
|
||||||
|
marginLeft: 8,
|
||||||
|
width: '25%',
|
||||||
|
},
|
||||||
inputwrapper: {
|
inputwrapper: {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
@ -100,8 +111,6 @@ export const styles = StyleSheet.create({
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
padding: 8,
|
padding: 8,
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
},
|
|
||||||
newtext: {
|
|
||||||
paddingLeft: 8,
|
paddingLeft: 8,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
},
|
},
|
||||||
|
@ -12,6 +12,8 @@ export function useRegistry() {
|
|||||||
tabbed: null,
|
tabbed: null,
|
||||||
accounts: [],
|
accounts: [],
|
||||||
server: null,
|
server: null,
|
||||||
|
filter: false,
|
||||||
|
username: null,
|
||||||
busy: false,
|
busy: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,7 +49,13 @@ export function useRegistry() {
|
|||||||
if (!state.busy) {
|
if (!state.busy) {
|
||||||
try {
|
try {
|
||||||
updateState({ busy: true });
|
updateState({ busy: true });
|
||||||
const accounts = await getListing(server, true);
|
let accounts;
|
||||||
|
if (state.filter && state.username) {
|
||||||
|
accounts = await getListing(server, state.username);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
accounts = await getListing(server);
|
||||||
|
}
|
||||||
const filtered = accounts.filter(item => {
|
const filtered = accounts.filter(item => {
|
||||||
if (item.guid === profile.state.profile.guid) {
|
if (item.guid === profile.state.profile.guid) {
|
||||||
return false;
|
return false;
|
||||||
@ -74,7 +82,13 @@ export function useRegistry() {
|
|||||||
},
|
},
|
||||||
search: async () => {
|
search: async () => {
|
||||||
await getAccounts(state.server, false);
|
await getAccounts(state.server, false);
|
||||||
}
|
},
|
||||||
|
filter: async () => {
|
||||||
|
updateState({ filter: true });
|
||||||
|
},
|
||||||
|
setUsername: async (username) => {
|
||||||
|
updateState({ username });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
Loading…
Reference in New Issue
Block a user