Skip to content

Commit bf2b462

Browse files
committed
feat: better dispatch
1 parent 654dd1d commit bf2b462

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/components/footer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { HStack, Text } from "@chakra-ui/react";
22
import { useDuckDb } from "duckdb-wasm-kit";
3+
import { useStacGeoparquet } from "./stac-geoparquet/hooks";
34
export default function Footer() {
45
const { loading, error } = useDuckDb();
6+
const state = useStacGeoparquet();
7+
58
return (
69
<HStack
710
style={{
@@ -14,6 +17,7 @@ export default function Footer() {
1417
>
1518
{loading && <Text>Loading DuckDB...</Text>}
1619
{error && <Text color={"red"}>DuckDB error: {error.toString()}</Text>}
20+
{state.path && !state.metadata && <Text>Loading {state.path}</Text>}
1721
</HStack>
1822
);
1923
}

src/components/stac-geoparquet/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export type StacGeoparquetAction =
2525
| { type: "set-path"; path: string }
2626
| { type: "set-metadata"; metadata: StacGeoparquetMetadata }
2727
| { type: "set-table"; table: Table }
28-
| { type: "set-id"; id?: string }
29-
| { type: "set-item"; item?: StacItem };
28+
| { type: "set-id"; id: string }
29+
| { type: "set-item"; item: StacItem };
3030

3131
export const StacGeoparquetContext =
3232
createContext<StacGeoparquetContextType | null>(null);

src/components/stac-geoparquet/provider.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ export default function StacGeoparquetProvider({
4242

4343
useEffect(() => {
4444
if (state.path) {
45-
dispatch({ type: "set-id" });
46-
dispatch({ type: "set-item" });
4745
if (connection) {
4846
(async () => {
4947
let result;
@@ -129,9 +127,8 @@ export default function StacGeoparquetProvider({
129127
}
130128
}, [state.path, connection, dispatch]);
131129

132-
// TODO I don't like this depending on state.path.
133130
useEffect(() => {
134-
if (state.id) {
131+
if (state.id && state.path) {
135132
if (connection) {
136133
(async () => {
137134
// TODO refactor query so we don't repeat logic.
@@ -144,8 +141,6 @@ export default function StacGeoparquetProvider({
144141
} else {
145142
// TODO Handle missing connection
146143
}
147-
} else {
148-
dispatch({ type: "set-item" });
149144
}
150145
}, [state.id, state.path, connection, dispatch]);
151146

@@ -159,13 +154,13 @@ export default function StacGeoparquetProvider({
159154
function reducer(state: StacGeoparquetState, action: StacGeoparquetAction) {
160155
switch (action.type) {
161156
case "set-path":
162-
return { ...state, path: action.path };
157+
return { ...state, path: action.path, id: undefined, item: undefined };
163158
case "set-metadata":
164159
return { ...state, metadata: action.metadata };
165160
case "set-table":
166161
return { ...state, table: action.table };
167162
case "set-id":
168-
return { ...state, id: action.id };
163+
return { ...state, id: action.id, item: undefined };
169164
case "set-item":
170165
return { ...state, item: action.item };
171166
}

0 commit comments

Comments
 (0)