Skip to content

Commit 647eaae

Browse files
authored
Merge pull request #1128 from rust-lang/survey-2024
Add a notification for the Rust 2023 survey
2 parents 0a6700b + c53f7a7 commit 647eaae

File tree

4 files changed

+22
-86
lines changed

4 files changed

+22
-86
lines changed

ui/frontend/Notifications.tsx

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,36 @@ import { Portal } from 'react-portal';
33

44
import { Close } from './Icon';
55
import { useAppDispatch, useAppSelector } from './hooks';
6-
import { swapTheme } from './reducers/configuration';
7-
import { seenDarkMode, seenRustSurvey2023 } from './reducers/notifications';
6+
import { seenRustSurvey2024 } from './reducers/notifications';
87
import { allowLongRun, wsExecuteKillCurrent } from './reducers/output/execute';
98
import * as selectors from './selectors';
10-
import { Theme } from './types';
119

1210
import * as styles from './Notifications.module.css';
1311

14-
const SURVEY_URL = 'https://blog.rust-lang.org/2023/12/18/survey-launch.html';
12+
const SURVEY_URL = 'https://blog.rust-lang.org/2024/12/05/annual-survey-2024-launch.html';
1513

1614
const Notifications: React.FC = () => {
1715
return (
1816
<Portal>
1917
<div className={styles.container}>
20-
<DarkModeNotification />
21-
<RustSurvey2023Notification />
18+
<RustSurvey2024Notification />
2219
<ExcessiveExecutionNotification />
2320
</div>
2421
</Portal>
2522
);
2623
};
2724

28-
const DarkModeNotification: React.FC = () => {
29-
const showIt = useAppSelector(selectors.showDarkModeSelector);
25+
const RustSurvey2024Notification: React.FC = () => {
26+
const showIt = useAppSelector(selectors.showRustSurvey2024Selector);
3027

3128
const dispatch = useAppDispatch();
32-
const seenIt = useCallback(() => dispatch(seenDarkMode()), [dispatch]);
33-
const swapToLight = useCallback(() => dispatch(swapTheme(Theme.Light)), [dispatch]);
34-
const swapToDark = useCallback(() => dispatch(swapTheme(Theme.Dark)), [dispatch]);
35-
const swapToSystem = useCallback(() => dispatch(swapTheme(Theme.System)), [dispatch]);
36-
37-
return showIt ? (
38-
<Notification onClose={seenIt}>
39-
<p>The playground now has a dark mode! Sample the themes here:</p>
40-
41-
<table>
42-
<tr>
43-
<th>
44-
<button className={styles.swapTheme} onClick={swapToSystem}>
45-
System
46-
</button>
47-
</th>
48-
<td>Use your system&apos;s preference</td>
49-
</tr>
50-
51-
<tr>
52-
<th>
53-
<button className={styles.swapTheme} onClick={swapToLight}>
54-
Light
55-
</button>
56-
</th>
57-
<td>The classic playground style</td>
58-
</tr>
59-
60-
<tr>
61-
<th>
62-
<button className={styles.swapTheme} onClick={swapToDark}>
63-
Dark
64-
</button>
65-
</th>
66-
<td>Reduce the number of photons hitting your eyeballs</td>
67-
</tr>
68-
</table>
69-
70-
<p>
71-
You can change the current UI theme (and the editor&apos;s theme) in the configuration menu.
72-
</p>
73-
</Notification>
74-
) : null;
75-
};
76-
77-
const RustSurvey2023Notification: React.FC = () => {
78-
const showIt = useAppSelector(selectors.showRustSurvey2023Selector);
79-
80-
const dispatch = useAppDispatch();
81-
const seenIt = useCallback(() => dispatch(seenRustSurvey2023()), [dispatch]);
29+
const seenIt = useCallback(() => dispatch(seenRustSurvey2024()), [dispatch]);
8230

8331
return showIt ? (
8432
<Notification onClose={seenIt}>
8533
Please help us take a look at who the Rust community is composed of, how the Rust project is
8634
doing, and how we can improve the Rust programming experience by completing the{' '}
87-
<a href={SURVEY_URL}>2023 State of Rust Survey</a>. Whether or not you use Rust today, we want
35+
<a href={SURVEY_URL}>2024 State of Rust Survey</a>. Whether or not you use Rust today, we want
8836
to know your opinions.
8937
</Notification>
9038
) : null;

ui/frontend/reducers/notifications.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ interface State {
1010
seenRustSurvey2021: boolean; // expired
1111
seenMonacoEditorAvailable: boolean; // expired
1212
seenRustSurvey2022: boolean; // expired
13-
seenRustSurvey2023: boolean;
14-
seenDarkMode: boolean;
13+
seenRustSurvey2023: boolean; // expired
14+
seenDarkMode: boolean; // expired
15+
seenRustSurvey2024: boolean;
1516
}
1617

1718
const initialState: State = {
@@ -22,8 +23,9 @@ const initialState: State = {
2223
seenRustSurvey2021: true,
2324
seenMonacoEditorAvailable: true,
2425
seenRustSurvey2022: true,
25-
seenRustSurvey2023: false,
26-
seenDarkMode: false,
26+
seenRustSurvey2023: true,
27+
seenDarkMode: true,
28+
seenRustSurvey2024: false,
2729
};
2830

2931
const slice = createSlice({
@@ -32,12 +34,8 @@ const slice = createSlice({
3234
reducers: {
3335
notificationSeen: (state, action: PayloadAction<Notification>) => {
3436
switch (action.payload) {
35-
case Notification.DarkMode: {
36-
state.seenDarkMode = true;
37-
break;
38-
}
39-
case Notification.RustSurvey2023: {
40-
state.seenRustSurvey2023 = true;
37+
case Notification.RustSurvey2024: {
38+
state.seenRustSurvey2024 = true;
4139
break;
4240
}
4341
}
@@ -47,7 +45,6 @@ const slice = createSlice({
4745

4846
const { notificationSeen } = slice.actions;
4947

50-
export const seenDarkMode = () => notificationSeen(Notification.DarkMode);
51-
export const seenRustSurvey2023 = () => notificationSeen(Notification.RustSurvey2023);
48+
export const seenRustSurvey2024 = () => notificationSeen(Notification.RustSurvey2024);
5249

5350
export default slice.reducer;

ui/frontend/selectors/index.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,15 @@ const notificationsSelector = (state: State) => state.notifications;
360360

361361
const NOW = new Date();
362362

363-
const DARK_MODE_END = new Date('2024-10-15T00:00:00Z');
364-
const DARK_MODE_OPEN = NOW <= DARK_MODE_END;
365-
export const showDarkModeSelector = createSelector(
363+
const RUST_SURVEY_2024_END = new Date('2024-12-23T00:00:00Z');
364+
const RUST_SURVEY_2024_OPEN = NOW <= RUST_SURVEY_2024_END;
365+
export const showRustSurvey2024Selector = createSelector(
366366
notificationsSelector,
367-
notifications => DARK_MODE_OPEN && !notifications.seenDarkMode,
368-
);
369-
370-
const RUST_SURVEY_2023_END = new Date('2024-01-15T00:00:00Z');
371-
const RUST_SURVEY_2023_OPEN = NOW <= RUST_SURVEY_2023_END;
372-
export const showRustSurvey2023Selector = createSelector(
373-
notificationsSelector,
374-
notifications => RUST_SURVEY_2023_OPEN && !notifications.seenRustSurvey2023,
367+
notifications => RUST_SURVEY_2024_OPEN && !notifications.seenRustSurvey2024,
375368
);
376369

377370
export const anyNotificationsToShowSelector = createSelector(
378-
showDarkModeSelector,
379-
showRustSurvey2023Selector,
371+
showRustSurvey2024Selector,
380372
excessiveExecutionSelector,
381373
(...allNotifications) => allNotifications.some(n => n),
382374
);

ui/frontend/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,5 @@ export enum Focus {
165165
}
166166

167167
export enum Notification {
168-
DarkMode = 'dark-mode',
169-
RustSurvey2023 = 'rust-survey-2023',
168+
RustSurvey2024 = 'rust-survey-2024',
170169
}

0 commit comments

Comments
 (0)