@@ -42,8 +42,8 @@ $(document).ready(function(){
4242 $ ( ".collapsible" ) . collapsible ( ) ;
4343 $ ( ".tooltipped" ) . tooltip ( ) ;
4444
45- // fetchRepos();
46- // fetchTeam();
45+ fetchRepos ( ) ;
46+ fetchTeam ( ) ;
4747} ) ;
4848
4949function fetchRepos ( force = false ) {
@@ -55,6 +55,17 @@ function fetchRepos(force = false) {
5555 } )
5656 . then (
5757 function ( response ) {
58+ if ( response . status == 304 ) {
59+ try {
60+ let data = JSON . parse ( ls . getKey ( "repo-data" ) ) ;
61+ updateRepos ( data ) ;
62+ console . log ( "[LOCAL Repo] Loaded cached copy." ) ;
63+ } catch ( e ) {
64+ ls . removeKey ( "repo-etag" ) ;
65+ setTimeout ( fetchRepos ( ) ) ;
66+ }
67+ return ;
68+ }
5869 if ( response . status !== 200 ) {
5970 console . log ( "[FETCH Repo] Request failed!. Status Code: " + response . status ) ;
6071 return ;
@@ -63,6 +74,7 @@ function fetchRepos(force = false) {
6374 response . json ( ) . then ( function ( data ) {
6475 try {
6576 ls . setKey ( "repo-etag" , response . headers . get ( "etag" ) ) ;
77+ ls . setKey ( "repo-data" , JSON . stringify ( data ) ) ;
6678 } catch ( e ) {
6779 console . log ( "[FETCH Repo] ETag Missing" ) ;
6880 }
@@ -77,6 +89,7 @@ function fetchRepos(force = false) {
7789}
7890
7991function updateRepos ( data ) {
92+ $ ( "#repo" ) . html ( "" ) ;
8093 data . forEach ( function ( i ) {
8194 let outerDiv = createElement ( "div" , { class : "card z-depth-1 scale-card" } ) ;
8295 let div1 = createElement ( "div" , { class : "card-content black-text" } ) ;
@@ -102,6 +115,17 @@ function fetchTeam(force = false) {
102115 } )
103116 . then (
104117 function ( response ) {
118+ if ( response . status == 304 ) {
119+ try {
120+ let data = JSON . parse ( ls . getKey ( "team-data" ) ) ;
121+ updateTeam ( data ) ;
122+ console . log ( "[LOCAL Team] Loaded cached copy." ) ;
123+ } catch ( e ) {
124+ ls . removeKey ( "team-etag" ) ;
125+ setTimeout ( fetchTeam ( ) ) ;
126+ }
127+ return ;
128+ }
105129 if ( response . status !== 200 ) {
106130 console . log ( "[FETCH Team] Request failed!. Status Code: " + response . status ) ;
107131 return ;
@@ -110,6 +134,7 @@ function fetchTeam(force = false) {
110134 response . json ( ) . then ( function ( data ) {
111135 try {
112136 ls . setKey ( "team-etag" , response . headers . get ( "etag" ) ) ;
137+ ls . setKey ( "team-data" , JSON . stringify ( data ) ) ;
113138 } catch ( e ) {
114139 console . log ( "[FETCH Team] ETag Missing" ) ;
115140 }
@@ -125,6 +150,7 @@ function fetchTeam(force = false) {
125150
126151function updateTeam ( data ) {
127152 let container = $ ( "#team" ) . find ( ".card-content" ) ;
153+ container . html ( ) ;
128154 data . forEach ( function ( i ) {
129155 let anchor = createElement ( "a" , { href : i . html_url , target : "_blank" } ) ;
130156 anchor . append ( createElement ( "img" , { class : "circle team-img tooltipped" , src : i . avatar_url , "data-tooltip" : i . login } ) ) ;
0 commit comments