fix(browser): refresh used space after all uploads are done

This commit is contained in:
hexxa 2021-10-05 18:15:51 +08:00 committed by Hexxa
parent 8b47f2f385
commit 5eafcf884d
3 changed files with 25 additions and 20 deletions

View file

@ -18,7 +18,7 @@ import { ICoreState, MsgProps, UIProps } from "./core_state";
import { LoginProps } from "./pane_login"; import { LoginProps } from "./pane_login";
import { MetadataResp, roleVisitor, roleAdmin } from "../client"; import { MetadataResp, roleVisitor, roleAdmin } from "../client";
import { Up } from "../worker/upload_mgr"; import { Up } from "../worker/upload_mgr";
import { UploadEntry } from "../worker/interface"; import { UploadEntry, UploadState } from "../worker/interface";
import { Flexbox } from "./layout/flexbox"; import { Flexbox } from "./layout/flexbox";
export interface Item { export interface Item {
@ -236,12 +236,24 @@ export class Browser extends React.Component<Props, State, {}> {
}); });
}; };
updateProgress = (infos: Map<string, UploadEntry>, refresh: boolean) => { updateProgress = async (infos: Map<string, UploadEntry>, refresh: boolean) => {
updater().setUploadings(infos); updater().setUploadings(infos);
let errCount = 0;
infos.valueSeq().forEach((entry: UploadEntry) => {
errCount += entry.state === UploadState.Error ? 1 : 0;
});
if (infos.size === 0 || infos.size === errCount) {
// refresh used space
updater().self().then(() => {
this.update(updater().updateLogin);
});
}
if (refresh) { if (refresh) {
updater() updater()
.setItems(this.props.browser.dirPath) .setItems(this.props.browser.dirPath)
.then((ok: boolean) => { .then(() => {
this.update(updater().updateBrowser); this.update(updater().updateBrowser);
}); });
} else { } else {
@ -357,9 +369,8 @@ export class Browser extends React.Component<Props, State, {}> {
} }
); );
const nameCellClass = `item-name item-name-${ const nameCellClass = `item-name item-name-${this.props.ui.isVertical ? "vertical" : "horizontal"
this.props.ui.isVertical ? "vertical" : "horizontal" } pointer`;
} pointer`;
const ops = ( const ops = (
<div> <div>
@ -445,9 +456,8 @@ export class Browser extends React.Component<Props, State, {}> {
<span className={`padding-m ${showOp}`}> <span className={`padding-m ${showOp}`}>
<button <button
onClick={() => this.select(item.name)} onClick={() => this.select(item.name)}
className={`${ className={`${isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font"
isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font" }`}
}`}
style={{ width: "8rem", display: "inline-block" }} style={{ width: "8rem", display: "inline-block" }}
> >
{isSelected {isSelected
@ -502,9 +512,8 @@ export class Browser extends React.Component<Props, State, {}> {
<button <button
type="button" type="button"
onClick={() => this.select(item.name)} onClick={() => this.select(item.name)}
className={`${ className={`${isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font"
isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font" }`}
}`}
style={{ width: "8rem", display: "inline-block" }} style={{ width: "8rem", display: "inline-block" }}
> >
{isSelected {isSelected
@ -516,9 +525,8 @@ export class Browser extends React.Component<Props, State, {}> {
childrenStyles={List([{}, { justifyContent: "flex-end" }])} childrenStyles={List([{}, { justifyContent: "flex-end" }])}
/> />
<div <div
className={`${ className={`${this.state.showDetail.has(item.name) ? "" : "hidden"
this.state.showDetail.has(item.name) ? "" : "hidden" }`}
}`}
> >
<Flexbox <Flexbox
children={List([ children={List([
@ -785,9 +793,8 @@ export class Browser extends React.Component<Props, State, {}> {
type="text" type="text"
readOnly readOnly
className="margin-r-m" className="margin-r-m"
value={`${ value={`${document.location.href.split("?")[0]
document.location.href.split("?")[0] }?dir=${encodeURIComponent(dirPath)}`}
}?dir=${encodeURIComponent(dirPath)}`}
/> />
<button <button
onClick={() => { onClick={() => {

View file

@ -8,7 +8,6 @@ import (
"github.com/ihexxa/quickshare/src/client" "github.com/ihexxa/quickshare/src/client"
q "github.com/ihexxa/quickshare/src/handlers" q "github.com/ihexxa/quickshare/src/handlers"
// "github.com/ihexxa/quickshare/src/userstore"
) )
func TestConcurrency(t *testing.T) { func TestConcurrency(t *testing.T) {

View file

@ -279,7 +279,6 @@ func (us *KVUserStore) SetPwd(id uint64, pwd string) error {
func (us *KVUserStore) CanIncrUsed(id uint64, capacity int64) (bool, error) { func (us *KVUserStore) CanIncrUsed(id uint64, capacity int64) (bool, error) {
us.mtx.Lock() us.mtx.Lock()
defer us.mtx.Unlock() defer us.mtx.Unlock()
userID := fmt.Sprint(id) userID := fmt.Sprint(id)
infoStr, ok := us.store.GetStringIn(UsersNs, userID) infoStr, ok := us.store.GetStringIn(UsersNs, userID)
if !ok { if !ok {