This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from newrelic/feature/NR-2231-2
NR-2231 Fetch files from localhost
- Loading branch information
Showing
3 changed files
with
91 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { getQuickstartFilesFromLocal } from '../utils/preview/fetchHelpers'; | ||
//import { parseQuickstartFiles } from '../utils/preview/parseHelpers'; | ||
import { navigate } from 'gatsby'; | ||
|
||
const useLocalhostQuickstart = (location) => { | ||
const [quickstart, setQuickstart] = useState([]); | ||
|
||
useEffect(() => { | ||
const urlParams = new URLSearchParams(location.search); | ||
const port = urlParams.get('port') || 3000; | ||
|
||
/* | ||
* Async function to get quickstart files from local | ||
* and set to state variable | ||
**/ | ||
const fetchFiles = async () => { | ||
let rawFileContent; | ||
|
||
try { | ||
rawFileContent = await getQuickstartFilesFromLocal(port); | ||
} catch (err) { | ||
navigate('/'); | ||
return; | ||
} | ||
/** | ||
* TODO: Uncomment these lines and delete setQuickstart(rawFileContent) once parsing is complete | ||
*/ | ||
//const quickstart = await parseQuickstartFiles(rawFileContent); | ||
//setQuickstart(quickstart); | ||
setQuickstart(rawFileContent); | ||
}; | ||
|
||
fetchFiles(); | ||
}, []); | ||
|
||
return quickstart; | ||
}; | ||
|
||
export default useLocalhostQuickstart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters