|
1 | | -import React, { FunctionComponent, useState, useEffect } from 'react'; |
| 1 | +import React, { FunctionComponent, useEffect, useState } from 'react'; |
| 2 | +import { Button } from '@codesandbox/common/lib/components/Button'; |
| 3 | + |
2 | 4 | import { useOvermind } from 'app/overmind'; |
3 | 5 |
|
4 | | -import { Button } from '@codesandbox/common/lib/components/Button'; |
| 6 | +import { Explanation, Heading } from '../elements'; |
5 | 7 | import { Container } from '../LiveSessionEnded/elements'; |
6 | | -import { Heading, Explanation } from '../elements'; |
7 | 8 |
|
8 | | -import { List, Item } from './elements'; |
| 9 | +import { Item, List } from './elements'; |
9 | 10 |
|
10 | | -const NetlifyLogs: FunctionComponent = () => { |
11 | | - const [logs, setLogs] = useState(['Contacting Netlify']); |
| 11 | +export const NetlifyLogs: FunctionComponent = () => { |
12 | 12 | const { |
| 13 | + actions: { modalClosed }, |
13 | 14 | state: { |
14 | | - deployment: { netlifyLogs: url }, |
| 15 | + deployment: { netlifyLogs: netlifyLogsUrl }, |
15 | 16 | }, |
16 | | - actions: { modalClosed }, |
17 | 17 | } = useOvermind(); |
| 18 | + const [logs, setLogs] = useState(['Contacting Netlify']); |
18 | 19 |
|
19 | 20 | useEffect(() => { |
20 | | - const getLogs = async apiUrl => { |
21 | | - const data = await fetch(apiUrl); |
22 | | - const { logs: newLogs } = await data.json(); |
23 | | - setLogs(newLogs); |
24 | | - }; |
25 | | - const interval = setInterval(() => getLogs(url), 2000); |
26 | | - return () => { |
27 | | - clearInterval(interval); |
28 | | - }; |
29 | | - }, [url]); |
| 21 | + const interval = setInterval(async () => { |
| 22 | + const { logs: fetchedLogs } = await fetch(netlifyLogsUrl).then(data => |
| 23 | + data.json() |
| 24 | + ); |
| 25 | + |
| 26 | + setLogs(fetchedLogs); |
| 27 | + }, 2000); |
| 28 | + |
| 29 | + return () => clearInterval(interval); |
| 30 | + }, [netlifyLogsUrl]); |
30 | 31 |
|
31 | 32 | return ( |
32 | 33 | <Container> |
33 | 34 | <Heading>Sandbox Site Logs</Heading> |
| 35 | + |
34 | 36 | <Explanation> |
35 | 37 | Builds typically take a minute or two to complete |
36 | 38 | </Explanation> |
| 39 | + |
37 | 40 | <List> |
38 | | - {logs.map((log, i) => ( |
39 | | - // eslint-disable-next-line react/no-array-index-key |
40 | | - <Item key={i}>{log}</Item> |
| 41 | + {logs.map(log => ( |
| 42 | + <Item key={log}>{log}</Item> |
41 | 43 | ))} |
42 | 44 | </List> |
43 | | - <Button small onClick={() => modalClosed()}> |
| 45 | + |
| 46 | + <Button onClick={() => modalClosed()} small> |
44 | 47 | Close |
45 | 48 | </Button> |
46 | 49 | </Container> |
47 | 50 | ); |
48 | 51 | }; |
49 | | - |
50 | | -export default NetlifyLogs; |
|
0 commit comments