import React, {useState} from 'react'; import styles from '../Contacts/styles' import { Button, Checkbox, Form } from 'semantic-ui-react' import * as api from '../../api' import * as rsa from '../../crypto' export default class Tribes extends React.Component { constructor(props) { super(props) this.state = { values: {} } } async onNewTribe(v) { const name = v.tribe_name console.log("NAME",name) const r = await api.relay.POST('group',{ name, is_tribe:true, }) console.log(r) } async onSave(v) { console.log(v) const r = await api.relay.POST('tribe',{ chat_name: v.name, uuid: v.uuid, group_key: v.group_key, }) console.log(r) } onCancel() { } setValue(key, value) { let new_values = {...this.state.values} new_values[key] = value this.setState({ values: new_values }) } render() { const {chats} = this.props const tribes = chats&&chats.filter(c=>c.type===2) const {values} = this.state const fields = ['uuid','group_key','name'] const showTribes = tribes && tribes.length>0 ? true : false return

JOIN TRIBE

this.onSave(values)}> {fields.map(field => ( this.setValue(field, e.target.value)} /> ))}

CREATE NEW TRIBE

this.onNewTribe(values)}> {['tribe_name'].map(field => ( this.setValue(field, e.target.value)} /> ))}
{showTribes &&

TRIBES

{tribes.map(t=>{ return })}
}
} } function Tribe(t){ const [text,setText] = useState('') async function sendMessage(){ const encText = await rsa.encrypt(t.group_key,text) console.log(t,encText) const body = { chat_id: t.id, remote_text_map: { [t.id]: encText } } await api.relay.POST('messages', body) } return
NAME: {t.name}
UUID: {t.uuid}
KEY: {t.group_key}
setText(e.target.value)}/>
}