Skip to content

Commit 169c8e8

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch NetlifyLogs to use useOvermind (#3068)
* 🔨 Switch NetlifyLogs to use useOvermind * Resolve discussions
1 parent 94b3148 commit 169c8e8

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-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: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
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(['Waiting for build to start...']);
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+
if (fetchedLogs.length > 0) {
27+
setLogs(fetchedLogs);
28+
}
29+
}, 2000);
30+
31+
return () => clearInterval(interval);
32+
}, [netlifyLogsUrl]);
3033

3134
return (
3235
<Container>
3336
<Heading>Sandbox Site Logs</Heading>
37+
3438
<Explanation>
3539
Builds typically take a minute or two to complete
3640
</Explanation>
41+
3742
<List>
38-
{logs.map((log, i) => (
39-
// eslint-disable-next-line react/no-array-index-key
40-
<Item key={i}>{log}</Item>
43+
{logs.map(log => (
44+
<Item key={log}>{log}</Item>
4145
))}
4246
</List>
43-
<Button small onClick={() => modalClosed()}>
47+
48+
<Button onClick={() => modalClosed()} small>
4449
Close
4550
</Button>
4651
</Container>
4752
);
4853
};
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
@@ -23,7 +23,7 @@ import { FeedbackModal } from './FeedbackModal';
2323
import { ForkServerModal } from './ForkServerModal';
2424
import { LiveSessionEnded } from './LiveSessionEnded';
2525
import LiveSessionVersionMismatch from './LiveSessionVersionMismatch';
26-
import NetlifyLogs from './NetlifyLogs';
26+
import {NetlifyLogs} from './NetlifyLogs';
2727
import { PickSandboxModal } from './PickSandboxModal';
2828
import PreferencesModal from './PreferencesModal';
2929
import PRModal from './PRModal';

0 commit comments

Comments
 (0)