mirror of
https://github.com/balzack/databag.git
synced 2025-05-05 07:55:15 +00:00
support editing message
This commit is contained in:
parent
9711227e9d
commit
6ddb9055c0
@ -40,8 +40,10 @@ export function Contacts({openRegistry, openContact}: {openRegistry: () => void;
|
|||||||
<TextInput
|
<TextInput
|
||||||
dense={true}
|
dense={true}
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
|
outlineColor="transparent"
|
||||||
|
activeOutlineColor="transparent"
|
||||||
autoCapitalize={false}
|
autoCapitalize={false}
|
||||||
unserlineStyle={styles.inputUnderline}
|
underlineStyle={styles.inputUnderline}
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
placeholder={state.strings.contacts}
|
placeholder={state.strings.contacts}
|
||||||
left={<TextInput.Icon style={styles.icon} icon="magnify" />}
|
left={<TextInput.Icon style={styles.icon} icon="magnify" />}
|
||||||
|
@ -59,6 +59,8 @@ export function Content({openConversation}: {openConversation: ()=>void}) {
|
|||||||
style={styles.input}
|
style={styles.input}
|
||||||
autoCapitalize={false}
|
autoCapitalize={false}
|
||||||
unserlineStyle={styles.inputUnderline}
|
unserlineStyle={styles.inputUnderline}
|
||||||
|
outlineColor="transparent"
|
||||||
|
activeOutlineColor="transparent"
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
placeholder={state.strings.topics}
|
placeholder={state.strings.topics}
|
||||||
left={<TextInput.Icon style={styles.icon} icon="magnify" />}
|
left={<TextInput.Icon style={styles.icon} icon="magnify" />}
|
||||||
|
@ -119,5 +119,52 @@ export const styles = StyleSheet.create({
|
|||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
backgroundColor: 'yellow',
|
backgroundColor: 'yellow',
|
||||||
}
|
},
|
||||||
|
message: {
|
||||||
|
width: '100%',
|
||||||
|
fontSize: 14,
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
modal: {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
editArea: {
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex',
|
||||||
|
alignItem: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
width:'80%',
|
||||||
|
maxWidth: 400,
|
||||||
|
padding: 16,
|
||||||
|
borderRadius: 8,
|
||||||
|
},
|
||||||
|
blur: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
},
|
||||||
|
closeIcon: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: 20,
|
||||||
|
paddingLeft: 4,
|
||||||
|
paddingBottom: 4,
|
||||||
|
},
|
||||||
|
controls: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
paddingTop: 16,
|
||||||
|
gap: 8,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useRef, useEffect, useState, useCallback } from 'react';
|
import { useRef, useEffect, useState, useCallback } from 'react';
|
||||||
import { avatar } from '../constants/Icons'
|
import { avatar } from '../constants/Icons'
|
||||||
import { Pressable, ScrollView, View, Image } from 'react-native';
|
import { Pressable, ScrollView, View, Image, Modal } from 'react-native';
|
||||||
import {Icon, Text, IconButton, Surface, Divider} from 'react-native-paper';
|
import {Icon, Text, TextInput, IconButton, Button, Surface, Divider} from 'react-native-paper';
|
||||||
import { Topic, Card, Profile } from 'databag-client-sdk';
|
import { Topic, Card, Profile } from 'databag-client-sdk';
|
||||||
import { ImageAsset } from './imageAsset/ImageAsset';
|
import { ImageAsset } from './imageAsset/ImageAsset';
|
||||||
import { AudioAsset } from './audioAsset/AudioAsset';
|
import { AudioAsset } from './audioAsset/AudioAsset';
|
||||||
@ -12,6 +12,7 @@ import {styles} from './Message.styled';
|
|||||||
import { MediaAsset } from '../conversation/Conversatin';
|
import { MediaAsset } from '../conversation/Conversatin';
|
||||||
import { Confirm } from '../confirm/Confirm';
|
import { Confirm } from '../confirm/Confirm';
|
||||||
import { Shimmer } from './shimmer/Shimmer';
|
import { Shimmer } from './shimmer/Shimmer';
|
||||||
|
import {BlurView} from '@react-native-community/blur';
|
||||||
|
|
||||||
export function Message({ topic, card, profile, host, select, selected }: { topic: Topic, card: Card | null, profile: Profile | null, host: boolean, select: (id: null | string)=>void, selected: string }) {
|
export function Message({ topic, card, profile, host, select, selected }: { topic: Topic, card: Card | null, profile: Profile | null, host: boolean, select: (id: null | string)=>void, selected: string }) {
|
||||||
const { state, actions } = useMessage();
|
const { state, actions } = useMessage();
|
||||||
@ -37,6 +38,10 @@ export function Message({ topic, card, profile, host, select, selected }: { topi
|
|||||||
setTimeout(() => setShowAsset(true), 2000);
|
setTimeout(() => setShowAsset(true), 2000);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setEditText(text);
|
||||||
|
}, [text]);
|
||||||
|
|
||||||
const loaded = () => {
|
const loaded = () => {
|
||||||
loadedCount.current += 1;
|
loadedCount.current += 1;
|
||||||
if (loadedCount.current >= assets.length) {
|
if (loadedCount.current >= assets.length) {
|
||||||
@ -44,6 +49,23 @@ export function Message({ topic, card, profile, host, select, selected }: { topi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const edit = () => {
|
||||||
|
setEditing(true);
|
||||||
|
select(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
const save = async () => {
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
await actions.saveSubject(topic.topicId, topic.sealed, {...topic.data, text: editText});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
showError();
|
||||||
|
}
|
||||||
|
setSaving(false);
|
||||||
|
setEditing(false);
|
||||||
|
}
|
||||||
|
|
||||||
const block = () => {
|
const block = () => {
|
||||||
setConfirmParams({
|
setConfirmParams({
|
||||||
title: state.strings.blockMessage,
|
title: state.strings.blockMessage,
|
||||||
@ -175,11 +197,7 @@ export function Message({ topic, card, profile, host, select, selected }: { topi
|
|||||||
</View>
|
</View>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<View style={styles.padding}>
|
<View style={styles.padding}>
|
||||||
{ !locked && status === 'confirmed' && editing && (
|
{ !locked && status === 'confirmed' && text && (
|
||||||
<View style={styles.editing}>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
{ !locked && status === 'confirmed' && text && !editing && (
|
|
||||||
<Text style={{ ...styles.text, ...textStyle }}>{ text }</Text>
|
<Text style={{ ...styles.text, ...textStyle }}>{ text }</Text>
|
||||||
)}
|
)}
|
||||||
{ !locked && status !== 'confirmed' && (
|
{ !locked && status !== 'confirmed' && (
|
||||||
@ -212,7 +230,7 @@ export function Message({ topic, card, profile, host, select, selected }: { topi
|
|||||||
<IconButton style={styles.option} loading={false} compact="true" mode="contained" icon="share-variant-outline" size={24} onPress={() => {}} />
|
<IconButton style={styles.option} loading={false} compact="true" mode="contained" icon="share-variant-outline" size={24} onPress={() => {}} />
|
||||||
)}
|
)}
|
||||||
{ !locked && profile && (
|
{ !locked && profile && (
|
||||||
<IconButton style={styles.option} loading={false} compact="true" mode="contained" icon="square-edit-outline" size={24} onPress={() => {}} />
|
<IconButton style={styles.option} loading={false} compact="true" mode="contained" icon="square-edit-outline" size={24} onPress={edit} />
|
||||||
)}
|
)}
|
||||||
{ (host || profile) && (
|
{ (host || profile) && (
|
||||||
<IconButton style={styles.option} loading={removing} compact="true" mode="contained" icon="trash-can-outline" size={24} onPress={remove} />
|
<IconButton style={styles.option} loading={removing} compact="true" mode="contained" icon="trash-can-outline" size={24} onPress={remove} />
|
||||||
@ -227,6 +245,30 @@ export function Message({ topic, card, profile, host, select, selected }: { topi
|
|||||||
)}
|
)}
|
||||||
<Divider style={styles.border} />
|
<Divider style={styles.border} />
|
||||||
<Confirm show={confirmShow} busy={removing || reporting || blocking} params={confirmParams} />
|
<Confirm show={confirmShow} busy={removing || reporting || blocking} params={confirmParams} />
|
||||||
|
<Modal animationType="fade" transparent={true} supportedOrientations={['portrait', 'landscape']} visible={editing} onRequestClose={()=>setEditing(false)}>
|
||||||
|
<View style={styles.modal}>
|
||||||
|
<Pressable style={styles.blur} onPress={()=>setEditing(false)}>
|
||||||
|
<BlurView style={styles.blur} blurType="dark" blurAmount={6} reducedTransparencyFallbackColor="dark" />
|
||||||
|
</Pressable>
|
||||||
|
<Surface elevation={2} style={styles.editArea}>
|
||||||
|
<Text style={styles.title}>{ state.strings.edit }</Text>
|
||||||
|
<TextInput multiline={true} mode="outlined" style={styles.message}
|
||||||
|
outlineColor="transparent" activeOutlineColor="transparent" spellcheck={false}
|
||||||
|
autoComplete="off" autoCapitalize="none" autoCorrect={false} placeholder={state.strings.newMessage}
|
||||||
|
value={editText} onChangeText={value => setEditText(value)} />
|
||||||
|
<View style={styles.controls}>
|
||||||
|
<Button mode="outlined" onPress={()=>setEditing(false)}>
|
||||||
|
{state.strings.cancel}
|
||||||
|
</Button>
|
||||||
|
<Button mode="contained" loading={saving} onPress={save}>
|
||||||
|
{state.strings.save}
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
<IconButton style={styles.closeIcon} icon="close" compact="true" mode="contained" size={24} onPress={()=>setEditing(false)} />
|
||||||
|
</Surface>
|
||||||
|
</View>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ export function Registry({close, openContact}: {close: () => void; openContact:
|
|||||||
dense={true}
|
dense={true}
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
autoCapitalize={false}
|
autoCapitalize={false}
|
||||||
|
outlineColor="transparent"
|
||||||
|
activeOutlineColor="transparent"
|
||||||
underlineStyle={styles.inputUnderline}
|
underlineStyle={styles.inputUnderline}
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
placeholder={state.strings.username}
|
placeholder={state.strings.username}
|
||||||
@ -32,6 +34,8 @@ export function Registry({close, openContact}: {close: () => void; openContact:
|
|||||||
dense={true}
|
dense={true}
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
autoCapitalize={false}
|
autoCapitalize={false}
|
||||||
|
outlineColor="transparent"
|
||||||
|
activeOutlineColor="transparent"
|
||||||
underlineStyle={styles.inputUnderline}
|
underlineStyle={styles.inputUnderline}
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
placeholder={state.strings.node}
|
placeholder={state.strings.node}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user