Skip to content

Commit

Permalink
Merge pull request #7 from anrouxel/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
anrouxel authored Mar 7, 2024
2 parents d6c8474 + 9c18e7c commit e2a3aae
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Configurations/GithubSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ namespace anrouxel.Configurations
public class GithubSettings
{
public string GITHUB_API_URL { get; set; } = null!;

public string GITHUB_PROFILE_URL { get; set; } = null!;
}
}
6 changes: 3 additions & 3 deletions Models/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public class Repository

public Uri? deployments_url { get; set; }

public string? created_at { get; set; }
public DateTimeOffset created_at { get; set; }

public string? updated_at { get; set; }
public DateTimeOffset updated_at { get; set; }

public string? pushed_at { get; set; }
public DateTimeOffset pushed_at { get; set; }

public Uri? git_url { get; set; }

Expand Down
9 changes: 9 additions & 0 deletions Pages/Home/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/"
@using anrouxel.Pages.Home.Sections

<PageTitle>Accueil</PageTitle>

<Banners Title="Site en construction" />

<Home></Home>
<Projects></Projects>
18 changes: 8 additions & 10 deletions Pages/Home.razor → Pages/Home/Sections/Home.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
@page "/"

<PageTitle>Accueil</PageTitle>

<Banners Title="Site en construction" />

<section class="w-screen h-screen">
<section class="w-screen h-screen">
<div class="flex size-full">
<div class="flex-auto size-full hidden md:flex">
<div class="m-auto">
Expand All @@ -20,8 +14,12 @@
<div class="text-4xl font-bold text-EUGrey-40 w-fit m-auto" w-fit>
Bienvenue, je suis</div>
<div class="my-5" />
<div class="text-7xl font-Metropolis font-bold text-EUPurple-40 w-fit m-auto">
Antonin Rouxel</div>
@if (profile != null)
{
<div class="text-7xl font-Metropolis font-bold text-EUPurple-40 w-fit m-auto">
@profile.name
</div>
}
<div class="my-5" />
<div
class="text-xl font-mono font-bold text-EUGrey-40 bg-EUGrey-80 w-fit m-auto py-3 px-10 rounded-2xl shadow-2xl">
Expand Down Expand Up @@ -57,4 +55,4 @@
</button>
</div>
</div>
</section>
</section>
10 changes: 3 additions & 7 deletions Pages/Home.razor.cs → Pages/Home/Sections/Home.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using anrouxel.Services;
using Microsoft.AspNetCore.Components;

namespace anrouxel.Pages
namespace anrouxel.Pages.Home.Sections
{
public partial class Home
{
Expand All @@ -16,13 +16,9 @@ public partial class Home

private Profile? profile { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnInitializedAsync()
{
if (firstRender)
{
profile = await _githubService.GetProfileAsync();
StateHasChanged();
}
profile = await _githubService.GetProfileAsync();
}

private void navigateTo(string uri)
Expand Down
55 changes: 55 additions & 0 deletions Pages/Home/Sections/Projects.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<section class="w-screen h-screen">
<div class="flex size-full">
<div class="flex-auto size-full flex">
<div class="m-auto max-w-md">
<form class="mx-auto">
<label for="default-search"
class="mb-2 text-sm font-medium text-EUGrey-80 sr-only">Search</label>
<div class="relative">
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
<svg class="w-4 h-4 text-EUGrey-80" aria-hidden="true"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z" />
</svg>
</div>
<input type="search" id="default-search"
class="block w-full p-4 ps-10 text-sm text-EUGrey-80 border border-EUGrey-80 rounded-2xl bg-EUGrey-10 focus:ring-EUPurple-140 focus:border-EUPurple-140"
placeholder="Search Mockups, Logos..." required />
<button type="submit"
class="text-white absolute w-fit inset-y-0 end-0 bg-EUPurple-100 hover:bg-EUPurple-110 focus:ring-4 focus:outline-none focus:ring-EUPurple-120 font-medium rounded-lg text-sm px-4 py-2 m-2">Search</button>
</div>
</form>

<div class="mt-5 overflow-y-auto max-h-96">
@foreach (var repository in repositories)
{
<div class="flex justify-between gap-x-6 p-5 bg-EUGrey-80 rounded-2xl font-mono">
<div class="flex min-w-0 gap-x-4">
<div class="min-w-0 flex-auto">
<p class="text-sm font-semibold leading-6 text-EUGrey-20">@repository.name</p>
<p class="mt-1 truncate text-xs leading-5 text-EUGrey-40">@repository.description</p>
</div>
</div>
<div class="hidden shrink-0 sm:flex sm:flex-col sm:items-end">
<p class="text-sm leading-6 text-EUGrey-20">@repository.language</p>
<p class="mt-1 text-xs leading-5 text-EUGrey-40"><time
datetime="@(repository.pushed_at)">@(CalculateTimeDifference(repository.pushed_at))</time>
</p>
</div>
</div>

@if (repositories.IndexOf(repository) != repositories.Count - 1)
{
<div class="my-5" />
}
}
</div>
</div>
</div>
<div class="flex-auto size-full flex">
<div class="m-auto">
</div>
</div>
</div>
</section>
66 changes: 66 additions & 0 deletions Pages/Home/Sections/Projects.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

using System.Net.Http.Json;
using anrouxel.Models;
using anrouxel.Services;
using Microsoft.AspNetCore.Components;

namespace anrouxel.Pages.Home.Sections
{
public partial class Projects
{
[Inject]
private NavigationManager navigationManager { get; set; } = null!;

[Inject]
private IGithubService _githubService { get; set; } = null!;

private List<Repository> repositories = new List<Repository>();

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
repositories = await _githubService.GetRepositoriesAsync();
StateHasChanged();
}
}

private string CalculateTimeDifference(DateTimeOffset time)
{
DateTimeOffset now = DateTimeOffset.Now;
TimeSpan difference = now - time;

if (difference.TotalDays >= 365)
{
return $"{(int)(difference.TotalDays / 365)} année{(difference.TotalDays >= 730 ? "s" : "")}";
}
else if (difference.TotalDays >= 30)
{
return $"{(int)(difference.TotalDays / 30)} mois";
}
else if (difference.TotalDays >= 1)
{
return $"{(int)difference.TotalDays} jour{(difference.TotalDays >= 2 ? "s" : "")}";
}
else if (difference.TotalHours >= 1)
{
return $"{(int)difference.TotalHours} heure{(difference.TotalHours >= 2 ? "s" : "")}";
}
else if (difference.TotalMinutes >= 1)
{
return $"{(int)difference.TotalMinutes} minute{(difference.TotalMinutes >= 2 ? "s" : "")}";
}
else if (difference.TotalSeconds >= 1)
{
return $"{(int)difference.TotalSeconds} seconde{(difference.TotalSeconds >= 2 ? "s" : "")}";
} else {
return "à l'instant";
}
}

private void navigateTo(string uri)
{
navigationManager.NavigateTo(uri, true);
}
}
}
31 changes: 18 additions & 13 deletions Services/GithubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,40 @@ namespace anrouxel.Services
{
public class GithubService : IGithubService
{
private readonly GithubSettings _githubSettings;

private readonly HttpClient _httpClient;

public GithubService(
IOptions<GithubSettings> githubSettings
) {
_githubSettings = githubSettings.Value;
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri(githubSettings.Value.GITHUB_API_URL);

Console.WriteLine($"Github API URL: {githubSettings.Value.GITHUB_API_URL}");
Console.WriteLine($"HttpClient BaseAddress: {_httpClient.BaseAddress}");
}

public async Task<Profile?> GetProfileAsync()
private string MakeUrl(string? path)
{
return await _httpClient.GetFromJsonAsync<Profile>("");
if (path == null)
{
return _githubSettings.GITHUB_PROFILE_URL;
}
return $"{_githubSettings.GITHUB_PROFILE_URL}/{path}";
}

public async Task<Repository[]?> GetRepositoriesAsync()
public async Task<Profile?> GetProfileAsync()
{
return await _httpClient.GetFromJsonAsync<Repository[]>("/repos");
return await _httpClient.GetFromJsonAsync<Profile>(MakeUrl(null));
}

public async Task<string?> GetAvatarAsync()
public async Task<List<Repository>> GetRepositoriesAsync()
{
var avatar_url = await _httpClient.GetFromJsonAsync<Profile>("");

Console.WriteLine(avatar_url!.avatar_url);

return avatar_url!.avatar_url;
var repositories = await _httpClient.GetFromJsonAsync<List<Repository>>(MakeUrl("repos"));
if (repositories == null)
{
return new List<Repository>();
}
return repositories;
}
}
}
4 changes: 1 addition & 3 deletions Services/IGithubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public interface IGithubService
{
Task<Profile?> GetProfileAsync();

Task<Repository[]?> GetRepositoriesAsync();

Task<string?> GetAvatarAsync();
Task<List<Repository>> GetRepositoriesAsync();
}
}
3 changes: 2 additions & 1 deletion wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"GithubSettings": {
"GITHUB_API_URL": "https://api.github.com/users/anrouxel"
"GITHUB_API_URL": "https://api.github.com/users/",
"GITHUB_PROFILE_URL": "anrouxel"
}
}

0 comments on commit e2a3aae

Please sign in to comment.