@@ -3,6 +3,8 @@ import { majorScale, Heading, Pane, Spinner } from 'evergreen-ui'
3
3
import { useLocation , Redirect } from 'react-router-dom'
4
4
import { useStateValue , actions , loadingState } from '../state'
5
5
6
+ import { getAllDatabases , removeDatabase } from '../database'
7
+
6
8
import ProgramList from '../components/DatabaseList'
7
9
8
10
function useQuery ( ) {
@@ -24,6 +26,24 @@ function SearchResultsView () {
24
26
)
25
27
}
26
28
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
+
27
47
return (
28
48
< Pane display = 'flex' justifyContent = 'center' >
29
49
< Pane
@@ -38,7 +58,9 @@ function SearchResultsView () {
38
58
{ programs . length } programs found
39
59
</ Heading >
40
60
</ 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 } /> }
42
64
</ Pane >
43
65
</ Pane >
44
66
)
0 commit comments