Skip to content
Open
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
62 changes: 29 additions & 33 deletions src/app/core/components/all-archives/all-archives.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ActivatedRoute, Router } from '@angular/router';
import { Validators } from '@angular/forms';

import { remove, orderBy, partition } from 'lodash';
import { Deferred } from '@root/vendor/deferred';

import { AccountService } from '@shared/services/account/account.service';
import {
Expand Down Expand Up @@ -93,7 +92,7 @@ export class AllArchivesComponent implements AfterViewInit, OnDestroy {
}

archiveClick(archive: ArchiveVO) {
const deferred = new Deferred();
const { promise, resolve } = Promise.withResolvers();

const buttons: PromptButton[] = [
{
Expand All @@ -119,34 +118,31 @@ export class AllArchivesComponent implements AfterViewInit, OnDestroy {
)} access and switch?`;
}

this.prompt
.promptButtons(buttons, message, deferred.promise)
.then((result) => {
if (result === 'switch') {
let acceptIfNeeded: Promise<ArchiveResponse | any> =
Promise.resolve();

if (archive.isPending()) {
acceptIfNeeded = this.api.archive.accept(archive);
}

acceptIfNeeded
.then(async () => await this.accountService.changeArchive(archive))
.then(() => {
deferred.resolve();
this.router.navigate(['/private']);
})
.catch((response: BaseResponse) => {
deferred.resolve();
this.message.showError({
message: response.getMessage(),
translate: true,
});
});
} else {
deferred.resolve();
this.prompt.promptButtons(buttons, message, promise).then((result) => {
if (result === 'switch') {
let acceptIfNeeded: Promise<ArchiveResponse | any> = Promise.resolve();

if (archive.isPending()) {
acceptIfNeeded = this.api.archive.accept(archive);
}
});

acceptIfNeeded
.then(async () => await this.accountService.changeArchive(archive))
.then(() => {
resolve(undefined);
this.router.navigate(['/private']);
})
.catch((response: BaseResponse) => {
resolve(undefined);
this.message.showError({
message: response.getMessage(),
translate: true,
});
});
} else {
resolve(undefined);
}
});
}

async switchToArchive(archive: ArchiveVO) {
Expand Down Expand Up @@ -185,7 +181,7 @@ export class AllArchivesComponent implements AfterViewInit, OnDestroy {
}

onCreateArchiveClick() {
const deferred = new Deferred();
const { promise, resolve, reject } = Promise.withResolvers();

const fields: PromptField[] = [
{
Expand Down Expand Up @@ -227,23 +223,23 @@ export class AllArchivesComponent implements AfterViewInit, OnDestroy {
];

this.prompt
.prompt(fields, 'Create new archive', deferred.promise, 'Create archive')
.prompt(fields, 'Create new archive', promise, 'Create archive')
.then(
async (value) => await this.api.archive.create(new ArchiveVO(value)),
)
.then((response: ArchiveResponse) => {
const newArchive = response.getArchiveVO();
this.archives.push(newArchive);
this.archiveClick(newArchive);
deferred.resolve();
resolve(undefined);
})
.catch((response: ArchiveResponse | BaseResponse) => {
if (response) {
this.message.showError({
message: response.getMessage(),
translate: true,
});
deferred.reject();
reject();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { AccountService } from '@shared/services/account/account.service';
import { RelationshipService } from '@core/services/relationship/relationship.service';
import { RelationVO, ArchiveVO } from '@models';
import { FormInputSelectOption } from '@shared/components/form-input/form-input.component';
import { Deferred } from '@root/vendor/deferred';
import { RelationResponse } from '@shared/services/api/index.repo';
import { remove, find } from 'lodash';
import {
Expand Down Expand Up @@ -155,12 +154,12 @@ export class ConnectionsDialogComponent {
}

onRelationRequestClick(relation: RelationVO, skipDecline = false) {
const deferred = new Deferred();
const { promise, resolve } = Promise.withResolvers();
this.promptService
.prompt(
[RELATIONSHIP_FIELD],
`Accept relationship with ${relation.ArchiveVO.fullName}?`,
deferred.promise,
promise,
'Accept',
skipDecline ? 'Cancel' : 'Decline',
)
Expand Down Expand Up @@ -191,18 +190,18 @@ export class ConnectionsDialogComponent {
remove(this.connectionRequests, relation);
this.connections.push(relation);

deferred.resolve();
resolve(undefined);
});
})
.catch((response: RelationResponse) => {
if (response) {
deferred.resolve();
resolve(undefined);
this.messageService.showError({
message: response.getMessage(),
translate: true,
});
} else if (!skipDecline) {
deferred.resolve();
resolve(undefined);
this.removeRelation(relation);
}
});
Expand Down Expand Up @@ -238,14 +237,14 @@ export class ConnectionsDialogComponent {
async editRelation(relation: RelationVO) {
let updatedRelation: RelationVO;
const isNewRelation = !relation.relationId;
const deferred = new Deferred();
const { promise, resolve, reject } = Promise.withResolvers();
const fields: PromptField[] = [RELATIONSHIP_FIELD_INITIAL(relation.type)];

return await this.promptService
.prompt(
fields,
`Relationship with ${relation.RelationArchiveVO.fullName}`,
deferred.promise,
promise,
'Save',
)
.then(async (value) => {
Expand All @@ -270,23 +269,23 @@ export class ConnectionsDialogComponent {
if (isNewRelation) {
relation.relationId = response.getRelationVO().relationId;
}
deferred.resolve();
resolve(undefined);
})
.catch((response: RelationResponse) => {
if (response) {
this.messageService.showError({
message: response.getMessage(),
translate: true,
});
deferred.reject();
reject();
} else if (isNewRelation) {
remove(this.connections, relation);
}
});
}

async removeRelation(relation: RelationVO) {
const deferred = new Deferred();
const { promise, resolve } = Promise.withResolvers();
let confirmTitle = `Remove relationship with ${relation.RelationArchiveVO.fullName}?`;
let confirmText = 'Remove';

Expand All @@ -302,7 +301,7 @@ export class ConnectionsDialogComponent {
await this.promptService.confirm(
confirmText,
confirmTitle,
deferred.promise,
promise,
'btn-danger',
);
const response = await this.relationService.remove(relation);
Expand All @@ -322,7 +321,7 @@ export class ConnectionsDialogComponent {
});
}
} finally {
deferred.resolve();
resolve(undefined);
}
}
}
17 changes: 10 additions & 7 deletions src/app/core/components/folder-picker/folder-picker.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, OnDestroy } from '@angular/core';
import { remove } from 'lodash';
import { Deferred } from '@root/vendor/deferred';
import { DataService } from '@shared/services/data/data.service';
import { FolderVO, ItemVO, RecordVO } from '@root/app/models/index';
import { ApiService } from '@shared/services/api/api.service';
Expand All @@ -23,7 +22,8 @@ export enum FolderPickerOperations {
})
export class FolderPickerComponent implements OnDestroy {
public currentFolder: FolderVO;
public chooseFolderDeferred: Deferred;
public chooseFolderPromise: Promise<FolderVO | RecordVO>;
public chooseFolderResolve: (value: FolderVO | RecordVO) => void;
public operation: FolderPickerOperations;
public operationName: string;

Expand Down Expand Up @@ -85,9 +85,11 @@ export class FolderPickerComponent implements OnDestroy {
this.loadCurrentFolderChildData();
});

this.chooseFolderDeferred = new Deferred();
const { promise, resolve } = Promise.withResolvers<FolderVO | RecordVO>();
this.chooseFolderPromise = promise;
this.chooseFolderResolve = resolve;

return await this.chooseFolderDeferred.promise;
return await this.chooseFolderPromise;
}

onItemClick(item: ItemVO, evt: Event) {
Expand Down Expand Up @@ -199,7 +201,8 @@ export class FolderPickerComponent implements OnDestroy {

this.cancelResetTimeout = setTimeout(() => {
this.currentFolder = null;
this.chooseFolderDeferred = null;
this.chooseFolderPromise = null;
this.chooseFolderResolve = null;
this.isRootFolder = true;
this.cancelResetTimeout = null;
}, 500);
Expand All @@ -215,9 +218,9 @@ export class FolderPickerComponent implements OnDestroy {

protected setChosenFolder(): void {
if (this.selectedRecord) {
this.chooseFolderDeferred.resolve(this.selectedRecord);
this.chooseFolderResolve(this.selectedRecord);
} else if (this.currentFolder) {
this.chooseFolderDeferred.resolve(this.currentFolder);
this.chooseFolderResolve(this.currentFolder);
}
if (this.savePromise) {
this.saving = true;
Expand Down
20 changes: 8 additions & 12 deletions src/app/core/components/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { FolderVO, RecordVO, AccountVO } from '@root/app/models';
import { find } from 'lodash';
import { ApiService } from '@shared/services/api/api.service';
import { ShareResponse } from '@shared/services/api/share.repo';
import { Deferred } from '@root/vendor/deferred';
import { Validators } from '@angular/forms';
import { DataService } from '@shared/services/data/data.service';
import { UploadSessionStatus } from '@core/services/upload/upload.session';
Expand Down Expand Up @@ -206,12 +205,13 @@ export class MainComponent
},
];

const folderCreate = new Deferred();
const { promise: folderCreatePromise, resolve: folderCreateResolve } =
Promise.withResolvers();

const promptData: any = await this.prompt.prompt(
secondScreenFields,
'Name your new timeline',
folderCreate.promise,
folderCreatePromise,
'Continue',
null,
secondScreenTemplate,
Expand All @@ -231,7 +231,7 @@ export class MainComponent

this.ga.sendEvent(EVENTS.PUBLISH.PublishByUrl.initiated.params);
const newFolder = response.getFolderVO();
folderCreate.resolve();
folderCreateResolve(undefined);
await this.router.navigate([
'/public',
newFolder.archiveNbr,
Expand Down Expand Up @@ -305,21 +305,17 @@ export class MainComponent
// no access and no request
const title = `Request access to ${shareItem.displayName} shared by ${shareAccount.fullName}?`;
try {
const deferred = new Deferred();
await this.prompt.confirm(
'Request access',
title,
deferred.promise,
);
const { promise, resolve } = Promise.withResolvers();
await this.prompt.confirm('Request access', title, promise);
try {
await this.api.share.requestShareAccess(shareUrlToken);
deferred.resolve();
resolve(undefined);
this.messageService.showMessage({
message: 'Access requested.',
style: 'success',
});
} catch (err) {
deferred.resolve();
resolve(undefined);
if (err instanceof ShareResponse) {
if (err.messageIncludesPhrase('share.already_exists')) {
this.messageService.showError({
Expand Down
Loading