-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c3f2e3
commit 73158bc
Showing
9 changed files
with
432 additions
and
214 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 was deleted.
Oops, something went wrong.
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,37 @@ | ||
import React from 'react'; | ||
import axios from 'axios'; | ||
import log from 'loglevel'; | ||
|
||
export default function useLoadData( | ||
startDate, | ||
endDate, | ||
field1, | ||
field2, | ||
getNum1 = (e) => e.total, | ||
) { | ||
const [data, setData] = React.useState(undefined); | ||
|
||
async function load(baseUrl, startDate, endDate) { | ||
const res = await axios.get( | ||
`${baseUrl}?${ | ||
startDate ? 'capture_created_start_date=' + startDate : '' | ||
}&${endDate ? 'capture_created_end_date=' + endDate : ''}`, | ||
); | ||
const { data } = res; | ||
log.warn('load data: ', data); | ||
setData({ | ||
num1: getNum1(data[field1]), | ||
top: data[field1][field2].map((p) => ({ | ||
name: p.name, | ||
num: p.number, | ||
})), | ||
}); | ||
} | ||
|
||
React.useEffect(() => { | ||
setData(undefined); | ||
load('http://47.91.14.192:3006/capture/statistics', startDate, endDate); | ||
}, [startDate, endDate]); | ||
|
||
return data; | ||
} |
Oops, something went wrong.