fix(ui/browser): incorrect async operation order
This commit is contained in:
parent
101d47b2f7
commit
b89ad2765e
4 changed files with 20 additions and 8 deletions
|
@ -192,10 +192,10 @@ export class Browser extends React.Component<Props, State, {}> {
|
|||
updater()
|
||||
.setItems(dirPath)
|
||||
.then(() => {
|
||||
updater().listSharings();
|
||||
return updater().listSharings();
|
||||
})
|
||||
.then(() => {
|
||||
updater().setSharing(dirPath.join("/"));
|
||||
return updater().isSharing(dirPath.join("/"));
|
||||
})
|
||||
.then(() => {
|
||||
this.update(updater().setBrowser);
|
||||
|
@ -248,8 +248,12 @@ export class Browser extends React.Component<Props, State, {}> {
|
|||
if (!ok) {
|
||||
alert("failed to enable sharing");
|
||||
} else {
|
||||
this.listSharings();
|
||||
updater().setSharing(true);
|
||||
return this.listSharings();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.props.update(updater().setBrowser);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -260,8 +264,12 @@ export class Browser extends React.Component<Props, State, {}> {
|
|||
if (!ok) {
|
||||
alert("failed to disable sharing");
|
||||
} else {
|
||||
this.listSharings();
|
||||
updater().setSharing(false);
|
||||
return this.listSharings();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.props.update(updater().setBrowser);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -65,16 +65,20 @@ export class Updater {
|
|||
};
|
||||
|
||||
deleteSharing = async (dirPath: string): Promise<boolean> => {
|
||||
const resp = await this.filesClient.addSharing(dirPath);
|
||||
const resp = await this.filesClient.deleteSharing(dirPath);
|
||||
return resp.status === 200;
|
||||
};
|
||||
|
||||
setSharing = async (dirPath: string): Promise<boolean> => {
|
||||
isSharing = async (dirPath: string): Promise<boolean> => {
|
||||
const resp = await this.filesClient.isSharing(dirPath);
|
||||
this.props.isSharing = resp.status === 200;
|
||||
return resp.status === 200; // TODO: differentiate 404 and error
|
||||
};
|
||||
|
||||
setSharing = (shared: boolean) => {
|
||||
this.props.isSharing = shared;
|
||||
};
|
||||
|
||||
listSharings = async (): Promise<boolean> => {
|
||||
const resp = await this.filesClient.listSharings();
|
||||
this.props.sharings =
|
||||
|
|
|
@ -140,7 +140,7 @@ export class AuthPane extends React.Component<Props, State, {}> {
|
|||
return BrowserUpdater().refreshUploadings();
|
||||
})
|
||||
.then(() => {
|
||||
return BrowserUpdater().setSharing(
|
||||
return BrowserUpdater().isSharing(
|
||||
BrowserUpdater().props.dirPath.join("/")
|
||||
);
|
||||
})
|
||||
|
|
|
@ -41,7 +41,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
|
|||
return BrowserUpdater().initUploads();
|
||||
})
|
||||
.then(() => {
|
||||
return BrowserUpdater().setSharing(
|
||||
return BrowserUpdater().isSharing(
|
||||
BrowserUpdater().props.dirPath.join("/")
|
||||
);
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue