Skip to content

Commit

Permalink
Web: Socket: Added "restore-backup" event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeySafronov committed Feb 25, 2022
1 parent 0302dfd commit eae8b7c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
8 changes: 7 additions & 1 deletion common/ASC.Socket.IO/app/hubs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
logger.info(`refresh folder ${folderId} in room ${room}`);
socket.to(room).emit("refresh-folder", folderId);
});

socket.on("restore-backup", () => {
const room = getRoom("backup-restore");
logger.info(`restore backup in room ${room}`);
socket.to(room).emit("restore-backup");
});
});

function startEdit({ fileId, room } = {}) {
Expand All @@ -108,7 +114,7 @@
logger.info(`create new file ${fileId} in room ${room}`);
modifyFolder(room, "create", fileId, "file", data);
}

function deleteFile({ fileId, room } = {}) {
logger.info(`delete file ${fileId} in room ${room}`);
modifyFolder(room, "delete", fileId, "file");
Expand Down
7 changes: 6 additions & 1 deletion packages/asc-web-common/utils/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class SocketIOHelper {

if (!client.connected) {
client.on("connect", () => {
room ? client.to(room).emit(command, data) : client.emit(command, data);
if (room !== null) {
client.to(room).emit(command, data);
} else {
client.emit(command, data);
}
});
} else {
room ? client.to(room).emit(command, data) : client.emit(command, data);
Expand All @@ -46,6 +50,7 @@ class SocketIOHelper {

on = (eventName, callback) => {
if (!this.isEnabled) return;

if (!client.connected) {
client.on("connect", () => {
client.on(eventName, callback);
Expand Down
18 changes: 16 additions & 2 deletions web/ASC.Web.Client/src/Shell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const Shell = ({ items = [], page = "home", ...rest }) => {
language,
FirebaseHelper,
personal,
socketHelper,
} = rest;

useEffect(() => {
Expand Down Expand Up @@ -190,6 +191,16 @@ const Shell = ({ items = [], page = "home", ...rest }) => {
}
}, []);

useEffect(() => {
socketHelper.emit({
command: "subscribe",
data: "backup-restore",
});
socketHelper.on("restore-backup", () => {
alert("Backup restore started!");
});
}, [socketHelper]);

const { t } = useTranslation("Common");

let snackTimer = null;
Expand Down Expand Up @@ -473,11 +484,13 @@ const ShellWrapper = inject(({ auth }) => {
isDesktopClient,
firebaseHelper,
setModuleInfo,
socketHelper,
} = settingsStore;

return {
loadBaseInfo: () => {
init();
loadBaseInfo: async () => {
await init();

setModuleInfo(config.homepage, "home");
setProductVersion(config.version);

Expand All @@ -491,6 +504,7 @@ const ShellWrapper = inject(({ auth }) => {
isDesktop: isDesktopClient,
FirebaseHelper: firebaseHelper,
personal,
socketHelper,
};
})(observer(Shell));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AppServerConfig } from "@appserver/common/constants";
import config from "../../../../../../../../package.json";
import FloatingButton from "@appserver/common/components/FloatingButton";
import { request } from "@appserver/common/api/client";
import { inject, observer } from "mobx-react";

class RestoreBackup extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -266,7 +267,7 @@ class RestoreBackup extends React.Component {
isCheckedThirdParty,
formSettings,
} = this.state;
const { history } = this.props;
const { history, socketHelper } = this.props;

if (!this.canRestore()) return;

Expand Down Expand Up @@ -336,7 +337,12 @@ class RestoreBackup extends React.Component {
}

startRestore(backupId, storageType, storageParams, isNotify)
.then(() => (this.storageId = ""))
.then(() => {
this.storageId = "";
socketHelper.emit({
command: "restore-backup",
});
})
.then(() =>
history.push(
combineUrl(
Expand Down Expand Up @@ -538,6 +544,20 @@ class RestoreBackup extends React.Component {
tabIndex={10}
/>

<Button
label={"Fake restore"} //TODO: Remove fake button
onClick={() => {
const { socketHelper } = this.props;
socketHelper.emit({
command: "restore-backup",
data: new Date().toLocaleString(),
});
}}
primary
size="medium"
tabIndex={10}
/>

{downloadingProgress > 0 && downloadingProgress !== 100 && (
<FloatingButton
className="layout-progress-bar"
Expand All @@ -552,4 +572,11 @@ class RestoreBackup extends React.Component {
}
}

export default withTranslation(["Settings", "Common"])(RestoreBackup);
export default inject(({ auth }) => {
const { settingsStore } = auth;
const { socketHelper } = settingsStore;

return {
socketHelper,
};
})(withTranslation(["Settings", "Common"])(observer(RestoreBackup)));
9 changes: 9 additions & 0 deletions web/ASC.Web.Editor/src/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ const Editor = () => {
if (user) filesSettings = await getSettingsFiles();
personal = authStore.settingsStore.personal;
successAuth = !!user;

const { socketHelper } = authStore.settingsStore;
socketHelper.emit({
command: "subscribe",
data: "backup-restore",
});
socketHelper.on("restore-backup", () => {
alert("Backup restore started!");
});
} catch (e) {
successAuth = false;
}
Expand Down

0 comments on commit eae8b7c

Please sign in to comment.