Skip to content

Commit

Permalink
Merge pull request #42 from delta-reporter/realtime-notifications
Browse files Browse the repository at this point in the history
Realtime notifications for launches and projects
  • Loading branch information
Jnegrier authored Sep 14, 2020
2 parents eb92d1a + c4bee40 commit 718daaa
Show file tree
Hide file tree
Showing 13 changed files with 2,247 additions and 3,841 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
}
}
56 changes: 56 additions & 0 deletions components/templates/eventNotification.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is not currently used, it is a failed attempt to create a notification component
import React from "react"
import Snackbar, { SnackbarOrigin } from '@material-ui/core/Snackbar';
import { useRouter } from 'next/router'
import Button from '@material-ui/core/Button';
import ReplayIcon from '@material-ui/icons/Replay';
import Tooltip from '@material-ui/core/Tooltip';

export interface State extends SnackbarOrigin {
open: boolean;
}

export const EventNotification = function(message: string) {

const router = useRouter()

const [notificationState, setNotificationState] = React.useState<State>({
open: true,
vertical: 'top',
horizontal: 'right',
});
const { vertical, horizontal, open } = notificationState;

const handleReload = () => {
setNotificationState({ ...notificationState, open: false });
router.reload();
};

const handleClose = () => {
setNotificationState({ ...notificationState, open: false });
};
console.log(open)
console.log("Hola DOS")

return (
<div>
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
message={message}
autoHideDuration={3000}
action={
<React.Fragment>
<Tooltip title="Reload page">
<Button color="secondary" size="small" onClick={handleReload}>
<ReplayIcon fontSize="small" />
</Button>
</Tooltip>
</React.Fragment>
}
key={vertical + horizontal}
/>
</div>
)
}
1 change: 1 addition & 0 deletions components/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from "./TestResolution"
export * from "./ListOfSuites"
export * from "./TestHistory"
export * from "./DeltaViewForLaunches"
export * from "./eventNotification"
16 changes: 16 additions & 0 deletions hooks/useSocket.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useEffect } from 'react'
import io from 'socket.io-client'

const socket = io(process.env.publicDeltaWebsockets)

export default function useSocket(eventName, cb) {
useEffect(() => {
socket.on(eventName, cb)

return function useSocketCleanup() {
socket.off(eventName, cb)
}
}, [eventName, cb])

return socket
}
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = withCSS({
env: {
deltaCore: process.env.DELTA_CORE_URL,
publicDeltaCore: process.env.PUBLIC_DELTA_CORE_URL,
publicDeltaWebsockets: process.env.PUBLIC_DELTA_WEBSOCKETS_URL,
},
})
Loading

0 comments on commit 718daaa

Please sign in to comment.