fix(ui/browser): incorrect async operation order

This commit is contained in:
hexxa 2021-08-20 21:49:02 +08:00 committed by Hexxa
parent 101d47b2f7
commit b89ad2765e
4 changed files with 20 additions and 8 deletions

View file

@ -192,10 +192,10 @@ export class Browser extends React.Component<Props, State, {}> {
updater() updater()
.setItems(dirPath) .setItems(dirPath)
.then(() => { .then(() => {
updater().listSharings(); return updater().listSharings();
}) })
.then(() => { .then(() => {
updater().setSharing(dirPath.join("/")); return updater().isSharing(dirPath.join("/"));
}) })
.then(() => { .then(() => {
this.update(updater().setBrowser); this.update(updater().setBrowser);
@ -248,8 +248,12 @@ export class Browser extends React.Component<Props, State, {}> {
if (!ok) { if (!ok) {
alert("failed to enable sharing"); alert("failed to enable sharing");
} else { } 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) { if (!ok) {
alert("failed to disable sharing"); alert("failed to disable sharing");
} else { } else {
this.listSharings(); updater().setSharing(false);
return this.listSharings();
} }
})
.then(() => {
this.props.update(updater().setBrowser);
}); });
}; };

View file

@ -65,16 +65,20 @@ export class Updater {
}; };
deleteSharing = async (dirPath: string): Promise<boolean> => { deleteSharing = async (dirPath: string): Promise<boolean> => {
const resp = await this.filesClient.addSharing(dirPath); const resp = await this.filesClient.deleteSharing(dirPath);
return resp.status === 200; return resp.status === 200;
}; };
setSharing = async (dirPath: string): Promise<boolean> => { isSharing = async (dirPath: string): Promise<boolean> => {
const resp = await this.filesClient.isSharing(dirPath); const resp = await this.filesClient.isSharing(dirPath);
this.props.isSharing = resp.status === 200; this.props.isSharing = resp.status === 200;
return resp.status === 200; // TODO: differentiate 404 and error return resp.status === 200; // TODO: differentiate 404 and error
}; };
setSharing = (shared: boolean) => {
this.props.isSharing = shared;
};
listSharings = async (): Promise<boolean> => { listSharings = async (): Promise<boolean> => {
const resp = await this.filesClient.listSharings(); const resp = await this.filesClient.listSharings();
this.props.sharings = this.props.sharings =

View file

@ -140,7 +140,7 @@ export class AuthPane extends React.Component<Props, State, {}> {
return BrowserUpdater().refreshUploadings(); return BrowserUpdater().refreshUploadings();
}) })
.then(() => { .then(() => {
return BrowserUpdater().setSharing( return BrowserUpdater().isSharing(
BrowserUpdater().props.dirPath.join("/") BrowserUpdater().props.dirPath.join("/")
); );
}) })

View file

@ -41,7 +41,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
return BrowserUpdater().initUploads(); return BrowserUpdater().initUploads();
}) })
.then(() => { .then(() => {
return BrowserUpdater().setSharing( return BrowserUpdater().isSharing(
BrowserUpdater().props.dirPath.join("/") BrowserUpdater().props.dirPath.join("/")
); );
}) })