Skip to content

Commit e682bf8

Browse files
committed
🔨 Switch NetlifyLogs to use useOvermind
1 parent 4534009 commit e682bf8

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

‎packages/app/src/app/pages/common/Modals/NetlifyLogs/elements.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const loading = keyframes`
99
`;
1010

1111
export const List = styled.ul`
12-
margin: 0;
1312
padding: 1.3em;
1413
list-style: none;
1514
font-family: 'dm';

‎packages/app/src/app/pages/common/Modals/NetlifyLogs/index.tsx‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
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+
24
import { useOvermind } from 'app/overmind';
35

4-
import { Button } from '@codesandbox/common/lib/components/Button';
6+
import { Explanation, Heading } from '../elements';
57
import { Container } from '../LiveSessionEnded/elements';
6-
import { Heading, Explanation } from '../elements';
78

8-
import { List, Item } from './elements';
9+
import { Item, List } from './elements';
910

10-
const NetlifyLogs: FunctionComponent = () => {
11-
const [logs, setLogs] = useState(['Contacting Netlify']);
11+
export const NetlifyLogs: FunctionComponent = () => {
1212
const {
13+
actions: { modalClosed },
1314
state: {
14-
deployment: { netlifyLogs: url },
15+
deployment: { netlifyLogs: netlifyLogsUrl },
1516
},
16-
actions: { modalClosed },
1717
} = useOvermind();
18+
const [logs, setLogs] = useState(['Contacting Netlify']);
1819

1920
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]);
3031

3132
return (
3233
<Container>
3334
<Heading>Sandbox Site Logs</Heading>
35+
3436
<Explanation>
3537
Builds typically take a minute or two to complete
3638
</Explanation>
39+
3740
<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>
4143
))}
4244
</List>
43-
<Button small onClick={() => modalClosed()}>
45+
46+
<Button onClick={() => modalClosed()} small>
4447
Close
4548
</Button>
4649
</Container>
4750
);
4851
};
49-
50-
export default NetlifyLogs;

‎packages/app/src/app/pages/common/Modals/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { FeedbackModal } from './FeedbackModal';
1919
import { ForkServerModal } from './ForkServerModal';
2020
import { LiveSessionEnded } from './LiveSessionEnded';
2121
import LiveSessionVersionMismatch from './LiveSessionVersionMismatch';
22-
import NetlifyLogs from './NetlifyLogs';
22+
import { NetlifyLogs } from './NetlifyLogs';
2323
import NewSandbox from './NewSandbox';
2424
import { PickSandboxModal } from './PickSandboxModal';
2525
import PreferencesModal from './PreferencesModal';

0 commit comments

Comments
 (0)