feat(fe/panels): enable refreshing for files and sharing panel

This commit is contained in:
hexxa 2022-02-12 11:19:36 +08:00 committed by Hexxa
parent 52969eebe6
commit b2fb036a13
4 changed files with 29 additions and 3 deletions

View file

@ -13,9 +13,9 @@ export class Cron {
this.tasks = Map<string, CronTask>(); this.tasks = Map<string, CronTask>();
} }
add = (name: string, task: CronTask) => { setInterval = (name: string, task: CronTask) => {
if (this.tasks.has(name)) { if (this.tasks.has(name)) {
this.delete(name); this.clearInterval(name);
} }
const handler = window.setInterval(task.func, task.delay, ...task.args); const handler = window.setInterval(task.func, task.delay, ...task.args);
@ -23,7 +23,7 @@ export class Cron {
this.tasks = this.tasks.set(name, task); this.tasks = this.tasks.set(name, task);
}; };
delete = (name: string) => { clearInterval = (name: string) => {
const preTask = this.tasks.get(name); const preTask = this.tasks.get(name);
window.clearInterval(preTask.handler); window.clearInterval(preTask.handler);
this.tasks = this.tasks.delete(name); this.tasks = this.tasks.delete(name);

View file

@ -36,6 +36,7 @@ import {
loadingCtrl, loadingCtrl,
} from "../common/controls"; } from "../common/controls";
import { HotkeyHandler } from "../common/hotkeys"; import { HotkeyHandler } from "../common/hotkeys";
import { CronTable } from "../common/cron";
export interface Item { export interface Item {
name: string; name: string;
@ -102,6 +103,12 @@ export class FilesPanel extends React.Component<Props, State, {}> {
} }
componentDidMount(): void { componentDidMount(): void {
CronTable().setInterval("refreshFileList", {
func: updater().refreshFiles,
args: [],
delay: 5000,
});
this.hotkeyHandler = new HotkeyHandler(); this.hotkeyHandler = new HotkeyHandler();
this.hotkeyHandler.add({ key: "a", ctrl: true }, this.selectAll); this.hotkeyHandler.add({ key: "a", ctrl: true }, this.selectAll);
this.hotkeyHandler.add({ key: "q", ctrl: true }, this.onClickUpload); this.hotkeyHandler.add({ key: "q", ctrl: true }, this.onClickUpload);
@ -110,6 +117,8 @@ export class FilesPanel extends React.Component<Props, State, {}> {
} }
componentWillUnmount() { componentWillUnmount() {
CronTable().clearInterval("refreshFileList");
document.removeEventListener("keyup", this.hotkeyHandler.handle); document.removeEventListener("keyup", this.hotkeyHandler.handle);
} }

View file

@ -15,6 +15,7 @@ import { Container } from "./layout/container";
import { Rows, Row } from "./layout/rows"; import { Rows, Row } from "./layout/rows";
import { shareIDQuery } from "../client/files"; import { shareIDQuery } from "../client/files";
import { loadingCtrl, ctrlOn, ctrlOff } from "../common/controls"; import { loadingCtrl, ctrlOn, ctrlOff } from "../common/controls";
import { CronTable } from "../common/cron";
export interface SharingsProps { export interface SharingsProps {
sharings: Map<string, string>; sharings: Map<string, string>;
@ -36,6 +37,18 @@ export class SharingsPanel extends React.Component<Props, State, {}> {
this.state = {}; this.state = {};
} }
componentDidMount(): void {
CronTable().setInterval("refreshUploadings", {
func: updater().refreshUploadings,
args: [],
delay: 5000,
});
}
componentWillUnmount() {
CronTable().clearInterval("refreshUploadings");
}
setLoading = (state: boolean) => { setLoading = (state: boolean) => {
updater().setControlOption(loadingCtrl, state ? ctrlOn : ctrlOff); updater().setControlOption(loadingCtrl, state ? ctrlOn : ctrlOff);
this.props.update(updater().updateUI); this.props.update(updater().updateUI);

View file

@ -237,6 +237,10 @@ export class Updater {
return this.setItems(dirParts); return this.setItems(dirParts);
}; };
refreshFiles = async (): Promise<string> => {
return await this.setItems(this.props.filesInfo.dirPath);
};
setItems = async (dirParts: List<string>): Promise<string> => { setItems = async (dirParts: List<string>): Promise<string> => {
const dirPath = dirParts.join("/"); const dirPath = dirParts.join("/");
const listResp = await this.filesClient.list(dirPath); const listResp = await this.filesClient.list(dirPath);