@@ -53,8 +53,7 @@ function fetchRepos(force = false) {
5353 "Accept" : "application/vnd.github.v3+json" ,
5454 "If-None-Match" : ls . getKey ( "repo-etag" )
5555 }
56- } )
57- . then (
56+ } ) . then (
5857 function ( response ) {
5958 if ( response . status == 304 ) {
6059 try {
@@ -83,27 +82,62 @@ function fetchRepos(force = false) {
8382 updateRepos ( data ) ;
8483 } ) ;
8584 }
86- )
87- . catch ( function ( err ) {
85+ ) . catch ( function ( err ) {
8886 console . log ( "[FETCH Repo] Fetch Error!" , err ) ;
8987 } ) ;
9088}
9189
92- function updateRepos ( data ) {
93- $ ( "#repo" ) . html ( "" ) ;
94- data . forEach ( function ( i ) {
95- let outerDiv = createElement ( "div" , { class : "card z-depth-1 scale-card" } ) ;
96- let div1 = createElement ( "div" , { class : "card-content black-text" } ) ;
97- div1 . append ( createElement ( "span" , { class : "card-title" } , i . full_name ) ) ;
98- div1 . append ( createElement ( "p" , { } , i . description ) ) ;
99- let d = new Date ( i . updated_at ) ;
100- lastUpdated = formatDate ( d . getDay ( ) ) + "-" + formatDate ( ( d . getMonth ( ) + 1 ) ) + "-" + formatDate ( d . getFullYear ( ) ) + ", " + formatDate ( d . getHours ( ) ) + ":" + formatDate ( d . getMinutes ( ) ) ;
101- div1 . append ( createElement ( "p" , { } , "<b>Last Updated:</b> " + lastUpdated ) )
102- let div2 = createElement ( "div" , { class : "card-action" } ) ;
103- div2 . append ( createElement ( "a" , { href : i . html_url } , "View on GitHub" ) ) ;
104- outerDiv . append ( div1 ) ;
105- outerDiv . append ( div2 ) ;
106- $ ( "#repo" ) . append ( outerDiv ) ;
90+ function updateRepos ( data ) {
91+ const repoContainer = document . querySelector ( ".repo-container" ) ;
92+ data . forEach ( ( val ) => {
93+ // Creating Repo card
94+ let repoItem = createElement ( "div" , { class : "col-md-6 col-lg-4 repo-item" } ) ;
95+ let box = createElement ( "div" , { class : "box" } ) ;
96+ let icon = createElement ( "div" , { class : "icon" } ) ;
97+
98+ // Fetching image for repository
99+ let iconImg = val . name . split ( "-" ) [ 0 ] . toLowerCase ( ) ;
100+ let imgSource = "" ;
101+
102+ if ( iconImg === "website" ) {
103+ // For devcans website repo
104+ imgSource = "assets/img/icon.png"
105+ } else {
106+ if ( iconImg === "web" ) {
107+ iconImg = "html" ;
108+ }
109+ imgSource = `https://raw.githubusercontent.com/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/${ iconImg } /${ iconImg } .png` ;
110+ }
111+ icon . appendChild ( createElement ( "img" , { src : imgSource , class : "icon" , style : "background: #FCEEF3;" } ) ) ;
112+ box . appendChild ( icon ) ;
113+ let h3 = createElement ( "h3" , { class : "title" } ) ;
114+ h3 . innerHTML = `
115+ <a href="${ val . html_url } " target="_">${ val . name . replaceAll ( "-" , " " ) . toUpperCase ( ) } </a>
116+ ` ;
117+ box . appendChild ( h3 ) ;
118+ let p = createElement ( "p" , { class : "description" } ) ;
119+ p . innerHTML = val . description ;
120+ box . appendChild ( p ) ;
121+ repoItem . appendChild ( box ) ;
122+ repoContainer . appendChild ( repoItem ) ;
123+ } ) ;
124+
125+ // Setting up listener for show more button
126+ const button = document . querySelector ( ".more-btn" ) ;
127+ button . addEventListener ( "click" , ( ) => {
128+ button . childNodes [ 1 ] . classList . toggle ( "more-btn-inactive" ) ;
129+ let text = button . childNodes [ 3 ] . textContent ;
130+
131+ text == "Show More" ? text = "Show Less" : text = "Show More" ;
132+
133+ button . childNodes [ 3 ] . textContent = text ;
134+ button . childNodes [ 5 ] . classList . toggle ( "more-btn-inactive" ) ;
135+
136+ if ( button . childNodes [ 1 ] . classList . contains ( "more-btn-inactive" ) ) {
137+ repoContainer . style . maxHeight = 350 + "px" ;
138+ } else {
139+ repoContainer . style . maxHeight = repoContainer . scrollHeight + "px" ;
140+ }
107141 } ) ;
108142}
109143
@@ -113,8 +147,7 @@ function fetchTeam(force = false) {
113147 "Accept" : "application/vnd.github.v3+json" ,
114148 "If-None-Match" : ls . getKey ( "team-etag" )
115149 }
116- } )
117- . then (
150+ } ) . then (
118151 function ( response ) {
119152 if ( response . status == 304 ) {
120153 try {
@@ -143,21 +176,63 @@ function fetchTeam(force = false) {
143176 updateTeam ( data ) ;
144177 } ) ;
145178 }
146- )
147- . catch ( function ( err ) {
179+ ) . catch ( function ( err ) {
148180 console . log ( "[FETCH Team] Fetch Error!" , err ) ;
149181 } ) ;
150182}
151183
152- function updateTeam ( data ) {
153- let container = $ ( "#team" ) . find ( ".card-content" ) ;
154- container . html ( "" ) ;
155- data . forEach ( function ( i ) {
156- let anchor = createElement ( "a" , { href : i . html_url , target : "_blank" } ) ;
157- anchor . append ( createElement ( "img" , { class : "circle team-img tooltipped" , src : i . avatar_url , "data-tooltip" : i . login } ) ) ;
158- container . append ( anchor ) ;
184+ function updateTeam ( data ) {
185+ data . forEach ( ( member ) => {
186+ if ( ls . getKey ( member . node_id ) != null ) {
187+ // Fetching member info from local storage
188+ info = JSON . parse ( ls . getKey ( member . node_id ) ) ;
189+ setMember ( info ) ;
190+ } else {
191+ // Fetching member info from github api
192+ fetch ( member . url , {
193+ headers : {
194+ "Accept" : "application/vnd.github.v3+json" ,
195+ "If-None-Match" : ls . getKey ( "team-etag" )
196+ }
197+ } ) . then ( ( response ) => {
198+ if ( response . status != 200 ) {
199+ console . log ( "[Fetch Member Info] Status code" + response . status ) ;
200+ }
201+
202+ response . json ( ) . then ( ( info ) => {
203+ // Saving member info to local storage
204+ ls . setKey ( info . node_id , JSON . stringify ( info ) ) ;
205+ setMember ( info )
206+ } ) ;
207+ } ) . catch ( function ( err ) {
208+ console . log ( "[FETCH Team] Fetch Error!" , err ) ;
209+ } ) ;
210+ }
211+
159212 } ) ;
160- $ ( ".tooltipped" ) . tooltip ( ) ;
213+ }
214+
215+ function setMember ( info ) {
216+ // Creating member card
217+ const teamContainer = document . querySelector ( ".team-container" ) ;
218+ let outerDiv = createElement ( "div" , { class : "col-lg-2 col-md-4" } ) ;
219+ let member = createElement ( "div" , { class : "member" } ) ;
220+ let img = createElement ( "img" , { class : "img-fluid" , src : info . avatar_url } ) ;
221+ let memberInfo = createElement ( "div" , { class : "member-info" } ) ;
222+ let memberInfoContent = createElement ( "div" , { class : "member-info-content" } ) ;
223+ let h4 = createElement ( "h4" ) ;
224+ h4 . innerHTML = info . name ;
225+ memberInfoContent . appendChild ( h4 ) ;
226+ let social = createElement ( "div" , { class : "social" } ) ;
227+ social . innerHTML = `
228+ <a href="${ info . html_url } " target="_"><i class="fa fa-github"></i></a>
229+ ` ;
230+ memberInfoContent . appendChild ( social ) ;
231+ memberInfo . appendChild ( memberInfoContent ) ;
232+ member . appendChild ( img ) ;
233+ member . appendChild ( memberInfo ) ;
234+ outerDiv . appendChild ( member ) ;
235+ teamContainer . appendChild ( outerDiv ) ;
161236}
162237
163238function createElement ( tag , options = { } , html = "" ) {
0 commit comments