-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
route.resolve
feature (#4607)
* Stop using route.resolve feature (pages should load all the data themselves) * Remove route.resolve feature Co-authored-by: Arik Fraimovich <[email protected]>
- Loading branch information
1 parent
75cc6b3
commit e552eff
Showing
4 changed files
with
55 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useState, useEffect, useRef } from "react"; | ||
import PropTypes from "prop-types"; | ||
import LoadingState from "@/components/items-list/components/LoadingState"; | ||
import { Query } from "@/services/query"; | ||
|
||
export default function wrapQueryPage(WrappedComponent) { | ||
function QueryPageWrapper({ queryId, onError, ...props }) { | ||
const [query, setQuery] = useState(null); | ||
const onErrorRef = useRef(); | ||
onErrorRef.current = onError; | ||
|
||
useEffect(() => { | ||
let isCancelled = false; | ||
const promise = queryId ? Query.get({ id: queryId }) : Promise.resolve(Query.newQuery()); | ||
promise | ||
.then(result => { | ||
if (!isCancelled) { | ||
setQuery(result); | ||
} | ||
}) | ||
.catch(error => onErrorRef.current(error)); | ||
|
||
return () => { | ||
isCancelled = true; | ||
}; | ||
}, [queryId]); | ||
|
||
if (!query) { | ||
return <LoadingState className="flex-fill" />; | ||
} | ||
|
||
return <WrappedComponent query={query} onError={onError} {...props} />; | ||
} | ||
|
||
QueryPageWrapper.propTypes = { | ||
queryId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
}; | ||
|
||
QueryPageWrapper.defaultProps = { | ||
queryId: null, | ||
}; | ||
|
||
return QueryPageWrapper; | ||
} |