mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 09:00:06 +00:00
connecting shared asset to selected channel
This commit is contained in:
parent
b30ff56093
commit
0d09122c3f
@ -30,6 +30,10 @@ export function Content({share, closeAll, openConversation, textCard}: { share:
|
||||
const cards = state.sealSet && sealedTopic ? state.sealable : state.connected;
|
||||
|
||||
const select = (cardId: string, channelId: string) => {
|
||||
if (share) {
|
||||
const { filePath, mimeType } = share;
|
||||
actions.setSharing({ cardId, channelId, filePath, mimeType });
|
||||
}
|
||||
actions.setFocus(cardId, channelId);
|
||||
openConversation();
|
||||
}
|
||||
|
@ -234,6 +234,7 @@ export function useContent() {
|
||||
}, []);
|
||||
|
||||
const actions = {
|
||||
setSharing: app.actions.setSharing,
|
||||
setFilter: (filter: string) => {
|
||||
updateState({filter});
|
||||
},
|
||||
|
@ -50,6 +50,7 @@ export function useAppContext() {
|
||||
fullDayTime: false,
|
||||
monthFirstDate: true,
|
||||
initialized: false,
|
||||
sharing: null as null | { cardId: string, channelId: string, filePath: string, mimeType: string },
|
||||
});
|
||||
|
||||
const updateState = (value: any) => {
|
||||
@ -186,6 +187,12 @@ export function useAppContext() {
|
||||
adminLogout: async () => {
|
||||
updateState({service: null});
|
||||
},
|
||||
setSharing: (sharing: { cardId: string, channelId: string, filePath: string, mimeType: string }) => {
|
||||
updateState({ sharing });
|
||||
},
|
||||
clearSharing: () => {
|
||||
updateState({ sharing: null });
|
||||
},
|
||||
};
|
||||
|
||||
return {state, actions};
|
||||
|
@ -190,6 +190,10 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD
|
||||
const padStyle = state.layout === 'large' ? styles.pad : styles.nopad;
|
||||
const inputPadStyle = state.layout === 'large' ? styles.pad : styles.indent;
|
||||
const offset = state.layout === 'large' ? state.avoid - 64 : state.avoid - 120;
|
||||
const disableImage = !state.detailSet || !state.detail.enableImage;
|
||||
const disableVideo = !state.detailSet || !state.detail.enableVideo;
|
||||
const disableAudio = !state.detailSet || !state.detail.enableAudio;
|
||||
const disableBinary = !state.detailSet || !state.detail.enableBinary;
|
||||
|
||||
return (
|
||||
<View style={containerStyle}>
|
||||
@ -299,10 +303,10 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD
|
||||
{ avoid && (<View style={{ ...styles.avoid, height: offset }} />) }
|
||||
|
||||
<View style={styles.controls}>
|
||||
<Pressable style={styles.control} onPress={addImage}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="camera" size={24} color={Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} onPress={addVideo}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="video-outline" size={24} color={Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} onPress={addAudio}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="volume-high" size={24} color={Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} onPress={addBinary}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="file-outline" size={24} color={Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} disabled={disableImage} onPress={addImage}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="camera" size={24} color={disableImage ? Colors.placeholder : Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} disabled={disableVideo} onPress={addVideo}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="video-outline" size={24} color={disableVideo ? Colors.placeholder : Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} disabled={disableAudio} onPress={addAudio}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="volume-high" size={24} color={disableAudio ? Colors.placeholder : Colors.primary} /></Surface></Pressable>
|
||||
<Pressable style={styles.control} disabled={disableBinary} onPress={addBinary}><Surface style={styles.surface} elevation={2} mode="flat"><Icon style={styles.button} source="file-outline" size={24} color={disableBinary ? Colors.placeholder : Colors.primary} /></Surface></Pressable>
|
||||
<Divider style={styles.separator} />
|
||||
<Pressable style={styles.control} onPress={()=>setColorMenu(true)}>
|
||||
<Surface style={styles.surface} elevation={2} mode="flat">
|
||||
@ -331,10 +335,10 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD
|
||||
{ sending && (
|
||||
<ActivityIndicator size="small" />
|
||||
)}
|
||||
{ !sending && state.access && (state.message || state.assets.length != 0) && (
|
||||
{ !sending && state.access && state.validShare && (state.message || state.assets.length != 0) && (
|
||||
<Icon style={styles.button} source="send" size={24} color={Colors.primary} />
|
||||
)}
|
||||
{ !sending && (!state.access || (!state.message && state.assets.length == 0)) && (
|
||||
{ !sending && (!state.access || !state.validShare || (!state.message && state.assets.length == 0)) && (
|
||||
<Icon style={styles.button} source="send" size={24} color={Colors.placeholder} />
|
||||
)}
|
||||
</Surface>
|
||||
|
@ -63,6 +63,7 @@ export function useConversation() {
|
||||
textSizeSet: false,
|
||||
progress: 0,
|
||||
avoid: 0,
|
||||
validShare: true,
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@ -77,6 +78,48 @@ export function useConversation() {
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let validShare = true;
|
||||
state.assets.forEach(asset => {
|
||||
if (!state.detailSet) {
|
||||
validShare = false;
|
||||
} else {
|
||||
if (asset.type === 'image' && !state.detail.enableImage) {
|
||||
validShare = false;
|
||||
} else if (asset.type === 'audio' && !state.detail.enableAudio) {
|
||||
validShare = false;
|
||||
} else if (asset.type === 'video' && !state.detail.enableVideo) {
|
||||
validShare = false;
|
||||
} else if (!state.detail.enableBinary) {
|
||||
validShare = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
updateState({ validShare });
|
||||
}, [state.detail, state.detailSet, state.assets]);
|
||||
|
||||
useEffect(() => {
|
||||
const { sharing, focus } = app.state;
|
||||
if (sharing && focus && state.loaded) {
|
||||
const focused = focus.getFocused();
|
||||
if (focused.cardId == sharing.cardId && focused.channelId == sharing.channelId) {
|
||||
console.log("APPLY SHARING OF: ", sharing);
|
||||
const { mimeType, filePath } = sharing;
|
||||
const ext = mimeType.toLowerCase();
|
||||
if (ext == '.jpg' || ext == '.png' || ext == '.webp' || ext == '.bmp') {
|
||||
actions.addImage(filePath, mimeType, IMAGE_SCALE_SIZE);
|
||||
} else if (ext == '.mp4' || ext == '.mov') {
|
||||
actions.addVideo(filePath, mimeType);
|
||||
} else if (ext == '.mp3' || ext == '.aac') {
|
||||
actions.addAudio(filePath, mimeType);
|
||||
} else {
|
||||
actions.addBinary(filePath, filePath.split('/').pop());
|
||||
}
|
||||
app.actions.clearSharing();
|
||||
}
|
||||
}
|
||||
}, [app.state, state.loaded]);
|
||||
|
||||
useEffect(() => {
|
||||
const { layout, strings } = display.state
|
||||
updateState({ layout, strings })
|
||||
@ -301,6 +344,7 @@ export function useConversation() {
|
||||
}
|
||||
},
|
||||
addImage: (path: string, mime: string, size: number) => {
|
||||
console.log("ADD IMAGE");
|
||||
const type = 'image';
|
||||
updateState({ assets: [ ...state.assets, { type, path, mime, size } ]});
|
||||
},
|
||||
|
@ -15,6 +15,7 @@ export function Selector({ share, selected, channels }: { share: { filePath: str
|
||||
|
||||
useEffect(() => {
|
||||
if (share) {
|
||||
setTopic(null);
|
||||
setShow(true);
|
||||
}
|
||||
}, [share]);
|
||||
|
Loading…
Reference in New Issue
Block a user