File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,12 +28,26 @@ class Content extends Component {
2828 }
2929
3030 getData = async ( id ) => {
31+ if ( ! localStorage . getItem ( 'devCon' ) ) {
32+ localStorage . setItem ( 'devCon' , '{}' ) ;
33+ }
3134 try {
3235 const { data } = await axios ( `https://raw.githubusercontent.com/devsonket/devsonket.github.io/develop/data/${ id } .json` ) ;
3336 let contributor ;
3437 try {
35- let { data } = await axios ( `https://api.github.com/repos/devsonket/devsonket.github.io/commits?path=data/${ id } .json` ) ;
36- contributor = contributorMap ( data ) ;
38+ const getLocalContributor = JSON . parse ( localStorage . getItem ( 'devCon' ) ) ;
39+ const getCurrentId = getLocalContributor [ id ] ;
40+ const getCurrentTime = Date . now ( ) ;
41+ let compareTime = 1000 * 60 * 60 ;
42+ if ( getCurrentId && ( getCurrentId [ 1 ] + compareTime >= getCurrentTime ) ) {
43+ contributor = getCurrentId [ 0 ] ;
44+ } else {
45+ contributor = await axios ( `https://api.github.com/repos/devsonket/devsonket.github.io/commits?path=data/${ id } .json` ) ;
46+ contributor = contributorMap ( contributor . data ) ;
47+ let dataForLocalStorage = [ contributor , Date . now ( ) ] ;
48+ getLocalContributor [ id ] = dataForLocalStorage ;
49+ localStorage . setItem ( 'devCon' , JSON . stringify ( getLocalContributor ) ) ;
50+ }
3751 } catch ( e ) {
3852 contributor = null ;
3953 }
You can’t perform that action at this time.
0 commit comments