Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c980885

Browse files
authored
Extract RoomStatusBarUnsentMessages (#9080)
1 parent dca4b8b commit c980885

File tree

4 files changed

+111
-25
lines changed

4 files changed

+111
-25
lines changed

res/css/structures/_RoomStatusBar.pcss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ limitations under the License.
138138
mask-image: url('$(res)/img/element-icons/trashcan.svg');
139139
}
140140

141-
&.mx_RoomStatusBar_unsentResendAllBtn {
141+
&.mx_RoomStatusBar_unsentRetry {
142142
padding-left: 34px; // 28px from above, but +6px to account for the wider icon
143143

144144
&::before {

src/components/structures/RoomStatusBar.tsx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import Resend from '../../Resend';
2424
import dis from '../../dispatcher/dispatcher';
2525
import { messageForResourceLimitError } from '../../utils/ErrorUtils';
2626
import { Action } from "../../dispatcher/actions";
27-
import NotificationBadge from "../views/rooms/NotificationBadge";
2827
import { StaticNotificationState } from "../../stores/notifications/StaticNotificationState";
2928
import AccessibleButton from "../views/elements/AccessibleButton";
3029
import InlineSpinner from "../views/elements/InlineSpinner";
3130
import MatrixClientContext from "../../contexts/MatrixClientContext";
31+
import { RoomStatusBarUnsentMessages } from './RoomStatusBarUnsentMessages';
3232

3333
const STATUS_BAR_HIDDEN = 0;
3434
const STATUS_BAR_EXPANDED = 1;
@@ -240,7 +240,7 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
240240
<AccessibleButton onClick={this.onCancelAllClick} className="mx_RoomStatusBar_unsentCancelAllBtn">
241241
{ _t("Delete all") }
242242
</AccessibleButton>
243-
<AccessibleButton onClick={this.onResendAllClick} className="mx_RoomStatusBar_unsentResendAllBtn">
243+
<AccessibleButton onClick={this.onResendAllClick} className="mx_RoomStatusBar_unsentRetry">
244244
{ _t("Retry all") }
245245
</AccessibleButton>
246246
</>;
@@ -252,28 +252,12 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
252252
</>;
253253
}
254254

255-
return <>
256-
<div className="mx_RoomStatusBar mx_RoomStatusBar_unsentMessages">
257-
<div role="alert">
258-
<div className="mx_RoomStatusBar_unsentBadge">
259-
<NotificationBadge
260-
notification={StaticNotificationState.RED_EXCLAMATION}
261-
/>
262-
</div>
263-
<div>
264-
<div className="mx_RoomStatusBar_unsentTitle">
265-
{ title }
266-
</div>
267-
<div className="mx_RoomStatusBar_unsentDescription">
268-
{ _t("You can select all or individual messages to retry or delete") }
269-
</div>
270-
</div>
271-
<div className="mx_RoomStatusBar_unsentButtonBar">
272-
{ buttonRow }
273-
</div>
274-
</div>
275-
</div>
276-
</>;
255+
return <RoomStatusBarUnsentMessages
256+
title={title}
257+
description={_t("You can select all or individual messages to retry or delete")}
258+
notificationState={StaticNotificationState.RED_EXCLAMATION}
259+
buttons={buttonRow}
260+
/>;
277261
}
278262

279263
public render(): JSX.Element {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { ReactElement } from "react";
18+
19+
import { StaticNotificationState } from "../../stores/notifications/StaticNotificationState";
20+
import NotificationBadge from "../views/rooms/NotificationBadge";
21+
22+
interface RoomStatusBarUnsentMessagesProps {
23+
title: string;
24+
description?: string;
25+
notificationState: StaticNotificationState;
26+
buttons: ReactElement;
27+
}
28+
29+
export const RoomStatusBarUnsentMessages = (props: RoomStatusBarUnsentMessagesProps): ReactElement => {
30+
return (
31+
<div className="mx_RoomStatusBar mx_RoomStatusBar_unsentMessages">
32+
<div role="alert">
33+
<div className="mx_RoomStatusBar_unsentBadge">
34+
<NotificationBadge
35+
notification={props.notificationState}
36+
/>
37+
</div>
38+
<div>
39+
<div className="mx_RoomStatusBar_unsentTitle">
40+
{ props.title }
41+
</div>
42+
{
43+
props.description &&
44+
<div className="mx_RoomStatusBar_unsentDescription">
45+
{ props.description }
46+
</div>
47+
}
48+
</div>
49+
<div className="mx_RoomStatusBar_unsentButtonBar">
50+
{ props.buttons }
51+
</div>
52+
</div>
53+
</div>
54+
);
55+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
import { render, screen } from "@testing-library/react";
19+
20+
import { RoomStatusBarUnsentMessages } from "../../../src/components/structures/RoomStatusBarUnsentMessages";
21+
import { StaticNotificationState } from "../../../src/stores/notifications/StaticNotificationState";
22+
23+
describe("RoomStatusBarUnsentMessages", () => {
24+
const title = "test title";
25+
const description = "test description";
26+
const buttonsText = "test buttons";
27+
const buttons = <div>{ buttonsText }</div>;
28+
29+
beforeEach(() => {
30+
render(
31+
<RoomStatusBarUnsentMessages
32+
title={title}
33+
description={description}
34+
buttons={buttons}
35+
notificationState={StaticNotificationState.RED_EXCLAMATION}
36+
/>,
37+
);
38+
});
39+
40+
it("should render the values passed as props", () => {
41+
screen.getByText(title);
42+
screen.getByText(description);
43+
screen.getByText(buttonsText);
44+
// notification state
45+
screen.getByText("!");
46+
});
47+
});

0 commit comments

Comments
 (0)