-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add support for multiple collections - add support for featured collections (from GitHub) - add support for loading collections from a custom URL Signed-off-by: Zvonimir Fras <[email protected]>
- Loading branch information
1 parent
3e4b780
commit eed26a9
Showing
7 changed files
with
279 additions
and
47 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
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
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
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,29 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import { GithubContext, GlobalStateContext } from '../context'; | ||
import axios from 'axios'; | ||
|
||
export const useRemoteCustomComponentsCollections = () => { | ||
const { customComponentsCollections } = useContext(GlobalStateContext); | ||
const { getFeaturedCustomComponentsCollection } = useContext(GithubContext); | ||
|
||
const [collections, setCollections] = useState([] as any[]); | ||
const promises: any[] = []; | ||
customComponentsCollections.forEach((collection: any) => { | ||
if (collection.type === 'featured') { | ||
promises.push(getFeaturedCustomComponentsCollection(collection.collection)); | ||
} | ||
|
||
if (collection.type === 'url') { | ||
promises.push(axios.get(collection.url, { responseType: 'text' }).then((value: any) => value.data)); | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
Promise.all(promises).then((data: any[]) => { | ||
setCollections(data); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return [collections, setCollections]; | ||
}; |
Oops, something went wrong.