Journal sharing: support sharing journals as read-only.

master
Tom Hacohen 5 years ago
parent 8e790ed666
commit c907285d78

@ -1,6 +1,8 @@
import * as React from 'react'; import * as React from 'react';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import Checkbox from '@material-ui/core/Checkbox';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import LoadingIndicator from '../widgets/LoadingIndicator'; import LoadingIndicator from '../widgets/LoadingIndicator';
import ConfirmationDialog from '../widgets/ConfirmationDialog'; import ConfirmationDialog from '../widgets/ConfirmationDialog';
@ -14,7 +16,7 @@ import { handleInputChange } from '../helpers';
interface PropsType { interface PropsType {
etesync: CredentialsData; etesync: CredentialsData;
info: EteSync.CollectionInfo; info: EteSync.CollectionInfo;
onOk: (user: string, publicKey: string) => void; onOk: (user: string, publicKey: string, readOnly: boolean) => void;
onClose: () => void; onClose: () => void;
} }
@ -22,6 +24,7 @@ class JournalMemberAddDialog extends React.PureComponent<PropsType> {
public state = { public state = {
addUser: '', addUser: '',
publicKey: '', publicKey: '',
readOnly: false,
userChosen: false, userChosen: false,
error: undefined as Error | undefined, error: undefined as Error | undefined,
}; };
@ -88,6 +91,7 @@ class JournalMemberAddDialog extends React.PureComponent<PropsType> {
{userChosen ? {userChosen ?
<LoadingIndicator /> <LoadingIndicator />
: :
<>
<TextField <TextField
name="addUser" name="addUser"
type="email" type="email"
@ -96,6 +100,16 @@ class JournalMemberAddDialog extends React.PureComponent<PropsType> {
value={addUser} value={addUser}
onChange={this.handleInputChange} onChange={this.handleInputChange}
/> />
<FormControlLabel
control={
<Checkbox
checked={this.state.readOnly}
onChange={(event) => this.setState({ readOnly: event.target.checked })}
/>
}
label="Read only?"
/>
</>
} }
</ConfirmationDialog> </ConfirmationDialog>
</> </>
@ -124,8 +138,8 @@ class JournalMemberAddDialog extends React.PureComponent<PropsType> {
} }
private onOk() { private onOk() {
const { addUser, publicKey } = this.state; const { addUser, publicKey, readOnly } = this.state;
this.props.onOk(addUser, publicKey); this.props.onOk(addUser, publicKey, readOnly);
} }
} }

@ -150,7 +150,7 @@ class JournalMembers extends React.PureComponent<PropsTypeInner> {
}); });
} }
private onMemberAdd(user: string, publicKey: string) { private onMemberAdd(user: string, publicKey: string, readOnly: boolean) {
const { etesync, syncJournal, userInfo } = this.props; const { etesync, syncJournal, userInfo } = this.props;
const journal = syncJournal.journal; const journal = syncJournal.journal;
const derived = this.props.etesync.encryptionKey; const derived = this.props.etesync.encryptionKey;
@ -164,7 +164,7 @@ class JournalMembers extends React.PureComponent<PropsTypeInner> {
const creds = etesync.credentials; const creds = etesync.credentials;
const apiBase = etesync.serviceApiUrl; const apiBase = etesync.serviceApiUrl;
const journalMembersManager = new EteSync.JournalMembersManager(creds, apiBase, journal.uid); const journalMembersManager = new EteSync.JournalMembersManager(creds, apiBase, journal.uid);
journalMembersManager.create({ user, key: encryptedKey }).then(() => { journalMembersManager.create({ user, key: encryptedKey, readOnly }).then(() => {
this.fetchMembers(); this.fetchMembers();
}); });
this.setState({ this.setState({

Loading…
Cancel
Save