aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/DocServer.ts34
-rw-r--r--src/client/views/MainView.tsx7
2 files changed, 33 insertions, 8 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index cbcf751ee..f477b4999 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -7,16 +7,29 @@ import { RefField } from '../new_fields/RefField';
import { Id, HandleUpdate } from '../new_fields/FieldSymbols';
export namespace DocServer {
- const _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {};
+ let _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {};
const _socket = OpenSocket(`${window.location.protocol}//${window.location.hostname}:4321`);
const GUID: string = Utils.GenerateGuid();
+ let _isReadOnly = false;
export function makeReadOnly() {
+ if (_isReadOnly) return;
+ _isReadOnly = true;
_CreateField = emptyFunction;
_UpdateField = emptyFunction;
_respondToUpdate = emptyFunction;
}
+ export function makeEditable() {
+ if (!_isReadOnly) return;
+ location.reload();
+ // _isReadOnly = false;
+ // _CreateField = _CreateFieldImpl;
+ // _UpdateField = _UpdateFieldImpl;
+ // _respondToUpdate = _respondToUpdateImpl;
+ // _cache = {};
+ }
+
export function prepend(extension: string): string {
return window.location.origin + extension;
}
@@ -95,29 +108,33 @@ export namespace DocServer {
return map;
}
- let _UpdateField = (id: string, diff: any) => {
+ function _UpdateFieldImpl(id: string, diff: any) {
if (id === updatingId) {
return;
}
Utils.Emit(_socket, MessageStore.UpdateField, { id, diff });
- };
+ }
+
+ let _UpdateField = _UpdateFieldImpl;
export function UpdateField(id: string, diff: any) {
_UpdateField(id, diff);
}
- let _CreateField = (field: RefField) => {
+ function _CreateFieldImpl(field: RefField) {
_cache[field[Id]] = field;
const initialState = SerializationHelper.Serialize(field);
Utils.Emit(_socket, MessageStore.CreateField, initialState);
- };
+ }
+
+ let _CreateField = _CreateFieldImpl;
export function CreateField(field: RefField) {
_CreateField(field);
}
let updatingId: string | undefined;
- let _respondToUpdate = (diff: any) => {
+ function _respondToUpdateImpl(diff: any) {
const id = diff.id;
if (id === undefined) {
return;
@@ -139,7 +156,10 @@ export namespace DocServer {
} else {
update(field);
}
- };
+ }
+
+ let _respondToUpdate = _respondToUpdateImpl;
+
function respondToUpdate(diff: any) {
_respondToUpdate(diff);
}
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index da126fb74..204503d7f 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -13,7 +13,7 @@ import { Id } from '../../new_fields/FieldSymbols';
import { InkTool } from '../../new_fields/InkField';
import { List } from '../../new_fields/List';
import { listSpec } from '../../new_fields/Schema';
-import { Cast, FieldValue, NumCast } from '../../new_fields/Types';
+import { Cast, FieldValue, NumCast, BoolCast } from '../../new_fields/Types';
import { CurrentUserUtils } from '../../server/authentication/models/current_user_utils';
import { RouteStore } from '../../server/RouteStore';
import { emptyFunction, returnOne, returnTrue } from '../../Utils';
@@ -194,6 +194,11 @@ export class MainView extends React.Component {
openWorkspace = async (doc: Doc, fromHistory = false) => {
CurrentUserUtils.MainDocId = doc[Id];
this.mainContainer = doc;
+ if (BoolCast(doc.readOnly)) {
+ DocServer.makeReadOnly();
+ } else {
+ DocServer.makeEditable();
+ }
fromHistory || HistoryUtil.pushState({ type: "doc", docId: doc[Id], initializers: {} });
const col = await Cast(CurrentUserUtils.UserDocument.optionalRightCollection, Doc);
// if there is a pending doc, and it has new data, show it (syip: we use a timeout to prevent collection docking view from being uninitialized)