fix: URI not required

This commit is contained in:
cha0s 2022-03-20 15:15:04 -05:00
parent 0f9e821426
commit b350b78f64

View File

@ -27,13 +27,17 @@ const EntityComponent = ({
const flecks = useFlecks(); const flecks = useFlecks();
const {Entity, EntityList} = flecks.get('$avocado/resource.resources'); const {Entity, EntityList} = flecks.get('$avocado/resource.resources');
const [entity, setEntity] = useState(); const [entity, setEntity] = useState();
const dep = uri ? join(uri, path) : path;
useEffect(() => { useEffect(() => {
setEntity(); setEntity();
const loadEntity = async () => { const loadEntity = async () => {
const entity = await Entity.load({ const json = {
...resource, ...resource,
uri, };
}); if (uri) {
json.uri = uri;
}
const entity = await Entity.load(json);
entity.list = new EntityList(); entity.list = new EntityList();
setEntity(entity); setEntity(entity);
}; };
@ -45,7 +49,7 @@ const EntityComponent = ({
setEntity(); setEntity();
}; };
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [Entity, join(uri, path)]); }, [Entity, dep]);
useEffect(() => { useEffect(() => {
const load = async () => { const load = async () => {
await entity?.load(resource); await entity?.load(resource);
@ -83,6 +87,7 @@ const EntityComponent = ({
EntityComponent.defaultProps = { EntityComponent.defaultProps = {
path: '/', path: '/',
uri: null,
}; };
EntityComponent.displayName = 'EntityComponent'; EntityComponent.displayName = 'EntityComponent';
@ -92,7 +97,7 @@ EntityComponent.propTypes = {
resource: PropTypes.shape({ resource: PropTypes.shape({
traits: PropTypes.shape({}), traits: PropTypes.shape({}),
}).isRequired, }).isRequired,
uri: PropTypes.string.isRequired, uri: PropTypes.string,
}; };
export default EntityComponent; export default EntityComponent;