Skip to content

Commit

Permalink
enum
Browse files Browse the repository at this point in the history
  • Loading branch information
amrocha committed Sep 13, 2019
1 parent 7dd8e0a commit 7eeba2a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions scripts/splash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import {Box, Text, Color, render} from 'ink';
import sortBy from 'lodash/sortBy';
import {getGitStagedFiles, getDependencies} from './treebuilder';

enum Status {
Loading = 'LOADING',
Loaded = 'LOADED',
}

const excludedFileNames = (fileName) =>
!fileName.includes('test') && !fileName.includes('types');

Expand Down Expand Up @@ -75,14 +80,14 @@ const Component = ({pathname, filename, dependencies}) => (

const Components = ({components, status}) => (
<React.Fragment>
{status === 'loading' && (
{status === Status.Loading && (
<Box marginLeft={4} marginBottom={1}>
{' '}
Please wait during compilation… Beep boop beep 🤖
</Box>
)}

{status === 'loaded' &&
{status === Status.Loaded &&
components.map(({pathname, filename, dependencies}) => (
<Component
key={pathname + filename}
Expand Down Expand Up @@ -117,7 +122,7 @@ const Summary = ({
<Text>Files potentially affected:</Text>
</Box>
<Box justifyContent="flex-end" width={3}>
{status === 'loading' ? '⏳' : dependencies}
{status === Status.Loading ? '⏳' : dependencies}
</Box>
</Box>
</Box>
Expand All @@ -126,15 +131,20 @@ const Summary = ({
const App = () => {
const [stagedFiles, setStagedFiles] = useState([]);
const [data, setData] = useState([]);
const [dataStatus, setDataStatus] = useState('loading');
const [dataStatus, setDataStatus] = useState<Status>(Status.Loading);

useEffect(() => {
const getStagedFiles = async () => {
const staged = (await getGitStagedFiles('src/')) as string[];
setStagedFiles(staged);
};
getStagedFiles();
}, []);
useEffect(
() => {
if (dataStatus === Status.Loading) {
const getStagedFiles = async () => {
const staged = (await getGitStagedFiles('src/')) as string[];
setStagedFiles(staged);
};
getStagedFiles();
}
},
[dataStatus],
);

useEffect(
() => {
Expand All @@ -147,7 +157,7 @@ const App = () => {
setData(formatDependencies(dependencies));
}

setDataStatus('loaded');
setDataStatus(Status.Loaded);
},
[setData, stagedFiles],
);
Expand Down

0 comments on commit 7eeba2a

Please sign in to comment.