mirror of
https://github.com/balzack/databag.git
synced 2025-05-05 07:55:15 +00:00
support direct text link
This commit is contained in:
parent
f0823db3ec
commit
f5b5443c94
@ -18,7 +18,7 @@ function Action({icon, color, select}: {icon: string; color: string; select: ()
|
|||||||
return <IconButton style={styles.icon} loading={loading} iconColor={color} mode="contained" icon={icon} onPress={onPress} />;
|
return <IconButton style={styles.icon} loading={loading} iconColor={color} mode="contained" icon={icon} onPress={onPress} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Contacts({openRegistry, openContact}: {openRegistry: () => void; openContact: (params: ContactParams) => void}) {
|
export function Contacts({openRegistry, openContact, callContact, textContact}: {openRegistry: () => void; openContact: (params: ContactParams) => void, callContact: (cardId: null|string)=>void, textContact: (cardId: null|string)=>void}) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const {state, actions} = useContacts();
|
const {state, actions} = useContacts();
|
||||||
const [alert, setAlert] = useState(false);
|
const [alert, setAlert] = useState(false);
|
||||||
@ -74,17 +74,13 @@ export function Contacts({openRegistry, openContact}: {openRegistry: () => void;
|
|||||||
key="call"
|
key="call"
|
||||||
icon="phone-outline"
|
icon="phone-outline"
|
||||||
color={Colors.connected}
|
color={Colors.connected}
|
||||||
select={async () => {
|
select={()=>callContact(item.cardId)}
|
||||||
await new Promise(r => setTimeout(r, 2000)); //call contact
|
|
||||||
}}
|
|
||||||
/>,
|
/>,
|
||||||
<Action
|
<Action
|
||||||
key="text"
|
key="text"
|
||||||
icon="message-outline"
|
icon="message-outline"
|
||||||
color={Colors.connected}
|
color={Colors.connected}
|
||||||
select={async () => {
|
select={()=>textContact(item.cardId)}
|
||||||
await new Promise(r => setTimeout(r, 2000)); //text contact
|
|
||||||
}}
|
|
||||||
/>,
|
/>,
|
||||||
];
|
];
|
||||||
} else if (syncStatus === 'offsync') {
|
} else if (syncStatus === 'offsync') {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, {useState} from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import {Divider, Switch, Surface, IconButton, Button, Text, TextInput, useTheme} from 'react-native-paper';
|
import {Divider, Switch, Surface, IconButton, Button, Text, TextInput, useTheme} from 'react-native-paper';
|
||||||
import {SafeAreaView, Modal, FlatList, View} from 'react-native';
|
import {SafeAreaView, Modal, FlatList, View} from 'react-native';
|
||||||
import {styles} from './Content.styled';
|
import {styles} from './Content.styled';
|
||||||
@ -9,7 +9,7 @@ import {BlurView} from '@react-native-community/blur';
|
|||||||
import {Card} from '../card/Card';
|
import {Card} from '../card/Card';
|
||||||
import {Confirm} from '../confirm/Confirm';
|
import {Confirm} from '../confirm/Confirm';
|
||||||
|
|
||||||
export function Content({openConversation}: {openConversation: ()=>void}) {
|
export function Content({openConversation, textCard}: {openConversation: ()=>void, textCard: {cardId: null|string}}) {
|
||||||
const [add, setAdd] = useState(false);
|
const [add, setAdd] = useState(false);
|
||||||
const [adding, setAdding] = useState(false);
|
const [adding, setAdding] = useState(false);
|
||||||
const [sealedTopic, setSealedTopic] = useState(false);
|
const [sealedTopic, setSealedTopic] = useState(false);
|
||||||
@ -28,6 +28,25 @@ export function Content({openConversation}: {openConversation: ()=>void}) {
|
|||||||
});
|
});
|
||||||
const cards = state.sealSet && sealedTopic ? state.sealable : state.connected;
|
const cards = state.sealSet && sealedTopic ? state.sealable : state.connected;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (textCard.cardId) {
|
||||||
|
openTopic(textCard.cardId);
|
||||||
|
}
|
||||||
|
}, [textCard]);
|
||||||
|
|
||||||
|
const openTopic = async (cardId: string) => {
|
||||||
|
setAdding(true);
|
||||||
|
try {
|
||||||
|
const id = await actions.openTopic(cardId);
|
||||||
|
actions.setFocus(null, id);
|
||||||
|
openConversation();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setAlert(true);
|
||||||
|
}
|
||||||
|
setAdding(false);
|
||||||
|
}
|
||||||
|
|
||||||
const addTopic = async () => {
|
const addTopic = async () => {
|
||||||
setAdding(true);
|
setAdding(true);
|
||||||
try {
|
try {
|
||||||
|
@ -229,6 +229,26 @@ export function useContent() {
|
|||||||
setFocus: async (cardId: string | null, channelId: string) => {
|
setFocus: async (cardId: string | null, channelId: string) => {
|
||||||
await app.actions.setFocus(cardId, channelId);
|
await app.actions.setFocus(cardId, channelId);
|
||||||
},
|
},
|
||||||
|
openTopic: async (cardId: string) => {
|
||||||
|
const content = app.state.session.getContent()
|
||||||
|
const card = state.cards.find(card => card.cardId === cardId)
|
||||||
|
if (card) {
|
||||||
|
const sealable = card.sealable && state.sealSet;
|
||||||
|
const thread = state.sorted.find(channel => {
|
||||||
|
const { sealed, cardId, members} = channel;
|
||||||
|
if (sealed === sealable && cardId == null && members.length === 1 && members[0].guid === card.guid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (thread) {
|
||||||
|
return thread.channelId;
|
||||||
|
} else {
|
||||||
|
const topic = await content.addChannel(sealable, sealable ? 'sealed' : 'superbasic', {}, [cardId]);
|
||||||
|
return topic.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
addTopic: async (sealed: boolean, subject: string, contacts: string[]) => {
|
addTopic: async (sealed: boolean, subject: string, contacts: string[]) => {
|
||||||
const content = app.state.session.getContent()
|
const content = app.state.session.getContent()
|
||||||
if (sealed) {
|
if (sealed) {
|
||||||
|
@ -31,12 +31,18 @@ export function Session() {
|
|||||||
const {state} = useSession();
|
const {state} = useSession();
|
||||||
const scheme = useColorScheme();
|
const scheme = useColorScheme();
|
||||||
const [tab, setTab] = useState('content');
|
const [tab, setTab] = useState('content');
|
||||||
|
const [textCard, setTextCard] = useState({ cardId: null} as {cardId: null|string});
|
||||||
|
|
||||||
const sessionNav = {strings: state.strings};
|
const sessionNav = {strings: state.strings};
|
||||||
const showContent = {display: tab === 'content' ? 'flex' : 'none'};
|
const showContent = {display: tab === 'content' ? 'flex' : 'none'};
|
||||||
const showContact = {display: tab === 'contacts' ? 'flex' : 'none'};
|
const showContact = {display: tab === 'contacts' ? 'flex' : 'none'};
|
||||||
const showSettings = {display: tab === 'settings' ? 'flex' : 'none'};
|
const showSettings = {display: tab === 'settings' ? 'flex' : 'none'};
|
||||||
|
|
||||||
|
const textContact = (cardId: null|string) => {
|
||||||
|
setTextCard({ cardId });
|
||||||
|
setTab('content')
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.session}>
|
<View style={styles.session}>
|
||||||
{state.layout !== 'large' && (
|
{state.layout !== 'large' && (
|
||||||
@ -48,14 +54,14 @@ export function Session() {
|
|||||||
...styles.body,
|
...styles.body,
|
||||||
...showContent,
|
...showContent,
|
||||||
}}>
|
}}>
|
||||||
<ContentTab scheme={scheme} />
|
<ContentTab textCard={textCard} scheme={scheme} />
|
||||||
</View>
|
</View>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
...styles.body,
|
...styles.body,
|
||||||
...showContact,
|
...showContact,
|
||||||
}}>
|
}}>
|
||||||
<ContactTab scheme={scheme} />
|
<ContactTab textContact={textContact} scheme={scheme} />
|
||||||
</View>
|
</View>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
@ -157,13 +163,13 @@ export function Session() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ContentTab({scheme}: {scheme: string}) {
|
function ContentTab({scheme, textCard}: {scheme: string, textCard: {cardId: null|string}}) {
|
||||||
return (
|
return (
|
||||||
<NavigationContainer theme={scheme === 'dark' ? DarkTheme : DefaultTheme}>
|
<NavigationContainer theme={scheme === 'dark' ? DarkTheme : DefaultTheme}>
|
||||||
<ContentStack.Navigator initialRouteName="contacts" screenOptions={{headerShown: false}}>
|
<ContentStack.Navigator initialRouteName="contacts" screenOptions={{headerShown: false}}>
|
||||||
<ContentStack.Screen name="content" options={{headerBackTitleVisible: false}}>
|
<ContentStack.Screen name="content" options={{headerBackTitleVisible: false}}>
|
||||||
{props => (
|
{props => (
|
||||||
<Content openConversation={()=>props.navigation.navigate('conversation')} />
|
<Content textCard={textCard} openConversation={()=>props.navigation.navigate('conversation')} />
|
||||||
)}
|
)}
|
||||||
</ContentStack.Screen>
|
</ContentStack.Screen>
|
||||||
<ContentStack.Screen name="conversation"
|
<ContentStack.Screen name="conversation"
|
||||||
@ -180,7 +186,7 @@ function ContentTab({scheme}: {scheme: string}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ContactTab({scheme}: {scheme: string}) {
|
function ContactTab({scheme, textContact}: {scheme: string, textContact: (cardId: null|string)=>void}) {
|
||||||
const [contactParams, setContactParams] = useState({
|
const [contactParams, setContactParams] = useState({
|
||||||
guid: '',
|
guid: '',
|
||||||
} as ContactParams);
|
} as ContactParams);
|
||||||
@ -198,6 +204,8 @@ function ContactTab({scheme}: {scheme: string}) {
|
|||||||
setContactParams(params);
|
setContactParams(params);
|
||||||
props.navigation.navigate('profile');
|
props.navigation.navigate('profile');
|
||||||
}}
|
}}
|
||||||
|
callContact={(cardId: string)=>console.log("CALL: ", cardId)}
|
||||||
|
textContact={textContact}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</ContactStack.Screen>
|
</ContactStack.Screen>
|
||||||
@ -301,6 +309,7 @@ function RegistryScreen({nav}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ContactsScreen({nav}) {
|
function ContactsScreen({nav}) {
|
||||||
|
const [textCard, setTextCard] = useState({ cardId: null} as {cardId: null|string});
|
||||||
const ContactsComponent = useCallback(
|
const ContactsComponent = useCallback(
|
||||||
() => (
|
() => (
|
||||||
<Surface elevation={1}>
|
<Surface elevation={1}>
|
||||||
@ -309,6 +318,8 @@ function ContactsScreen({nav}) {
|
|||||||
openContact={(params: ContactParams) => {
|
openContact={(params: ContactParams) => {
|
||||||
nav.openContact(params, nav.profile.openDrawer);
|
nav.openContact(params, nav.profile.openDrawer);
|
||||||
}}
|
}}
|
||||||
|
callContact={(cardId: string)=>console.log('CALL: ', cardId)}
|
||||||
|
textContact={(cardId: null|string)=>setTextCard({ cardId })}
|
||||||
/>
|
/>
|
||||||
</Surface>
|
</Surface>
|
||||||
),
|
),
|
||||||
@ -325,7 +336,7 @@ function ContactsScreen({nav}) {
|
|||||||
drawerType: 'front',
|
drawerType: 'front',
|
||||||
headerShown: false,
|
headerShown: false,
|
||||||
}}>
|
}}>
|
||||||
<ContactsDrawer.Screen name="settings">{({navigation}) => <SettingsScreen nav={{...nav, contacts: navigation}} />}</ContactsDrawer.Screen>
|
<ContactsDrawer.Screen name="settings">{({navigation}) => <SettingsScreen nav={{...nav, textCard, contacts: navigation}} />}</ContactsDrawer.Screen>
|
||||||
</ContactsDrawer.Navigator>
|
</ContactsDrawer.Navigator>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -357,6 +368,7 @@ function SettingsScreen({nav}) {
|
|||||||
|
|
||||||
function HomeScreen({nav}) {
|
function HomeScreen({nav}) {
|
||||||
const [focus, setFocus] = useState(false);
|
const [focus, setFocus] = useState(false);
|
||||||
|
const [textCard, setTextCard] = useState({ cardId: null} as {cardId: null|string});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.frame}>
|
<View style={styles.frame}>
|
||||||
@ -365,7 +377,7 @@ function HomeScreen({nav}) {
|
|||||||
<Identity openSettings={nav.settings.openDrawer} openContacts={nav.contacts.openDrawer} />
|
<Identity openSettings={nav.settings.openDrawer} openContacts={nav.contacts.openDrawer} />
|
||||||
</Surface>
|
</Surface>
|
||||||
<Surface style={styles.channels} elevation={1} mode="flat">
|
<Surface style={styles.channels} elevation={1} mode="flat">
|
||||||
<Content openConversation={()=>setFocus(true)} />
|
<Content textCard={nav.textCard} openConversation={()=>setFocus(true)} />
|
||||||
</Surface>
|
</Surface>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.right}>
|
<View style={styles.right}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user