Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(classroom): add loading state to cloud record button #1628

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions desktop/renderer-app/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
{classRoomStore.isCreator && (
<CloudRecordBtn
isRecording={classRoomStore.isRecording}
onClick={() => {
void classRoomStore.toggleRecording({
onClick={() =>
classRoomStore.toggleRecording({
onStop() {
void message.success(t("recording-completed-tips"));
},
});
}}
})
}
/>
)}
{/* TODO: open cloud-storage sub window */}
Expand Down
8 changes: 4 additions & 4 deletions desktop/renderer-app/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
{classRoomStore.isCreator && (
<CloudRecordBtn
isRecording={classRoomStore.isRecording}
onClick={() => {
void classRoomStore.toggleRecording({
onClick={() =>
classRoomStore.toggleRecording({
onStop() {
void message.success(t("recording-completed-tips"));
},
});
}}
})
}
/>
)}
{/* TODO: open cloud-storage sub window */}
Expand Down
8 changes: 4 additions & 4 deletions desktop/renderer-app/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
{classRoomStore.isCreator && (
<CloudRecordBtn
isRecording={classRoomStore.isRecording}
onClick={() => {
void classRoomStore.toggleRecording({
onClick={() =>
classRoomStore.toggleRecording({
onStop() {
void message.success(t("recording-completed-tips"));
},
});
}}
})
}
/>
)}
{/* TODO: open cloud-storage sub window */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const Overview: Story<CloudRecordBtnProps> = () => {
isRecording={isRecording}
onClick={() => {
updateRecording(!isRecording);
return Promise.resolve();
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import React, { useCallback, useState } from "react";
import { observer } from "mobx-react-lite";
import React from "react";
import { useTranslation } from "react-i18next";

import { TopBarRightBtn } from "../TopBar";
import { SVGRecord, SVGRecordStop } from "../../FlatIcons";
import { useSafePromise } from "../../../utils/hooks";

export type CloudRecordBtnProps = {
isRecording: boolean;
onClick: (evt: any) => void;
onClick: () => Promise<void>;
crimx marked this conversation as resolved.
Show resolved Hide resolved
};

export const CloudRecordBtn: React.FC<CloudRecordBtnProps> = observer(
({ isRecording, onClick }) => {
const sp = useSafePromise();
const { t } = useTranslation();

const [loading, setLoading] = useState(false);

const handleClick = useCallback(async () => {
setLoading(true);
await sp(onClick());
setLoading(false);
}, [onClick, sp]);

return (
<TopBarRightBtn
disabled={loading}
icon={isRecording ? <SVGRecordStop active /> : <SVGRecord />}
title={t("recording")}
onClick={onClick}
onClick={handleClick}
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,33 @@
display: flex;
justify-content: center;
align-items: center;
margin: 0
(
(
@topbar-right-btn-gap -
(@topbar-right-btn-width - @topbar-icon-width)
) / 2
);
margin: 0 ((@topbar-right-btn-gap - (@topbar-right-btn-width - @topbar-icon-width)) / 2);
padding: 4px;
cursor: pointer;
background-color: white;
border: none;
outline: none;
border-radius: 8px;

&:hover {
&:not(:disabled):hover {
background-color: var(--blue-1);
}

&:disabled {
opacity: 0.5;
cursor: default;
}
}

.flat-color-scheme-dark {
.topbar-right-btn {
background-color: var(--grey-10);

&:hover {
&:not(:disabled):hover {
background-color: var(--grey-11);
}

&:active {
&:not(:disabled):active {
background-color: var(--grey-9);
}
}
Expand Down
8 changes: 4 additions & 4 deletions web/flat-web/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
{classRoomStore.isCreator && (
<CloudRecordBtn
isRecording={classRoomStore.isRecording}
onClick={() => {
void classRoomStore.toggleRecording({
onClick={() =>
classRoomStore.toggleRecording({
onStop() {
void message.success(t("recording-completed-tips"));
},
});
}}
})
}
/>
)}
{/* TODO: open cloud-storage sub window */}
Expand Down
8 changes: 4 additions & 4 deletions web/flat-web/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
{classRoomStore.isCreator && (
<CloudRecordBtn
isRecording={classRoomStore.isRecording}
onClick={() => {
void classRoomStore.toggleRecording({
onClick={() =>
classRoomStore.toggleRecording({
onStop() {
void message.success(t("recording-completed-tips"));
},
});
}}
})
}
/>
)}
{/* TODO: open cloud-storage sub window */}
Expand Down
8 changes: 4 additions & 4 deletions web/flat-web/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
{classRoomStore.isCreator && (
<CloudRecordBtn
isRecording={classRoomStore.isRecording}
onClick={() => {
void classRoomStore.toggleRecording({
onClick={() =>
classRoomStore.toggleRecording({
onStop() {
void message.success(t("recording-completed-tips"));
},
});
}}
})
}
/>
)}
<CloudStorageButton classroom={classRoomStore} />
Expand Down