From c907285d780749582b51fe844227426fb6bf7586 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 25 Feb 2020 17:35:04 +0200 Subject: [PATCH] Journal sharing: support sharing journals as read-only. --- src/Journals/JournalMemberAddDialog.tsx | 36 +++++++++++++++++-------- src/Journals/JournalMembers.tsx | 4 +-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Journals/JournalMemberAddDialog.tsx b/src/Journals/JournalMemberAddDialog.tsx index 1b9e5f6..13356e8 100644 --- a/src/Journals/JournalMemberAddDialog.tsx +++ b/src/Journals/JournalMemberAddDialog.tsx @@ -1,6 +1,8 @@ import * as React from 'react'; 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 ConfirmationDialog from '../widgets/ConfirmationDialog'; @@ -14,7 +16,7 @@ import { handleInputChange } from '../helpers'; interface PropsType { etesync: CredentialsData; info: EteSync.CollectionInfo; - onOk: (user: string, publicKey: string) => void; + onOk: (user: string, publicKey: string, readOnly: boolean) => void; onClose: () => void; } @@ -22,6 +24,7 @@ class JournalMemberAddDialog extends React.PureComponent { public state = { addUser: '', publicKey: '', + readOnly: false, userChosen: false, error: undefined as Error | undefined, }; @@ -88,14 +91,25 @@ class JournalMemberAddDialog extends React.PureComponent { {userChosen ? : - + <> + + this.setState({ readOnly: event.target.checked })} + /> + } + label="Read only?" + /> + } @@ -124,8 +138,8 @@ class JournalMemberAddDialog extends React.PureComponent { } private onOk() { - const { addUser, publicKey } = this.state; - this.props.onOk(addUser, publicKey); + const { addUser, publicKey, readOnly } = this.state; + this.props.onOk(addUser, publicKey, readOnly); } } diff --git a/src/Journals/JournalMembers.tsx b/src/Journals/JournalMembers.tsx index 6e85b03..f28d5d5 100644 --- a/src/Journals/JournalMembers.tsx +++ b/src/Journals/JournalMembers.tsx @@ -150,7 +150,7 @@ class JournalMembers extends React.PureComponent { }); } - private onMemberAdd(user: string, publicKey: string) { + private onMemberAdd(user: string, publicKey: string, readOnly: boolean) { const { etesync, syncJournal, userInfo } = this.props; const journal = syncJournal.journal; const derived = this.props.etesync.encryptionKey; @@ -164,7 +164,7 @@ class JournalMembers extends React.PureComponent { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; 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.setState({