Skip to content

Commit 3bcfa07

Browse files
authored
New notifications (codesandbox#1823)
* Add support for new notifications * Add event system * Working version with buttons * IImprovements * Move app to new notifications * Cleanup * Tweak update notification * Handle the timeAlive from s to ms * Add build script for notifications * Remove old component * v1.0.5 * Publish and tweak icon location * Update * Fix build script * Add dependency back * Ignore missing common from the start * Update snapshots
1 parent e535751 commit 3bcfa07

File tree

45 files changed

+891
-368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+891
-368
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"build:prod": "NODE_OPTIONS=\"--max-old-space-size=4096\" lerna run build --scope homepage --stream && lerna run build --scope app --stream && gulp",
99
"build:embed": "lerna run build:embed --scope app --stream && gulp",
1010
"build:clean": "lerna run build:clean --scope app --scope homepage && rimraf www",
11-
"build:deps": "lerna run build:dev --scope codesandbox-api && lerna run build:dev --scope @codesandbox/common && lerna run build:dev --scope vscode-textmate --scope codesandbox-browserfs --scope node-services && lerna run build:dev --scope sse-hooks",
12-
"build:common": "lerna run build:dev --scope @codesandbox/common --stream",
11+
"build:deps": "lerna run build:dev --scope codesandbox-api --scope @codesandbox/notifications && lerna run build:dev --scope @codesandbox/common && lerna run build:dev --scope vscode-textmate --scope codesandbox-browserfs --scope node-services && lerna run build:dev --scope sse-hooks",
12+
"build:common": "lerna run build:dev --scope @codesandbox/common --stream",
1313
"build:dynamic": "lerna run build --scope dynamic-pages --stream",
1414
"start": "yarn build:deps && lerna run start --scope app --stream",
1515
"start:fast": "lerna run start --scope app --stream",
@@ -46,7 +46,8 @@
4646
"packages/sandbox-hooks",
4747
"packages/sse-hooks",
4848
"packages/react-embed",
49-
"packages/dynamic-pages"
49+
"packages/dynamic-pages",
50+
"packages/notifications"
5051
],
5152
"nohoist": [
5253
"**/react-codemirror2",

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"react-router-dom": "^4.3.1",
247247
"react-show": "^3.0.4",
248248
"react-split-pane": "^0.1.85",
249-
"react-spring": "^8.0.4",
249+
"react-spring": "^8.0.19",
250250
"react-stripe-elements": "^1.2.0",
251251
"react-tagsinput": "^3.19.0",
252252
"react-virtualized": "^9.19.1",

packages/app/src/app/components/CodeEditor/Monaco/define-theme.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Color from 'color';
2+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
3+
import { NotificationStatus } from '@codesandbox/notifications';
24

35
const sanitizeColor = color => {
46
if (!color) {
@@ -93,12 +95,11 @@ const defineTheme = (monaco, theme) => {
9395
monaco.editor.setTheme('CodeSandbox');
9496
} catch (e) {
9597
console.error(e);
96-
if (window.showNotification) {
97-
window.showNotification(
98-
`Problem initializing template in editor: ${e.message}`,
99-
'error'
100-
);
101-
}
98+
99+
notificationState.addNotification({
100+
message: `Problem initializing template in editor: ${e.message}`,
101+
status: NotificationStatus.ERROR,
102+
});
102103
}
103104
}
104105
};

packages/app/src/app/graphql/client.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { BatchHttpLink } from 'apollo-link-batch-http';
44
import { setContext } from 'apollo-link-context';
55
import { InMemoryCache } from 'apollo-cache-inmemory';
66
import { onError } from 'apollo-link-error';
7+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
8+
import { NotificationStatus } from '@codesandbox/notifications';
79

810
const httpLink = new BatchHttpLink({
911
uri: '/api/graphql',
@@ -34,15 +36,19 @@ const absintheAfterware = new ApolloLink((operation, forward) =>
3436

3537
const errorHandler = onError(({ graphQLErrors, networkError }) => {
3638
if (graphQLErrors) {
37-
if (window.showNotification) {
38-
graphQLErrors.forEach(({ message }) => {
39-
window.showNotification(message, 'error');
39+
graphQLErrors.forEach(({ message }) => {
40+
notificationState.addNotification({
41+
message,
42+
status: NotificationStatus.ERROR,
4043
});
41-
}
44+
});
4245
}
4346

4447
if (networkError) {
45-
window.showNotification(`Network Error: ${networkError}`, 'error');
48+
notificationState.addNotification({
49+
message: `Network Error: ${networkError}`,
50+
status: NotificationStatus.ERROR,
51+
});
4652
}
4753
});
4854

packages/app/src/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<script>
2727
WebFont.load({
2828
google: {
29-
families: ['Source Code Pro:500', 'Roboto:300,400,500,700', 'Poppins:300,400,600,700']
29+
families: ['Source Code Pro:500', 'Roboto:300,400,500,700', 'Poppins:300,400,500,600,700']
3030
}
3131
});
3232
</script>

packages/app/src/app/index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import history from 'app/utils/history';
1515
import { client } from 'app/graphql/client';
1616
import registerServiceWorker from '@codesandbox/common/lib/registerServiceWorker';
1717
import requirePolyfills from '@codesandbox/common/lib/load-dynamic-polyfills';
18+
import {
19+
notificationState,
20+
convertTypeToStatus,
21+
} from '@codesandbox/common/lib/utils/notifications';
22+
import { NotificationStatus } from '@codesandbox/notifications';
1823
import 'normalize.css';
1924
import theme from '@codesandbox/common/lib/theme';
2025
import { isSafari } from '@codesandbox/common/lib/utils/platform';
@@ -73,21 +78,39 @@ function boot() {
7378

7479
const rootEl = document.getElementById('root');
7580

76-
const showNotification = (message, type) =>
77-
controller.getSignal('notificationAdded')({
78-
type,
81+
const showNotification = (message, type) => {
82+
notificationState.addNotification({
7983
message,
84+
status: convertTypeToStatus(type),
8085
});
86+
};
8187

8288
window.showNotification = showNotification;
8389

8490
registerServiceWorker('/service-worker.js', {
8591
onUpdated: () => {
8692
debug('Updated SW');
8793
controller.getSignal('setUpdateStatus')({ status: 'available' });
94+
95+
notificationState.addNotification({
96+
title: 'CodeSandbox Update Available',
97+
message:
98+
'We just installed a new version of CodeSandbox, refresh to update!',
99+
status: NotificationStatus.SUCCESS,
100+
sticky: true,
101+
actions: [
102+
{
103+
primary: {
104+
run: () => document.location.reload(),
105+
title: 'Reload Page',
106+
},
107+
},
108+
],
109+
});
88110
},
89111
onInstalled: () => {
90112
debug('Installed SW');
113+
91114
showNotification(
92115
'CodeSandbox has been installed, it now works offline!',
93116
'success'

packages/app/src/app/pages/Dashboard/Content/routes/CreateTeam/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Button } from '@codesandbox/common/lib/components/Button';
66
import track from '@codesandbox/common/lib/utils/analytics';
77
import history from 'app/utils/history';
88
import { teamOverviewUrl } from '@codesandbox/common/lib/utils/url-generator';
9+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
10+
import { NotificationStatus } from '@codesandbox/notifications';
911

1012
import { Container, Description, HeaderContainer } from '../../elements';
1113
import {
@@ -86,12 +88,10 @@ export default class CreateTeam extends React.PureComponent {
8688
});
8789
},
8890
}).then(({ data }) => {
89-
if (window.showNotification) {
90-
window.showNotification(
91-
`Succesfully created team '${data.createTeam.name}'`,
92-
'success'
93-
);
94-
}
91+
notificationState.addNotification({
92+
message: `Succesfully created team '${data.createTeam.name}'`,
93+
status: NotificationStatus.SUCCESS,
94+
});
9595

9696
history.push(teamOverviewUrl(data.createTeam.id));
9797
});

packages/app/src/app/pages/Dashboard/Content/routes/TeamView/RemoveTeamMember/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Mutation } from 'react-apollo';
44
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
55
import history from 'app/utils/history';
66
import { dashboardUrl } from '@codesandbox/common/lib/utils/url-generator';
7+
import { NotificationStatus } from '@codesandbox/notifications';
8+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
79

810
import { REMOVE_FROM_TEAM, LEAVE_TEAM } from '../../../../queries';
911

@@ -50,14 +52,13 @@ export default ({
5052
mutation={isOwnUser ? LEAVE_TEAM : REMOVE_FROM_TEAM}
5153
refetchQueries={isOwnUser ? ['TeamsSidebar'] : []}
5254
onCompleted={() => {
53-
if (window.showNotification) {
54-
window.showNotification(
55-
isOwnUser
56-
? 'Succesfully left the team'
57-
: 'Succesfully removed from team',
58-
'success'
59-
);
60-
}
55+
notificationState.addNotification({
56+
message: isOwnUser
57+
? 'Succesfully left the team'
58+
: 'Succesfully removed from team',
59+
status: NotificationStatus.SUCCESS,
60+
});
61+
6162
history.push(dashboardUrl());
6263
}}
6364
>

packages/app/src/app/pages/Sandbox/Editor/utils/get-vscode-theme.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import JSON from 'json5';
33
import codesandbox from '@codesandbox/common/lib/themes/codesandbox.json';
44

55
import themes from '@codesandbox/common/lib/themes';
6+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
7+
import { NotificationStatus } from '@codesandbox/notifications';
68

79
const editorBackground = 'editor.background';
810
const editorForeground = 'editor.foreground';
@@ -59,12 +61,10 @@ function fetchTheme(foundTheme) {
5961
} catch (e) {
6062
console.error(e);
6163

62-
if (window.showNotification) {
63-
window.showNotification(
64-
'We had trouble loading the theme, error: \n' + e.message,
65-
'error'
66-
);
67-
}
64+
notificationState.addNotification({
65+
message: 'We had trouble loading the theme, error: \n' + e.message,
66+
status: NotificationStatus.ERROR,
67+
});
6868
}
6969
return theme;
7070
});
@@ -77,13 +77,12 @@ const findTheme = async (themeName, customTheme) => {
7777
} catch (e) {
7878
console.error(e);
7979

80-
if (window.showNotification) {
81-
window.showNotification(
80+
notificationState.addNotification({
81+
message:
8282
'We had trouble parsing your custom VSCode Theme, error: \n' +
83-
e.message,
84-
'error'
85-
);
86-
}
83+
e.message,
84+
status: NotificationStatus.ERROR,
85+
});
8786
}
8887
}
8988

packages/app/src/app/pages/common/Notifications/Notification/elements.js

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)