Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
lebalz committed Aug 7, 2024
1 parent baace70 commit d640628
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
23 changes: 13 additions & 10 deletions src/hooks/useDocumentRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ export const useDocumentRoot = <Type extends DocumentType>(id: string | undefine
)
);
const [dummyDocument] = React.useState(
CreateDocumentModel({
id: defaultDocId,
type: meta.type,
data: meta.defaultData,
authorId: 'dummy',
documentRootId: id || defaultRootDocId,
parentId: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
}, rootStore.documentStore)
CreateDocumentModel(
{
id: defaultDocId,
type: meta.type,
data: meta.defaultData,
authorId: 'dummy',
documentRootId: id || defaultRootDocId,
parentId: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
rootStore.documentStore
)
);
/**
* only run the effect after the initial render to avoid
Expand Down
7 changes: 1 addition & 6 deletions src/models/DocumentRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ class DocumentRoot<T extends DocumentType> {
@observable accessor _access: Access;
@observable accessor sharedAccess: Access;

constructor(
props: DocumentRootProps,
meta: TypeMeta<T>,
store: DocumentRootStore,
isDummy?: boolean
) {
constructor(props: DocumentRootProps, meta: TypeMeta<T>, store: DocumentRootStore, isDummy?: boolean) {
this.store = store;
this.meta = meta;
this.id = props.id;
Expand Down
2 changes: 1 addition & 1 deletion src/models/iDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ abstract class iDocument<Type extends DocumentType> {
}
return this.root.sharedAccess === Access.RW && this.root.permission === Access.RW;
}

@computed
get canDisplay() {
if (!this.root) {
Expand Down
10 changes: 6 additions & 4 deletions src/stores/DocumentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import ScriptVersion from '../models/documents/ScriptVersion';
import { ChangedDocument } from '../api/IoEventTypes';
import String from '../models/documents/String';


export function CreateDocumentModel<T extends DocumentType>(data: DocumentProps<T>, store: DocumentStore): TypeModelMapping[T];
export function CreateDocumentModel<T extends DocumentType>(
data: DocumentProps<T>,
store: DocumentStore
): TypeModelMapping[T];
export function CreateDocumentModel(data: DocumentProps<DocumentType>, store: DocumentStore): DocumentTypes {
switch (data.type) {
case DocumentType.Script:
Expand All @@ -34,7 +36,7 @@ export function CreateDocumentModel(data: DocumentProps<DocumentType>, store: Do
case DocumentType.String:
return new String(data as DocumentProps<DocumentType.String>, store);
}
};
}
class DocumentStore extends iStore {
readonly root: RootStore;
documents = observable.array<DocumentTypes>([]);
Expand Down Expand Up @@ -153,7 +155,7 @@ class DocumentStore extends iStore {
if (!model.canEdit) {
return Promise.resolve(undefined);
}
if ( model.root.permission !== Access.RW) {
if (model.root.permission !== Access.RW) {
return Promise.resolve(undefined);
}
return this.withAbortController(`save-${id}`, (sig) => {
Expand Down
3 changes: 1 addition & 2 deletions src/stores/utils/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { Primitive } from 'utility-types';
import siteConfig from '@generated/docusaurus.config';
import _ from 'lodash';


export type PersistedData = {
user?: User;
};

export const StorageKey = Object.freeze({
SessionStore: _.upperFirst(_.camelCase(`SessionStore${siteConfig.projectName}`)),
SessionStore: _.upperFirst(_.camelCase(`SessionStore${siteConfig.projectName}`))
});

/**
Expand Down

0 comments on commit d640628

Please sign in to comment.