From 7eeba2aecc8c9feaa21033fc7c30432cccdcd89a Mon Sep 17 00:00:00 2001 From: amrocha Date: Thu, 12 Sep 2019 17:14:23 -0700 Subject: [PATCH] enum --- scripts/splash/index.tsx | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/scripts/splash/index.tsx b/scripts/splash/index.tsx index 613d31ac85d..53efd78455b 100644 --- a/scripts/splash/index.tsx +++ b/scripts/splash/index.tsx @@ -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'); @@ -75,14 +80,14 @@ const Component = ({pathname, filename, dependencies}) => ( const Components = ({components, status}) => ( - {status === 'loading' && ( + {status === Status.Loading && ( ⏳{' '} Please wait during compilation… Beep boop beep 🤖 )} - {status === 'loaded' && + {status === Status.Loaded && components.map(({pathname, filename, dependencies}) => ( Files potentially affected: - {status === 'loading' ? '⏳' : dependencies} + {status === Status.Loading ? '⏳' : dependencies} @@ -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.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( () => { @@ -147,7 +157,7 @@ const App = () => { setData(formatDependencies(dependencies)); } - setDataStatus('loaded'); + setDataStatus(Status.Loaded); }, [setData, stagedFiles], );