Skip to content

Commit

Permalink
Add a notification for the Rust 2023 survey
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Dec 5, 2024
1 parent 29f6156 commit c53f7a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
14 changes: 7 additions & 7 deletions ui/frontend/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ import { Portal } from 'react-portal';

import { Close } from './Icon';
import { useAppDispatch, useAppSelector } from './hooks';
import { seenRustSurvey2023 } from './reducers/notifications';
import { seenRustSurvey2024 } from './reducers/notifications';
import { allowLongRun, wsExecuteKillCurrent } from './reducers/output/execute';
import * as selectors from './selectors';

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

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

const Notifications: React.FC = () => {
return (
<Portal>
<div className={styles.container}>
<RustSurvey2023Notification />
<RustSurvey2024Notification />
<ExcessiveExecutionNotification />
</div>
</Portal>
);
};

const RustSurvey2023Notification: React.FC = () => {
const showIt = useAppSelector(selectors.showRustSurvey2023Selector);
const RustSurvey2024Notification: React.FC = () => {
const showIt = useAppSelector(selectors.showRustSurvey2024Selector);

const dispatch = useAppDispatch();
const seenIt = useCallback(() => dispatch(seenRustSurvey2023()), [dispatch]);
const seenIt = useCallback(() => dispatch(seenRustSurvey2024()), [dispatch]);

return showIt ? (
<Notification onClose={seenIt}>
Please help us take a look at who the Rust community is composed of, how the Rust project is
doing, and how we can improve the Rust programming experience by completing the{' '}
<a href={SURVEY_URL}>2023 State of Rust Survey</a>. Whether or not you use Rust today, we want
<a href={SURVEY_URL}>2024 State of Rust Survey</a>. Whether or not you use Rust today, we want
to know your opinions.
</Notification>
) : null;
Expand Down
12 changes: 7 additions & 5 deletions ui/frontend/reducers/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ interface State {
seenRustSurvey2021: boolean; // expired
seenMonacoEditorAvailable: boolean; // expired
seenRustSurvey2022: boolean; // expired
seenRustSurvey2023: boolean;
seenRustSurvey2023: boolean; // expired
seenDarkMode: boolean; // expired
seenRustSurvey2024: boolean;
}

const initialState: State = {
Expand All @@ -22,8 +23,9 @@ const initialState: State = {
seenRustSurvey2021: true,
seenMonacoEditorAvailable: true,
seenRustSurvey2022: true,
seenRustSurvey2023: false,
seenRustSurvey2023: true,
seenDarkMode: true,
seenRustSurvey2024: false,
};

const slice = createSlice({
Expand All @@ -32,8 +34,8 @@ const slice = createSlice({
reducers: {
notificationSeen: (state, action: PayloadAction<Notification>) => {
switch (action.payload) {
case Notification.RustSurvey2023: {
state.seenRustSurvey2023 = true;
case Notification.RustSurvey2024: {
state.seenRustSurvey2024 = true;
break;
}
}
Expand All @@ -43,6 +45,6 @@ const slice = createSlice({

const { notificationSeen } = slice.actions;

export const seenRustSurvey2023 = () => notificationSeen(Notification.RustSurvey2023);
export const seenRustSurvey2024 = () => notificationSeen(Notification.RustSurvey2024);

export default slice.reducer;
10 changes: 5 additions & 5 deletions ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,15 @@ const notificationsSelector = (state: State) => state.notifications;

const NOW = new Date();

const RUST_SURVEY_2023_END = new Date('2024-01-15T00:00:00Z');
const RUST_SURVEY_2023_OPEN = NOW <= RUST_SURVEY_2023_END;
export const showRustSurvey2023Selector = createSelector(
const RUST_SURVEY_2024_END = new Date('2024-12-23T00:00:00Z');
const RUST_SURVEY_2024_OPEN = NOW <= RUST_SURVEY_2024_END;
export const showRustSurvey2024Selector = createSelector(
notificationsSelector,
notifications => RUST_SURVEY_2023_OPEN && !notifications.seenRustSurvey2023,
notifications => RUST_SURVEY_2024_OPEN && !notifications.seenRustSurvey2024,
);

export const anyNotificationsToShowSelector = createSelector(
showRustSurvey2023Selector,
showRustSurvey2024Selector,
excessiveExecutionSelector,
(...allNotifications) => allNotifications.some(n => n),
);
Expand Down
2 changes: 1 addition & 1 deletion ui/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ export enum Focus {
}

export enum Notification {
RustSurvey2023 = 'rust-survey-2023',
RustSurvey2024 = 'rust-survey-2024',
}

0 comments on commit c53f7a7

Please sign in to comment.