Skip to content

Commit

Permalink
Added loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
chunkangwong committed Sep 10, 2023
1 parent 521ca1e commit 36c0392
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const setRenderer = async () => {
function App() {
const viewDiv = useRef<HTMLDivElement>(null);
const layerView = useRef<__esri.FeatureLayerView>();
const [loading, setLoading] = useState(true);
const [count, setCount] = useState(countDefault);
const [orderBy, setOrderBy] = useState(orderByDefault);
const [year, setYear] = useState(yearDefault);
Expand All @@ -60,6 +61,7 @@ function App() {
if (!layer || !layerView.current) {
return;
}
setLoading(true);
const query = new TopFeaturesQuery({
topFilter: new TopFilter({
topCount: count,
Expand All @@ -81,6 +83,7 @@ function App() {
});

setGraphics(results.features);
setLoading(false);
};
filterItems();
}, [orderBy, count, year]);
Expand Down Expand Up @@ -116,7 +119,7 @@ function App() {
handleYearChange={handleYearChange}
handleReset={handleReset}
/>
<Results year={year} graphics={graphics} />
<Results year={year} graphics={graphics} loading={loading} />
</CalcitePanel>
</CalciteShellPanel>
<div id="viewDiv" ref={viewDiv} />
Expand Down
4 changes: 3 additions & 1 deletion src/components/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { view } from "../arcgis";
interface ResultsProps {
graphics: __esri.Graphic[];
year: string;
loading: boolean;
}

const Results = ({ graphics, year }: ResultsProps) => {
const Results = ({ graphics, year, loading }: ResultsProps) => {
const handleResultClick = (graphic: __esri.Graphic, index: number) => () => {
const popup = graphics && graphics[index];
if (popup) {
Expand All @@ -35,6 +36,7 @@ const Results = ({ graphics, year }: ResultsProps) => {
collapsible
heading={`Results (${graphics.length})`}
open={graphics.length > 0}
loading={loading}
>
<CalciteList>
{graphics.map((graphic, index) => (
Expand Down

0 comments on commit 36c0392

Please sign in to comment.