File indexing completed on 2025-01-26 05:27:59

0001 import React, { Component } from 'react';
0002 import ProductGit from './ProductGit';
0003 
0004 class ProductsMyGitContainer extends React.Component {
0005   constructor(props){
0006         super(props);
0007     this.gitUrl = `/json/gitlab?username=${props.user.username}`;
0008     this.gitUserUrl = '/json/gitlabfetchuser?username=';
0009     this.state = {items:[],user:null};
0010   }
0011 
0012   componentDidMount() {
0013     fetch(this.gitUrl)
0014       .then(response => response.json())
0015       .then(data => {
0016 
0017         if(data.user)
0018         {
0019           this.setState({user:data.user});
0020         }
0021         if(data.projects)
0022         {
0023           data.projects.map((fi,index) => {
0024             fi.user_avatar_url = data.user.avatar_url;            
0025           });
0026           this.setState({items:data.projects});
0027         }
0028         
0029       });
0030   }
0031 
0032   render(){
0033     let container;
0034     container = <div> <h1> Projects </h1></div>
0035     if (this.state.items){
0036       const items = this.state.items.sort(function(a,b){
0037                 return new Date(b.created_at) - new Date(a.created_at);
0038         });
0039       const products = items.map((product,index) => (
0040         <li key={index}>
0041           <ProductGit product={product}/>
0042         </li>
0043       ));
0044      container = <ul>{products}</ul>
0045     }
0046     return (
0047       <div className="panelContainer">
0048         <div className="title"> Projects</div>
0049         {container}
0050       </div>
0051     )
0052   }
0053 }
0054 
0055 export default ProductsMyGitContainer;