Skip to content

Commit

Permalink
feat(pkglist): add filter / loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Jul 7, 2024
1 parent d99abaa commit da4612e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 25 deletions.
102 changes: 83 additions & 19 deletions frontend/src/app/package-list/package-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,93 @@
<div class="chaotic-container-regular">
<h1 class="text-center text-4xl font-extrabold text-maroon">Package List</h1>
<p class="my-4 px-10 text-center text-lg text-text">
This package shows all packages currently deployed in Chaotic-AUR and their corresponding package names.
The list of all packages currently deployed in Chaotic-AUR and their corresponding package names can be
found below.
</p>
<p class="my-4 px-10 text-center text-lg text-text">
Total packages: <a class="text-red">{{ packageList.length }}</a>
Total packages: <a class="text-red">{{ packageList.length > 0 ? packageList.length : "loading ... ☕️" }}</a>
</p>

<ol class="relative pt-2.5">
<li class="mb-10">
@for (deployment of packageList; track deployment) {
<li>
<div
class="items-center justify-between rounded-lg border border-mauve bg-surface0 p-4 shadow-sm sm:flex"
>
<div class="lex text-sm font-bold text-maroon">
<a>{{ deployment.name }}</a>
<div class="container md:flex my-5 justify-center">
<input
(focusout)="searchPackage()"
(keyup.enter)="searchPackage()"
[(ngModel)]="searchTerm"
class="text-input mx-auto my-1 md:mx-1 block w-full rounded-lg border border-red bg-surface0 py-4 ps-10 text-sm text-maroon focus:border-red focus:bg-surface1 max-w-md"
id="input-search-pkg"
name="search-pkg"
placeholder="Search for a specific package ..."
required
type="search"
/>
</div>

<div>
@if (loading) {
<div class="mx-auto mt-5 p-5 text-center md:container md:mx-auto" role="status">
<svg
class="inline h-12 w-12 animate-spin fill-red text-gray-200"
aria-hidden="true"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span class="sr-only">Loading...</span>
</div>
}
</div>

@if (searchResults.length > 0) {
<h3 class="text-center pt-2.5 text-2xl font-extrabold text-maroon">Search results</h3>
<ol class="relative pt-2.5">
<li class="mb-10">
@for (result of searchResults; track result) {
<li>
<div
class="items-center justify-between rounded-lg border border-mauve bg-surface0 p-4 shadow-sm sm:flex"
>
<div class="lex text-sm font-bold text-maroon">
<a>{{ result.name }}</a>
</div>
<a class="mb-1 text-xs font-normal text-text sm:order-last sm:mb-0">
{{ result.fullString }}
</a>
</div>
</li>
}
</li>
</ol>
}

@if (packageList.length > 0) {
<h3 class="text-center pt-2.5 text-2xl font-extrabold text-maroon">All packages</h3>
<ol class="relative pt-2.5">
<li class="mb-10">
@for (deployment of packageList; track deployment) {
<li>
<div
class="items-center justify-between rounded-lg border border-mauve bg-surface0 p-4 shadow-sm sm:flex"
>
<div class="lex text-sm font-bold text-maroon">
<a>{{ deployment.name }}</a>
</div>
<a class="mb-1 text-xs font-normal text-text sm:order-last sm:mb-0">
{{ deployment.fullString }}
</a>
</div>
<a class="mb-1 text-xs font-normal text-text sm:order-last sm:mb-0">
{{ deployment.fullString }}
</a>
</div>
</li>
}
</li>
</ol>
</li>
}
</li>
</ol>
}
</div>
</div>
22 changes: 16 additions & 6 deletions frontend/src/app/package-list/package-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ import { CAUR_BACKEND_URL, PkgList } from "@./shared-lib"
import { CommonModule } from "@angular/common"
import { HttpClient } from "@angular/common/http"
import { Component } from "@angular/core"
import { ReactiveFormsModule } from "@angular/forms"
import { FormsModule, ReactiveFormsModule } from "@angular/forms"

@Component({
selector: "app-package-list",
standalone: true,
imports: [CommonModule, ReactiveFormsModule],
imports: [CommonModule, ReactiveFormsModule, FormsModule],
templateUrl: "./package-list.component.html",
styleUrl: "./package-list.component.css",
styleUrl: "./package-list.component.css"
})
export class PackageListComponent {
packageList: any[] = []
loading = true
searchTerm: string | undefined
searchResults: any[] = []

constructor(private httpClient: HttpClient) {
this.getPkgList()
void this.getPkgList()
}

/**
Expand All @@ -38,17 +41,24 @@ export class PackageListComponent {

pkgArray.push({
name: pkgname,
fullString: pkg,
fullString: pkg
})
})

return pkgArray
}

getPkgList = (): void => {
async getPkgList(): Promise<void> {
this.httpClient.get(`${CAUR_BACKEND_URL}/misc/pkglist`).subscribe((res): void => {
// @ts-ignore
this.packageList = this.parsePkgList(res.pkglist)
this.loading = false
})
}

async searchPackage(): Promise<void> {
this.loading = true
this.searchResults = this.packageList.filter((pkg) => pkg.name.includes(this.searchTerm))
this.loading = false
}
}

0 comments on commit da4612e

Please sign in to comment.