allow to set account details, cleanup
Change-Id: I6dd6589f78329e0113ee38fbaa8535abd6b37589
diff --git a/client/src/components/AccountPreferences.js b/client/src/components/AccountPreferences.js
index e14101f..7c7298d 100644
--- a/client/src/components/AccountPreferences.js
+++ b/client/src/components/AccountPreferences.js
@@ -39,6 +39,8 @@
const moderators = account.getDefaultModerators()
const [defaultModeratorUri, setDefaultModeratorUri] = useState('')
+ const [details, setDetails] = useState(account.getDetails())
+
const addModerator = () => {
if (defaultModeratorUri) {
authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${defaultModeratorUri}`, {method: "PUT"})
@@ -49,6 +51,22 @@
const removeModerator = (uri) =>
authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${uri}`, {method: "DELETE"})
+ const handleToggle = (key, value) => {
+ console.log(`handleToggle ${key} ${value}`)
+ const newDetails = {}
+ newDetails[key] = value ? "true" : "false"
+ console.log(newDetails)
+ authManager.fetch(`/api/accounts/${account.getId()}`, {
+ method: "POST",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(newDetails)
+ })
+ setDetails({...account.updateDetails(newDetails)})
+ }
+
return (
<React.Fragment>
<Typography variant="h2" component="h2" gutterBottom>{alias}</Typography>
@@ -83,8 +101,8 @@
<ListItemSecondaryAction>
<Switch
edge="end"
- /*onChange={handleToggle('wifi')}*/
- checked={account.isRendezVous()}
+ onChange={e => handleToggle('Account.rendezVous', e.target.checked)}
+ checked={details['Account.rendezVous'] === 'true'}
inputProps={{ 'aria-labelledby': 'switch-list-label-rendezvous' }}
/>
</ListItemSecondaryAction>
@@ -97,8 +115,8 @@
<ListItemSecondaryAction>
<Switch
edge="end"
- /*onChange={handleToggle('bluetooth')}*/
- checked={account.isPublicIn()}
+ onChange={e => handleToggle('DHT.PublicInCalls', e.target.checked)}
+ checked={details['DHT.PublicInCalls'] === 'true'}
inputProps={{ 'aria-labelledby': 'switch-list-label-publicin' }}
/>
</ListItemSecondaryAction>
diff --git a/client/src/components/ContactList.js b/client/src/components/ContactList.js
index ad75783..cbb64e1 100644
--- a/client/src/components/ContactList.js
+++ b/client/src/components/ContactList.js
@@ -1,16 +1,12 @@
import List from '@material-ui/core/List'
import React from 'react'
-class ContactList extends React.Component {
- render() {
- return (
- <div className="rooms-list">
- <List>
+export default function ContactList() {
+ return (
+ <div className="rooms-list">
+ <List>
- </List>
- </div>
- )
- }
+ </List>
+ </div>
+ )
}
-
-export default ContactList
\ No newline at end of file
diff --git a/client/src/components/ConversationView.js b/client/src/components/ConversationView.js
index 5c5a936..d0ab227 100644
--- a/client/src/components/ConversationView.js
+++ b/client/src/components/ConversationView.js
@@ -59,7 +59,7 @@
setState(state => {
if (state.conversation)
state.conversation.addMessage(data)
- return {...state}
+ return {...state}
})
})
}, [state.conversation ? state.conversation.getId() : "", socket])
@@ -74,9 +74,11 @@
.then(messages => {
console.log(messages)
setLoadingMesages(false)
- if (state.conversation)
+ setState(state => {
+ if (state.conversation)
state.conversation.addLoadedMessages(messages)
- setState(state)
+ return {...state}
+ })
}).catch(e => console.log(e))
return () => controller.abort()
}, [state, loadingMesages])
diff --git a/client/src/components/JamiIdCard.js b/client/src/components/JamiIdCard.js
index 1b75bc5..1ecfd94 100644
--- a/client/src/components/JamiIdCard.js
+++ b/client/src/components/JamiIdCard.js
@@ -7,7 +7,6 @@
fontSize: 14,
}, pos: {
fontSize: 14,
-
}
});
diff --git a/client/src/pages/accountSettings.jsx b/client/src/pages/accountSettings.jsx
index c685a3b..beca0fd 100644
--- a/client/src/pages/accountSettings.jsx
+++ b/client/src/pages/accountSettings.jsx
@@ -17,14 +17,17 @@
.then(result => {
console.log(result)
setState({loaded: true, account: Account.from(result)})
- })
+ }).catch(e => console.log(e))
return () => controller.abort()
}, [accountId])
return (
<Container maxWidth="sm">
<Header />
- {state.loaded ? <AccountPreferences account={state.account} /> : <CircularProgress />}
+ {state.loaded ? <AccountPreferences account={state.account} onAccontChanged={account => setState(state => {
+ state.account = account
+ return state
+ })} /> : <CircularProgress />}
</Container>
)
}