From 82092bbe57ff326cf1059ffd0e01897ccd8916dd Mon Sep 17 00:00:00 2001 From: balzack Date: Mon, 4 Sep 2023 21:37:10 -0700 Subject: [PATCH] adding blocked modals --- app/mobile/src/constants/Colors.js | 5 +-- app/mobile/src/constants/Strings.js | 12 +++++++ app/mobile/src/context/useCardContext.hook.js | 6 ++-- .../src/session/contact/useContact.hook.js | 2 +- app/mobile/src/session/settings/Settings.jsx | 31 ++++++++++++++-- .../src/session/settings/Settings.styled.js | 27 ++++++++++++++ .../src/session/settings/useSettings.hook.js | 35 +++++++++++++++++++ 7 files changed, 110 insertions(+), 8 deletions(-) diff --git a/app/mobile/src/constants/Colors.js b/app/mobile/src/constants/Colors.js index e0407bc3..44a8aa5b 100644 --- a/app/mobile/src/constants/Colors.js +++ b/app/mobile/src/constants/Colors.js @@ -42,6 +42,7 @@ const LightColors = { errorIndicator: '#ffaaaa', horizontalDivider: '#bbbbbb', verticalDivider: '#aaaaaa', + itemDivider: '#eeeeee', unreadIndicator: '#00aa00', enabledIndicator: '#8fbea7', disabledIndicator: '#eeeeee', @@ -91,6 +92,7 @@ const DarkColors = { errorIndicator: '#ffaaaa', horizontalDivider: '#888888', verticalDivider: '#aaaaaa', + itemDivider: '#eeeeee', unreadIndicator: '#00aa00', enabledIndicator: '#8fbea7', disabledIndicator: '#eeeeee', @@ -144,6 +146,7 @@ export const Colors = { errorIndicator: getColor('errorIndicator'), horizontalDivider: getColor('horizontalDivider'), verticalDivider: getColor('verticalDivider'), + itemDivider: getColor('itemDivider'), unreadIndicator: getColor('unreadIndicator'), enabledIndicator: getColor('enabledIndicator'), disabledIndicator: getColor('disabledIndicator'), @@ -165,14 +168,12 @@ export const Colors = { enabled: '#444444', lightgrey: '#bbbbbb', disabled: '#aaaaaa', - text: '#444444', link: '#0077CC', lightText: '#686868', active: '#222222', idle: '#707070', - itemDivider: '#eeeeee', connected: '#4488FF', connecting: '#dd88ff', diff --git a/app/mobile/src/constants/Strings.js b/app/mobile/src/constants/Strings.js index 27cf8324..85fbfc4d 100644 --- a/app/mobile/src/constants/Strings.js +++ b/app/mobile/src/constants/Strings.js @@ -67,6 +67,9 @@ const Strings = [ blockedMessages: 'Blocked Messages', restoreMessage: 'Restore Message?', close: 'Close', + noBlockedContacts: 'No Blocked Contacts', + noBlockedTopics: 'No Blocked Topics', + noBlockedMessages: 'No Blocked Messages', }, { visibleRegistry: 'Visible dans le Registre', @@ -131,6 +134,9 @@ const Strings = [ blockedMessages: 'Messages Bloqués', restoreMessage: 'Restaurer le Message?', close: 'Fermer', + noBlockedContacts: 'Aucun Contacts Bloqués', + noBlockedTopics: 'Aucun Sujet Bloqué', + noBlockedMessages: 'Aucun Message Bloqué', }, { visibleRegistry: 'Visible en el Registro', @@ -195,6 +201,9 @@ const Strings = [ blockedMessages: 'Mensajes Bloqueados', restoreMessage: 'Restaurar Mensaje?', close: 'Cerrar', + noBlockedContacts: 'No Hay ContactosBbloqueados', + noBlockedTopics: 'No Hay Temas Bloqueados ', + noBlockedMessages: 'No Hay Mensajes Bloqueados', }, { visibleRegistry: 'Sichtbar in der Registrierung', @@ -259,6 +268,9 @@ const Strings = [ blockedMessages: 'Blockierte Nachrichten', restoreMessage: 'Nachricht Wiederherstellen?', close: 'Schließen', + noBlockedContacts: 'Keine Blockierten Kontakte', + noBlockedTopics: 'Keine Blockierten Themen', + noBlockedMessages: 'Keine Blockierten Nachrichten', } ]; diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index 06699208..d386d2dd 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -424,7 +424,7 @@ export function useCardContext() { return await getContactChannelTopic(node, cardToken, channelId, topicId); }, setContactRevision: async (cardId, revision) => { - const { guid } = acccess.current || {}; + const { guid } = access.current || {}; await store.actions.setCardRequestStatus(guid, { revision }); updateState({ viewRevision: revision }); }, @@ -449,12 +449,12 @@ export function useCardContext() { setCardChannelField(cardId, channelId, 'topicMarker', marker, 'syncRevision', revision); }, setCardFlag: async (cardId) => { - const { guid } = acccess.current || {}; + const { guid } = access.current || {}; await store.actions.setCardItemBlocked(guid, cardId); setCardField(cardId, 'blocked', true); }, clearCardFlag: async (cardId) => { - const { guid } = acccess.current || {}; + const { guid } = access.current || {}; await store.actions.clearCardItemBlocked(guid, cardId); setCardField(cardId, 'blocked', false); }, diff --git a/app/mobile/src/session/contact/useContact.hook.js b/app/mobile/src/session/contact/useContact.hook.js index 5d789597..d217a6af 100644 --- a/app/mobile/src/session/contact/useContact.hook.js +++ b/app/mobile/src/session/contact/useContact.hook.js @@ -147,7 +147,7 @@ export function useContact(contact) { }, blockContact: async () => { await applyAction(async () => { - await card.actions.setCardBlocked(state.cardId); + await card.actions.setCardFlag(state.cardId); }); }, reportContact: async () => { diff --git a/app/mobile/src/session/settings/Settings.jsx b/app/mobile/src/session/settings/Settings.jsx index 8f6441e4..29790e08 100644 --- a/app/mobile/src/session/settings/Settings.jsx +++ b/app/mobile/src/session/settings/Settings.jsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { Linking, ActivityIndicator, KeyboardAvoidingView, Modal, ScrollView, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native'; +import { Linking, ActivityIndicator, FlatList, KeyboardAvoidingView, Modal, ScrollView, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native'; import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'; import { useNavigate } from 'react-router-dom'; import { styles } from './Settings.styled'; @@ -8,6 +8,7 @@ import MatIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import Colors from 'constants/Colors'; import { BlurView } from "@react-native-community/blur"; import { FloatingLabelInput } from 'react-native-floating-label-input'; +import { Logo } from 'utils/Logo'; export function Settings() { @@ -46,6 +47,9 @@ export function Settings() { } } + const unblockContact = (cardId) => { + }; + const logout = async () => { if (!busy) { try { @@ -99,6 +103,18 @@ export function Settings() { } } + const BlockedContact = ({ item }) => { + return ( + unblockContact(item.cardId)}> + + + { item.name } + { item.handle } + + + ) + } + return ( @@ -614,7 +630,18 @@ export function Settings() { { state.strings.blockedContacts } - + + { state.contacts.length === 0 && ( + { state.strings.noBlockContacts } + )} + { state.contacts.length !== 0 && ( + item.cardId} + /> + )} + { state.strings.close } diff --git a/app/mobile/src/session/settings/Settings.styled.js b/app/mobile/src/session/settings/Settings.styled.js index 04031392..fbe8ad27 100644 --- a/app/mobile/src/session/settings/Settings.styled.js +++ b/app/mobile/src/session/settings/Settings.styled.js @@ -324,5 +324,32 @@ export const styles = StyleSheet.create({ borderColor: Colors.horizontalDivider, display: 'flex' }, + item: { + width: '100%', + display: 'flex', + flexDirection: 'row', + height: 48, + paddingLeft: 16, + alignItems: 'center', + borderBottomWidth: 1, + borderColor: Colors.itemDivider, + }, + detail: { + paddingLeft: 12, + display: 'flex', + flexDirection: 'column', + justifyContent: 'center', + flexGrow: 1, + flexShrink: 1, + }, + name: { + color: Colors.text, + fontSize: 14, + }, + handle: { + color: Colors.text, + fontSize: 12, + }, + }); diff --git a/app/mobile/src/session/settings/useSettings.hook.js b/app/mobile/src/session/settings/useSettings.hook.js index 866fe93d..e36c0681 100644 --- a/app/mobile/src/session/settings/useSettings.hook.js +++ b/app/mobile/src/session/settings/useSettings.hook.js @@ -2,6 +2,7 @@ import { useState, useEffect, useRef, useContext } from 'react'; import { getLanguageStrings } from 'constants/Strings'; import { ProfileContext } from 'context/ProfileContext'; import { AccountContext } from 'context/AccountContext'; +import { CardContext } from 'context/CardContext'; import { AppContext } from 'context/AppContext'; import { generateSeal, updateSeal, unlockSeal } from 'context/sealUtil'; @@ -10,6 +11,7 @@ export function useSettings() { const profile = useContext(ProfileContext); const account = useContext(AccountContext); const app = useContext(AppContext); + const card = useContext(CardContext); const debounce = useRef(null); const checking = useRef(null); @@ -43,6 +45,10 @@ export function useSettings() { blockedContacts: false, blockedTopics: false, blockedMessages: false, + + contacts: [], + topics: [], + messages: [], }); const updateState = (value) => { @@ -63,6 +69,35 @@ export function useSettings() { updateState({ sealable, seal, sealKey, sealEnabled, sealUnlocked, pushEnabled }); }, [account.state]); + const setCardItem = (item) => { + const { profile, cardId } = item?.card || {}; + return { + cardId: cardId, + name: profile?.name, + handle: `${profile?.handle} / ${profile?.node}`, + blocked: item.card.blocked, + logo: profile?.imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar', + } + }; + + useEffect(() => { + const cards = Array.from(card.state.cards.values()); + const items = cards.map(setCardItem); + const filtered = items.filter(item => { + return item.blocked; + }); + filtered.sort((a, b) => { + if (a.name === b.name) { + return 0; + } + if (!a.name || (a.name < b.name)) { + return -1; + } + return 1; + }); + updateState({ contacts: filtered }); + }, [card.state]); + const unlockKey = async () => { const sealKey = unlockSeal(state.seal, state.sealPassword); await account.actions.unlockAccountSeal(sealKey);