diff --git a/web/app/components/document/sidebar.ts b/web/app/components/document/sidebar.ts index ea97f2931..2e57ed139 100644 --- a/web/app/components/document/sidebar.ts +++ b/web/app/components/document/sidebar.ts @@ -89,34 +89,17 @@ export default class DocumentSidebarComponent extends Component e === this.args.profile.email, ); @@ -429,29 +438,21 @@ export default class DocumentSidebarComponent extends Component e === this.args.profile.email, ); } - /** - * Whether the viewer has approved the document. - * True if their email is in the document's `approvedBy` array, - * and immediately when their approval completes. - */ - @tracked protected hasApproved = this.args.document.approvedBy?.includes( - this.args.profile.email, - ); - - /** - * Whether the viewer has requested changes to the document. - * True if their email is in the document's `changesRequestedBy` array, - * and immediately when their request completes. - */ - @tracked protected hasRejectedFRD = - this.args.document.changesRequestedBy?.includes(this.args.profile.email); - /** * Whether the document viewer is its owner. * True if the logged in user's email matches the documents owner. @@ -519,6 +520,20 @@ export default class DocumentSidebarComponent extends Component { + return this.store.peekRecord("group", approver); + }); + + this.approvers = approvers.filter((approver) => { + if (!this.approverGroups.includes(approver)) { + return this.store.peekRecord("person", approver); + } + }); + } + + @action updateContributors(contributors: string[]) { + this.contributors = contributors; + } + + @action saveTitle(title: string) { + this.title = title; + void this.save.perform("title", this.title); + } + + @action saveSummary(summary: string) { + this.summary = summary; + void this.save.perform("summary", this.summary); + } + + @action closeDeleteModal() { + this.deleteModalIsShown = false; + } + + @action closeRequestReviewModal() { + this.requestReviewModalIsShown = false; + } + + @action protected closeRequestReviewSuccessModal() { + this.requestReviewModalIsShown = false; + } + + /** + * The action run on the sidebar body's scroll event. + * If the user has scrolled, adds a border to the header. + */ + @action onScroll() { + let onScrollFunction = () => { + assert("_body must exist", this.body); + this.userHasScrolled = this.body.scrollTop > 0; + }; + + debounce(this, onScrollFunction, 50); + } + + /** + * Registers the body element locally and, if the document is a draft, + * kicks off the task to fetch the draft's `isShareable` attribute. + */ + @action protected didInsertBody(element: HTMLElement) { + this.body = element; + + if (this.isDraft) { + // kick off whether the draft is shareable. + void this.getDraftPermissions.perform(); + + // get docType for the "request review?" modal + this.args.docType.then((docType) => { + this.docType = docType; + }); + } + } + + /** + * This is an unfortunate hack to re-render the approvers list + * after the user leaves the approver role. Because the EditableField + * component has its own caching logic, it doesn't inherit changes + * from external components. This can be changed in the future, but will + * require a refactor of the EditableField and sidebar components. + * + * TODO: Improve this + */ + @action private toggleApproverVisibility() { + this.approversAreShown = false; + schedule("afterRender", () => { + this.approversAreShown = true; + }); + } + /** * A task that waits for a short time and then resolves. * Used to trigger the "link created" state of the share button. @@ -978,90 +1082,6 @@ export default class DocumentSidebarComponent extends Component { - return this.store.peekRecord("group", approver); - }); - - this.approvers = approvers.filter((approver) => { - if (!this.approverGroups.includes(approver)) { - return this.store.peekRecord("person", approver); - } - }); - } - - @action updateContributors(contributors: string[]) { - this.contributors = contributors; - } - - @action saveTitle(title: string) { - this.title = title; - void this.save.perform("title", this.title); - } - - @action saveSummary(summary: string) { - this.summary = summary; - void this.save.perform("summary", this.summary); - } - - @action closeDeleteModal() { - this.deleteModalIsShown = false; - } - - @action closeRequestReviewModal() { - this.requestReviewModalIsShown = false; - } - - @action protected closeRequestReviewSuccessModal() { - this.requestReviewModalIsShown = false; - } - - @action onScroll() { - let onScrollFunction = () => { - this.userHasScrolled = this.body.scrollTop > 0; - }; - - debounce(this, onScrollFunction, 50); - } - - /** - * Registers the body element locally and, if the document is a draft, - * kicks off the task to fetch the draft's `isShareable` attribute. - */ - @action protected didInsertBody(element: HTMLElement) { - this._body = element; - - if (this.isDraft) { - // kick off whether the draft is shareable. - void this.getDraftPermissions.perform(); - - // get docType for the "request review?" modal - this.args.docType.then((docType) => { - this.docType = docType; - }); - } - } - - /** - * This is an unfortunate hack to re-render the approvers list - * after the user leaves the approver role. Because the EditableField - * component has its own caching logic, it doesn't inherit changes - * from external components. This can be changed in the future, but will - * require a refactor of the EditableField and sidebar components. - * - * TODO: Improve this - */ - @action private toggleApproverVisibility() { - this.approversAreShown = false; - schedule("afterRender", () => { - this.approversAreShown = true; - }); - } - /** * The action to leave the approver role. * Updates the local approvers array and saves it to the back end.