mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
adding resync support to mobile app
This commit is contained in:
parent
95b5c82b36
commit
a1b2d5230c
@ -1,7 +1,7 @@
|
|||||||
export function getCardByGuid(cards, guid) {
|
export function getCardByGuid(cards, guid) {
|
||||||
let card = null;
|
let card = null;
|
||||||
cards.forEach((value, key, map) => {
|
cards.forEach((value, key, map) => {
|
||||||
if(value?.card.profile?.guid === guid) {
|
if(value?.card?.profile?.guid === guid) {
|
||||||
card = value;
|
card = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -110,12 +110,12 @@ export function useCardContext() {
|
|||||||
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data || {};
|
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data || {};
|
||||||
const cardRevision = { view: notifiedView, profile: notifiedProfile, artcile: notifiedArticle, channel: notifiedChannel };
|
const cardRevision = { view: notifiedView, profile: notifiedProfile, artcile: notifiedArticle, channel: notifiedChannel };
|
||||||
await syncCard(server, token, guid, entry, cardRevision);
|
await syncCard(server, token, guid, entry, cardRevision);
|
||||||
await store.action.clearCardItemOffsync(guid, cardId);
|
await store.actions.clearCardItemOffsync(guid, cardId);
|
||||||
entry.card.offsync = false;
|
entry.card.offsync = false;
|
||||||
}
|
|
||||||
|
|
||||||
cards.current.set(cardId, card);
|
cards.current.set(cardId, entry);
|
||||||
updateState({ cards: cards.current });
|
updateState({ cards: cards.current });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -24,7 +24,7 @@ export function useCards(filter, sort) {
|
|||||||
}, [account.state]);
|
}, [account.state]);
|
||||||
|
|
||||||
const setCardItem = (item) => {
|
const setCardItem = (item) => {
|
||||||
const { profile, detail, cardId } = item.card || { profile: {}, detail: {} }
|
const { profile, detail, cardId, blocked, offsync } = item.card || { profile: {}, detail: {} }
|
||||||
const { name, handle, node, guid, location, description, imageSet } = profile;
|
const { name, handle, node, guid, location, description, imageSet } = profile;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -37,9 +37,8 @@ export function useCards(filter, sort) {
|
|||||||
description: description,
|
description: description,
|
||||||
status: detail.status,
|
status: detail.status,
|
||||||
token: detail.token,
|
token: detail.token,
|
||||||
offsync: item.offsync,
|
offsync: offsync,
|
||||||
blocked: item.blocked,
|
blocked: blocked,
|
||||||
offsync: item.offsync,
|
|
||||||
updated: detail.statusUpdated,
|
updated: detail.statusUpdated,
|
||||||
logo: imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar',
|
logo: imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar',
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,21 @@ import { View } from 'react-native';
|
|||||||
import { useCardsIcon } from './useCardsIcon.hook';
|
import { useCardsIcon } from './useCardsIcon.hook';
|
||||||
import { styles } from './CardsIcon.styled';
|
import { styles } from './CardsIcon.styled';
|
||||||
import Ionicons from 'react-native-vector-icons/AntDesign';
|
import Ionicons from 'react-native-vector-icons/AntDesign';
|
||||||
|
import { useCardIcon } from './useCardIcon.hook.js';
|
||||||
|
|
||||||
export function CardsIcon({ size, color, active }) {
|
export function CardsIcon({ size, color, active }) {
|
||||||
|
|
||||||
|
const { state, actions } = useCardIcon();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<Ionicons name={'contacts'} size={size} color={color} />
|
<Ionicons name={'contacts'} size={size} color={color} />
|
||||||
|
{ state.requested && (
|
||||||
|
<View style={styles.requested} />
|
||||||
|
)}
|
||||||
|
{ state.offsync && (
|
||||||
|
<View style={styles.offsync} />
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,15 @@ export const styles = StyleSheet.create({
|
|||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
backgroundColor: Colors.pending,
|
backgroundColor: Colors.pending,
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
left: 0,
|
||||||
|
bottom: 0,
|
||||||
|
},
|
||||||
|
offsync: {
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: Colors.alert,
|
||||||
|
position: 'absolute',
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
},
|
},
|
||||||
|
35
app/mobile/src/session/cardsIcon/useCardIcon.hook.js
Normal file
35
app/mobile/src/session/cardsIcon/useCardIcon.hook.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { useState, useEffect, useContext } from 'react';
|
||||||
|
import { CardContext } from 'context/CardContext';
|
||||||
|
|
||||||
|
export function useCardIcon() {
|
||||||
|
|
||||||
|
const [state, setState] = useState({
|
||||||
|
requested: false,
|
||||||
|
offsync: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const card = useContext(CardContext);
|
||||||
|
|
||||||
|
const updateState = (value) => {
|
||||||
|
setState((s) => ({ ...s, ...value }));
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let requested = false;
|
||||||
|
let offsync = false;
|
||||||
|
card.state.cards.forEach(item => {
|
||||||
|
const status = item.card?.detail?.status;
|
||||||
|
if (status === 'pending' || status === 'requested') {
|
||||||
|
requested = true;
|
||||||
|
}
|
||||||
|
if (item.card?.offsync) {
|
||||||
|
offsync = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateState({ requested, offsync });
|
||||||
|
}, [card.state]);
|
||||||
|
|
||||||
|
const actions = {};
|
||||||
|
|
||||||
|
return { state, actions };
|
||||||
|
}
|
@ -130,6 +130,9 @@ export function useChannels() {
|
|||||||
contacts.push(entry.card);
|
contacts.push(entry.card);
|
||||||
});
|
});
|
||||||
const filtered = contacts.filter(contact => {
|
const filtered = contacts.filter(contact => {
|
||||||
|
if (contact == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (contact.detail.status !== 'connected') {
|
if (contact.detail.status !== 'connected') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -171,6 +174,7 @@ export function useChannels() {
|
|||||||
items.push({ loginTimestamp, channelId, channelItem: item });
|
items.push({ loginTimestamp, channelId, channelItem: item });
|
||||||
});
|
});
|
||||||
card.state.cards.forEach((cardItem, cardId) => {
|
card.state.cards.forEach((cardItem, cardId) => {
|
||||||
|
|
||||||
cardItem.channels.forEach((channelItem, channelId) => {
|
cardItem.channels.forEach((channelItem, channelId) => {
|
||||||
items.push({ loginTimestamp, cardId, channelId, channelItem });
|
items.push({ loginTimestamp, cardId, channelId, channelItem });
|
||||||
});
|
});
|
||||||
|
@ -286,6 +286,11 @@ export function ContactBody({ contact }) {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{ state.offsync && (
|
||||||
|
<TouchableOpacity style={styles.alert} onPress={actions.resync}>
|
||||||
|
<Text style={styles.alertText}>Resync Contact</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
@ -118,4 +118,17 @@ export const styles = StyleSheet.create({
|
|||||||
buttonText: {
|
buttonText: {
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
},
|
},
|
||||||
|
alert: {
|
||||||
|
width: 192,
|
||||||
|
padding: 6,
|
||||||
|
backgroundColor: Colors.alert,
|
||||||
|
borderRadius: 4,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: 16,
|
||||||
|
},
|
||||||
|
alertText: {
|
||||||
|
color: Colors.white,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
@ -149,7 +149,7 @@ export function useContact(contact) {
|
|||||||
await addFlag(state.node, state.guid);
|
await addFlag(state.node, state.guid);
|
||||||
},
|
},
|
||||||
resync: () => {
|
resync: () => {
|
||||||
card.actions.resync(contact.card);
|
card.actions.resyncCard(state.cardId);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user