Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tdev/page-read-check/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { iTaskableDocument } from '@tdev-models/iTaskableDocument';
import { Document as DocumentProps, TypeDataMapping, Factory } from '@tdev-api/document';
import DocumentStore from '@tdev-stores/DocumentStore';
import { ModelMeta } from './ModelMeta';
import { mdiBookCheck, mdiBookCheckOutline, mdiBookEducation, mdiBookOpenVariantOutline } from '@mdi/js';
import { mdiBookCheck, mdiBookEducation, mdiBookOpenVariantOutline } from '@mdi/js';
import { fSeconds, fSecondsLong } from '../helpers/time';

export const createModel: Factory = (data, store) => {
Expand Down
7 changes: 4 additions & 3 deletions src/components/EditingOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from './styles.module.scss';
import { observer } from 'mobx-react-lite';
import { useStore } from '@tdev-hooks/useStore';
import Button from '@tdev-components/shared/Button';
import { mdiAccountAlert, mdiAccountSyncOutline, mdiCheckboxMultipleMarkedCircle } from '@mdi/js';
import { mdiAccountSyncOutline, mdiCheckboxMultipleMarkedCircle } from '@mdi/js';
import { StateType } from '@tdev-api/document';
import Icon from '@mdi/react';
import Popup from 'reactjs-popup';
Expand Down Expand Up @@ -62,10 +62,11 @@ const EditingOverview = observer(() => {
if (!isBrowser || !currentUser || !currentPage) {
return null;
}
const taskStates = currentPage.taskableDocuments.filter((ts) => RWAccess.has(ts.root?.permission)) || [];
if (taskStates.length === 0) {
const taskableDocumentsCount = currentPage.taskableDocumentRootIds.length;
if (taskableDocumentsCount === 0) {
return null;
}
const taskStates = currentPage.taskableDocuments.filter((ts) => RWAccess.has(ts.root?.permission)) || [];
const someChecked = taskStates.some((d) => d.isDone);
const allChecked = someChecked && taskStates.every((d) => d.isDone);
return (
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useDocumentRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export const useDocumentRoot = <Type extends DocumentType>(
() => documentRootStore.find(id),
(docRoot) => {
if (docRoot) {
if (docRoot.isLoadable && !docRoot.isLoaded) {
documentRootStore.loadInNextBatch(
id!,
meta,
{ skipCreate: !!skipCreate, documentType: loadOnlyType, documentRoot: 'replace' },
access
);
}
return;
}
if (addDummyToStore) {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useFirstMainDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useFirstMainDocument = <Type extends DocumentType>(
loadOnlyType?: DocumentType
) => {
const defaultDocId = useDummyId(documentRootId);
const documentRoot = useDocumentRoot(documentRootId, meta, true, access, undefined, loadOnlyType);
const documentRoot = useDocumentRoot(documentRootId, meta, true, access, false, loadOnlyType);
const userStore = useStore('userStore');
const documentStore = useStore('documentStore');
const [dummyDocument] = React.useState(
Expand Down
4 changes: 3 additions & 1 deletion src/models/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export default class Page {

@computed
get stepsOnPage(): number {
return this.taskableDocuments.length;
// use the id's, otherwise not yet created documents would not be counted,
// which leads to wrong progress values until all documents are loaded
return this.taskableDocumentRootIds.length;
}

@computed
Expand Down
8 changes: 7 additions & 1 deletion src/stores/DocumentRootStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ export class DocumentRootStore extends iStore {
accessConfig?: Partial<Config>
) {
if (this.queued.has(id)) {
return;
const currentConfig = this.queued.get(id);
const needsReplacement =
loadConfig?.documentRoot === 'replace' && currentConfig?.load.documentRoot !== 'replace';
if (!needsReplacement) {
// already queued with same or higher loadConfig - do nothing
return;
}
}
this.queued.set(id, {
meta: meta,
Expand Down
17 changes: 11 additions & 6 deletions src/stores/PageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ export const SidebarVersions = (
).versions.map((version) => {
const versionPath = ensureTrailingSlash(version.path);
const slashCount = version.path.split('/').length + 1;
const rdocs = version.docs.filter(
(doc) =>
const rdocs = version.docs.filter((doc) => {
if (version.mainDocId === 'index' && doc.id === version.mainDocId) {
return true;
}
return (
doc.path.startsWith(version.path) && doc.path.replace(/\/$/, '').split('/').length === slashCount
);
);
});
return {
name: version.name,
rootPaths: rdocs.map((doc) => ensureTrailingSlash(doc.path)),
Expand Down Expand Up @@ -136,14 +140,15 @@ export class PageStore extends iStore {

@action
setCurrentPath(path: string | undefined) {
if (path === this.currentPath) {
const normalizedPath = path?.replace(BasePathRegex, '/');
if (normalizedPath === this.currentPath) {
return;
}
if (!path) {
if (!normalizedPath) {
this.currentPath = undefined;
return;
}
this.currentPath = path.replace(BasePathRegex, '/');
this.currentPath = normalizedPath;
if (this.isPageIndexLoaded) {
this.loadTaskableDocuments(this.currentStudentGroupName);
}
Expand Down