mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 10:05:19 +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} />;
|
||||
}
|
||||
|
||||
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 {state, actions} = useContacts();
|
||||
const [alert, setAlert] = useState(false);
|
||||
@ -74,17 +74,13 @@ export function Contacts({openRegistry, openContact}: {openRegistry: () => void;
|
||||
key="call"
|
||||
icon="phone-outline"
|
||||
color={Colors.connected}
|
||||
select={async () => {
|
||||
await new Promise(r => setTimeout(r, 2000)); //call contact
|
||||
}}
|
||||
select={()=>callContact(item.cardId)}
|
||||
/>,
|
||||
<Action
|
||||
key="text"
|
||||
icon="message-outline"
|
||||
color={Colors.connected}
|
||||
select={async () => {
|
||||
await new Promise(r => setTimeout(r, 2000)); //text contact
|
||||
}}
|
||||
select={()=>textContact(item.cardId)}
|
||||
/>,
|
||||
];
|
||||
} 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 {SafeAreaView, Modal, FlatList, View} from 'react-native';
|
||||
import {styles} from './Content.styled';
|
||||
@ -9,7 +9,7 @@ import {BlurView} from '@react-native-community/blur';
|
||||
import {Card} from '../card/Card';
|
||||
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 [adding, setAdding] = 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;
|
||||
|
||||
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 () => {
|
||||
setAdding(true);
|
||||
try {
|
||||
|
@ -229,6 +229,26 @@ export function useContent() {
|
||||
setFocus: async (cardId: string | null, channelId: string) => {
|
||||
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[]) => {
|
||||
const content = app.state.session.getContent()
|
||||
if (sealed) {
|
||||
|
@ -31,12 +31,18 @@ export function Session() {
|
||||
const {state} = useSession();
|
||||
const scheme = useColorScheme();
|
||||
const [tab, setTab] = useState('content');
|
||||
const [textCard, setTextCard] = useState({ cardId: null} as {cardId: null|string});
|
||||
|
||||
const sessionNav = {strings: state.strings};
|
||||
const showContent = {display: tab === 'content' ? 'flex' : 'none'};
|
||||
const showContact = {display: tab === 'contacts' ? 'flex' : 'none'};
|
||||
const showSettings = {display: tab === 'settings' ? 'flex' : 'none'};
|
||||
|
||||
const textContact = (cardId: null|string) => {
|
||||
setTextCard({ cardId });
|
||||
setTab('content')
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.session}>
|
||||
{state.layout !== 'large' && (
|
||||
@ -48,14 +54,14 @@ export function Session() {
|
||||
...styles.body,
|
||||
...showContent,
|
||||
}}>
|
||||
<ContentTab scheme={scheme} />
|
||||
<ContentTab textCard={textCard} scheme={scheme} />
|
||||
</View>
|
||||
<View
|
||||
style={{
|
||||
...styles.body,
|
||||
...showContact,
|
||||
}}>
|
||||
<ContactTab scheme={scheme} />
|
||||
<ContactTab textContact={textContact} scheme={scheme} />
|
||||
</View>
|
||||
<View
|
||||
style={{
|
||||
@ -157,13 +163,13 @@ export function Session() {
|
||||
);
|
||||
}
|
||||
|
||||
function ContentTab({scheme}: {scheme: string}) {
|
||||
function ContentTab({scheme, textCard}: {scheme: string, textCard: {cardId: null|string}}) {
|
||||
return (
|
||||
<NavigationContainer theme={scheme === 'dark' ? DarkTheme : DefaultTheme}>
|
||||
<ContentStack.Navigator initialRouteName="contacts" screenOptions={{headerShown: false}}>
|
||||
<ContentStack.Screen name="content" options={{headerBackTitleVisible: false}}>
|
||||
{props => (
|
||||
<Content openConversation={()=>props.navigation.navigate('conversation')} />
|
||||
<Content textCard={textCard} openConversation={()=>props.navigation.navigate('conversation')} />
|
||||
)}
|
||||
</ContentStack.Screen>
|
||||
<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({
|
||||
guid: '',
|
||||
} as ContactParams);
|
||||
@ -198,6 +204,8 @@ function ContactTab({scheme}: {scheme: string}) {
|
||||
setContactParams(params);
|
||||
props.navigation.navigate('profile');
|
||||
}}
|
||||
callContact={(cardId: string)=>console.log("CALL: ", cardId)}
|
||||
textContact={textContact}
|
||||
/>
|
||||
)}
|
||||
</ContactStack.Screen>
|
||||
@ -301,6 +309,7 @@ function RegistryScreen({nav}) {
|
||||
}
|
||||
|
||||
function ContactsScreen({nav}) {
|
||||
const [textCard, setTextCard] = useState({ cardId: null} as {cardId: null|string});
|
||||
const ContactsComponent = useCallback(
|
||||
() => (
|
||||
<Surface elevation={1}>
|
||||
@ -309,6 +318,8 @@ function ContactsScreen({nav}) {
|
||||
openContact={(params: ContactParams) => {
|
||||
nav.openContact(params, nav.profile.openDrawer);
|
||||
}}
|
||||
callContact={(cardId: string)=>console.log('CALL: ', cardId)}
|
||||
textContact={(cardId: null|string)=>setTextCard({ cardId })}
|
||||
/>
|
||||
</Surface>
|
||||
),
|
||||
@ -325,7 +336,7 @@ function ContactsScreen({nav}) {
|
||||
drawerType: 'front',
|
||||
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>
|
||||
);
|
||||
}
|
||||
@ -357,6 +368,7 @@ function SettingsScreen({nav}) {
|
||||
|
||||
function HomeScreen({nav}) {
|
||||
const [focus, setFocus] = useState(false);
|
||||
const [textCard, setTextCard] = useState({ cardId: null} as {cardId: null|string});
|
||||
|
||||
return (
|
||||
<View style={styles.frame}>
|
||||
@ -365,7 +377,7 @@ function HomeScreen({nav}) {
|
||||
<Identity openSettings={nav.settings.openDrawer} openContacts={nav.contacts.openDrawer} />
|
||||
</Surface>
|
||||
<Surface style={styles.channels} elevation={1} mode="flat">
|
||||
<Content openConversation={()=>setFocus(true)} />
|
||||
<Content textCard={nav.textCard} openConversation={()=>setFocus(true)} />
|
||||
</Surface>
|
||||
</View>
|
||||
<View style={styles.right}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user