Skip to content

Commit

Permalink
Add notification about Monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Jan 8, 2022
1 parent 434a62e commit 43d23e5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 56 deletions.
40 changes: 10 additions & 30 deletions ui/frontend/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,29 @@ import * as selectors from './selectors';

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

const EDITION_URL = 'https://doc.rust-lang.org/edition-guide/';
const SURVEY_URL = 'https://blog.rust-lang.org/2021/12/08/survey-launch.html';
const MONACO_EDITOR_URL = 'https://microsoft.github.io/monaco-editor/';

const Notifications: React.SFC = () => {
return (
<Portal>
<div className={styles.container}>
<Rust2021IsDefaultNotification />
<RustSurvey2021Notification />
<MonacoEditorAvailableNotification />
</div>
</Portal>
);
};

const Rust2021IsDefaultNotification: React.SFC = () => {
const showRust2021IsDefault = useSelector(selectors.showRust2021IsDefaultSelector);
const MonacoEditorAvailableNotification: React.SFC = () => {
const monicoEditorAvailable = useSelector(selectors.showMonicoEditorAvailableSelector);

const dispatch = useDispatch();
const seenRust2021IsDefault = useCallback(() => dispatch(actions.seenRust2021IsDefault()), [dispatch]);
const seenMonicoEditorAvailable = useCallback(() => dispatch(actions.seenMonicoEditorAvailable()), [dispatch]);

return showRust2021IsDefault && (
<Notification onClose={seenRust2021IsDefault}>
As of Rust 1.56, the default edition of Rust is now Rust
2021. Learn more about editions in the <a href={EDITION_URL}>Edition Guide</a>.
To specify which edition to use, use the advanced compilation options menu.
</Notification>
);
};


const RustSurvey2021Notification: React.SFC = () => {
const showRustSurvey2021 = useSelector(selectors.showRustSurvey2021Selector);

const dispatch = useDispatch();
const seenRustSurvey2021 = useCallback(() => dispatch(actions.seenRustSurvey2021()), [dispatch]);

return showRustSurvey2021 && (
<Notification onClose={seenRustSurvey2021}>
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}>2021 State of Rust Survey</a>. Whether or
not you use Rust today, we want to know your opinions.
return monicoEditorAvailable && (
<Notification onClose={seenMonicoEditorAvailable}>
The <a href={MONACO_EDITOR_URL}>Monaco Editor</a>, the code editor
that powers VS Code, is now available in the playground. Choose
your preferred editor from the Config menu.
</Notification>
);
};
Expand Down
3 changes: 1 addition & 2 deletions ui/frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,7 @@ export function performVersionsLoad(): ThunkAction {
const notificationSeen = (notification: Notification) =>
createAction(ActionType.NotificationSeen, { notification });

export const seenRust2021IsDefault = () => notificationSeen(Notification.Rust2021IsDefault);
export const seenRustSurvey2021 = () => notificationSeen(Notification.RustSurvey2021);
export const seenMonicoEditorAvailable = () => notificationSeen(Notification.MonacoEditorAvailable);

export const browserWidthChanged = (isSmall: boolean) =>
createAction(ActionType.BrowserWidthChanged, { isSmall });
Expand Down
17 changes: 8 additions & 9 deletions ui/frontend/reducers/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ interface State {
seenRustSurvey2018: boolean; // expired
seenRust2018IsDefault: boolean; // expired
seenRustSurvey2020: boolean; // expired
seenRust2021IsDefault: boolean;
seenRustSurvey2021: boolean;
seenRust2021IsDefault: boolean; // expired
seenRustSurvey2021: boolean; // expired
seenMonacoEditorAvailable: boolean;
}

const DEFAULT: State = {
seenRustSurvey2018: true,
seenRust2018IsDefault: true,
seenRustSurvey2020: true,
seenRust2021IsDefault: false,
seenRustSurvey2021: false,
seenRust2021IsDefault: true,
seenRustSurvey2021: true,
seenMonacoEditorAvailable: false,
};

export default function notifications(state = DEFAULT, action: Action): State {
switch (action.type) {
case ActionType.NotificationSeen: {
switch (action.notification) {
case Notification.Rust2021IsDefault: {
return { ...state, seenRust2021IsDefault: true };
}
case Notification.RustSurvey2021: {
return { ...state, seenRustSurvey2021: true };
case Notification.MonacoEditorAvailable: {
return { ...state, seenMonacoEditorAvailable: true };
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,15 @@ const notificationsSelector = (state: State) => state.notifications;

const NOW = new Date();

const RUST_2021_DEFAULT_END = new Date('2022-01-01T00:00:00Z');
const RUST_2021_DEFAULT_OPEN = NOW <= RUST_2021_DEFAULT_END;
export const showRust2021IsDefaultSelector = createSelector(
const MONACO_EDITOR_AVAILABLE_END = new Date('2022-02-15T00:00:00Z');
const MONACO_EDITOR_AVAILABLE_OPEN = NOW <= MONACO_EDITOR_AVAILABLE_END;
export const showMonicoEditorAvailableSelector = createSelector(
notificationsSelector,
notifications => RUST_2021_DEFAULT_OPEN && !notifications.seenRust2021IsDefault,
);

const RUST_SURVEY_2021_END = new Date('2021-12-22T00:00:00Z');
const RUST_SURVEY_2021_OPEN = NOW <= RUST_SURVEY_2021_END;
export const showRustSurvey2021Selector = createSelector(
notificationsSelector,
notifications => RUST_SURVEY_2021_OPEN && !notifications.seenRustSurvey2021,
notifications => MONACO_EDITOR_AVAILABLE_OPEN && !notifications.seenMonacoEditorAvailable,
);

export const anyNotificationsToShowSelector = createSelector(
showRust2021IsDefaultSelector,
showRustSurvey2021Selector,
showMonicoEditorAvailableSelector,
(...allNotifications) => allNotifications.some(n => n),
);

Expand Down
3 changes: 1 addition & 2 deletions ui/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ export enum Focus {
}

export enum Notification {
Rust2021IsDefault = 'rust-2021-is-default',
RustSurvey2021 = 'rust-survey-2021',
MonacoEditorAvailable = 'monaco-editor-available',
}

export type AceResizeKey = [Focus, number];

0 comments on commit 43d23e5

Please sign in to comment.