Skip to content

Commit 175688f

Browse files
committed
Add a notification for the Rust 2021 survey
1 parent c0d6787 commit 175688f

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

ui/frontend/Notifications.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import * as selectors from './selectors';
1010
import styles from './Notifications.module.css';
1111

1212
const EDITION_URL = 'https://doc.rust-lang.org/edition-guide/';
13+
const SURVEY_URL = 'https://blog.rust-lang.org/2021/12/08/survey-launch.html';
1314

1415
const Notifications: React.SFC = () => {
1516
return (
1617
<Portal>
1718
<div className={styles.container}>
1819
<Rust2021IsDefaultNotification />
20+
<RustSurvey2021Notification />
1921
</div>
2022
</Portal>
2123
);
@@ -36,6 +38,24 @@ const Rust2021IsDefaultNotification: React.SFC = () => {
3638
);
3739
};
3840

41+
42+
const RustSurvey2021Notification: React.SFC = () => {
43+
const showRustSurvey2021 = useSelector(selectors.showRustSurvey2021Selector);
44+
45+
const dispatch = useDispatch();
46+
const seenRustSurvey2021 = useCallback(() => dispatch(actions.seenRustSurvey2021()), [dispatch]);
47+
48+
return showRustSurvey2021 && (
49+
<Notification onClose={seenRustSurvey2021}>
50+
Please help us take a look at who the Rust community is
51+
composed of, how the Rust project is doing, and how we can
52+
improve the Rust programming experience by completing the <a
53+
href={SURVEY_URL}>2021 State of Rust Survey</a>. Whether or
54+
not you use Rust today, we want to know your opinions.
55+
</Notification>
56+
);
57+
};
58+
3959
interface NotificationProps {
4060
onClose: () => void;
4161
}

ui/frontend/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ const notificationSeen = (notification: Notification) =>
702702
createAction(ActionType.NotificationSeen, { notification });
703703

704704
export const seenRust2021IsDefault = () => notificationSeen(Notification.Rust2021IsDefault);
705+
export const seenRustSurvey2021 = () => notificationSeen(Notification.RustSurvey2021);
705706

706707
export const browserWidthChanged = (isSmall: boolean) =>
707708
createAction(ActionType.BrowserWidthChanged, { isSmall });

ui/frontend/reducers/notifications.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ interface State {
66
seenRust2018IsDefault: boolean; // expired
77
seenRustSurvey2020: boolean; // expired
88
seenRust2021IsDefault: boolean;
9+
seenRustSurvey2021: boolean;
910
}
1011

1112
const DEFAULT: State = {
1213
seenRustSurvey2018: true,
1314
seenRust2018IsDefault: true,
1415
seenRustSurvey2020: true,
1516
seenRust2021IsDefault: false,
17+
seenRustSurvey2021: false,
1618
};
1719

1820
export default function notifications(state = DEFAULT, action: Action): State {
@@ -22,6 +24,9 @@ export default function notifications(state = DEFAULT, action: Action): State {
2224
case Notification.Rust2021IsDefault: {
2325
return { ...state, seenRust2021IsDefault: true };
2426
}
27+
case Notification.RustSurvey2021: {
28+
return { ...state, seenRustSurvey2021: true };
29+
}
2530
}
2631
}
2732
default:

ui/frontend/selectors/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,25 @@ export const codeUrlSelector = createSelector(
249249
const notificationsSelector = (state: State) => state.notifications;
250250

251251
const NOW = new Date();
252+
252253
const RUST_2021_DEFAULT_END = new Date('2022-01-01T00:00:00Z');
253254
const RUST_2021_DEFAULT_OPEN = NOW <= RUST_2021_DEFAULT_END;
254255
export const showRust2021IsDefaultSelector = createSelector(
255256
notificationsSelector,
256257
notifications => RUST_2021_DEFAULT_OPEN && !notifications.seenRust2021IsDefault,
257258
);
258259

260+
const RUST_SURVEY_2021_END = new Date('2021-12-22T00:00:00Z');
261+
const RUST_SURVEY_2021_OPEN = NOW <= RUST_SURVEY_2021_END;
262+
export const showRustSurvey2021Selector = createSelector(
263+
notificationsSelector,
264+
notifications => RUST_SURVEY_2021_OPEN && !notifications.seenRustSurvey2021,
265+
);
266+
259267
export const anyNotificationsToShowSelector = createSelector(
260268
showRust2021IsDefaultSelector,
261-
allNotifications => allNotifications,
269+
showRustSurvey2021Selector,
270+
(...allNotifications) => allNotifications.some(n => n),
262271
);
263272

264273
export const clippyRequestSelector = createSelector(

ui/frontend/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export enum Focus {
120120

121121
export enum Notification {
122122
Rust2021IsDefault = 'rust-2021-is-default',
123+
RustSurvey2021 = 'rust-survey-2021',
123124
}
124125

125126
export type AceResizeKey = [Focus, number];

0 commit comments

Comments
 (0)