Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 591bcb6

Browse files
committed
fix search results remove button
1 parent 4ce58ea commit 591bcb6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/views/SearchResults.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { majorScale, Heading, Pane, Spinner } from 'evergreen-ui'
33
import { useLocation, Redirect } from 'react-router-dom'
44
import { useStateValue, actions, loadingState } from '../state'
55

6+
import { getAllDatabases, removeDatabase } from '../database'
7+
68
import ProgramList from '../components/DatabaseList'
79

810
function useQuery () {
@@ -24,6 +26,24 @@ function SearchResultsView () {
2426
)
2527
}
2628

29+
async function fetchDatabases () {
30+
dispatch({ type: actions.PROGRAMS.SET_PROGRAMS_LOADING, loading: true })
31+
const programs = await getAllDatabases()
32+
dispatch({ type: actions.PROGRAMS.SET_PROGRAMS, programs: programs.reverse() })
33+
dispatch({ type: actions.PROGRAMS.SET_PROGRAMS_LOADING, loading: false })
34+
return programs
35+
}
36+
37+
const handleRemoveDatabase = (hash, program) => {
38+
console.log("Remove database...", hash, program)
39+
removeDatabase(hash).then(() => {
40+
console.log("Removed")
41+
fetchDatabases().then((data) => {
42+
console.log("Loaded programs", data)
43+
})
44+
})
45+
}
46+
2747
return (
2848
<Pane display='flex' justifyContent='center'>
2949
<Pane
@@ -38,7 +58,9 @@ function SearchResultsView () {
3858
{programs.length} programs found
3959
</Heading>
4060
</Pane>
41-
{programs !== loadingState ? <ProgramList programs={programs} /> : <Spinner marginX='auto' marginY={120} />}
61+
{programs !== loadingState
62+
? <ProgramList programs={programs} onRemove={handleRemoveDatabase} />
63+
: <Spinner marginX='auto' marginY={120} />}
4264
</Pane>
4365
</Pane>
4466
)

0 commit comments

Comments
 (0)