diff --git a/e2e/app.spec.ts b/e2e/app.spec.ts index 60e5416..75d6f1f 100644 --- a/e2e/app.spec.ts +++ b/e2e/app.spec.ts @@ -39,4 +39,34 @@ test.describe('Git Catalogue App', () => { expect(errors).toEqual([]); }); + + test('should not scroll the tab content sideways', async ({ page }) => { + const repository = { + id: 1, + name: 'mod-example', + full_name: 'azerothcore/mod-example', + description: 'Example module', + stargazers_count: 5, + created_at: '2024-01-01T00:00:00Z', + default_branch: 'master', + owner: { login: 'azerothcore' }, + html_url: 'https://github.com/azerothcore/mod-example', + forks_count: 0, + watchers_count: 0, + topics: ['azerothcore-module'], + }; + const config = await (await page.request.get('/assets/config.json')).json(); + const organizations: Record> = {}; + for (const { org, topic } of Object.values<{ org: string; topic: string }>(config.tabs)) { + organizations[org] = { ...organizations[org], [topic]: [repository] }; + } + // the paginators only render with results, and the CI fixture has none + await page.route('**/catalogue.json', (route) => route.fulfill({ json: { organizations } })); + + await page.goto('/'); + await expect(page.locator('a.repo-row').first()).toBeVisible(); + + const tabBody = page.locator('.mat-mdc-tab-body-active .mat-mdc-tab-body-content'); + expect(await tabBody.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0); + }); }); \ No newline at end of file diff --git a/src/app/catalogue/catalogue.component.html b/src/app/catalogue/catalogue.component.html index 5387317..4181266 100644 --- a/src/app/catalogue/catalogue.component.html +++ b/src/app/catalogue/catalogue.component.html @@ -1,3 +1,13 @@ +@if (veilVisible) { + +} +
diff --git a/src/app/catalogue/catalogue.component.scss b/src/app/catalogue/catalogue.component.scss new file mode 100644 index 0000000..b0787b2 --- /dev/null +++ b/src/app/catalogue/catalogue.component.scss @@ -0,0 +1,76 @@ +.route-veil { + position: fixed; + inset: 0; + z-index: 9999; + display: flex; + align-items: center; + justify-content: center; + background: #0f1217; + color: #f6f7f9; + pointer-events: none; + animation: veil-sweep 0.85s cubic-bezier(0.76, 0, 0.24, 1) both; + will-change: transform; +} + +.route-veil-brand { + display: flex; + flex-direction: column; + align-items: center; + gap: 0.7rem; +} + +.route-veil-mark { + width: 46px; + height: 2px; + background: #b4232a; + transform-origin: center; + animation: veil-mark 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) 0.18s both; +} + +.route-veil-name { + font-size: 0.95rem; + font-weight: 700; + letter-spacing: 0.34em; + text-transform: uppercase; +} + +.route-veil-label { + color: rgba(246, 247, 249, 0.5); + font-size: 0.6rem; + letter-spacing: 0.44em; + text-transform: uppercase; +} + +@keyframes veil-sweep { + 0% { + transform: translateY(-100%); + } + + 30% { + transform: translateY(0); + } + + 62% { + transform: translateY(0); + } + + 100% { + transform: translateY(-100%); + } +} + +@keyframes veil-mark { + from { + transform: scaleX(0); + } + + to { + transform: scaleX(1); + } +} + +@media (prefers-reduced-motion: reduce) { + .route-veil { + display: none; + } +} diff --git a/src/app/catalogue/catalogue.component.ts b/src/app/catalogue/catalogue.component.ts index e65a37f..c387659 100644 --- a/src/app/catalogue/catalogue.component.ts +++ b/src/app/catalogue/catalogue.component.ts @@ -1,8 +1,57 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; +import { NavigationStart, Router } from '@angular/router'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-catalogue', templateUrl: './catalogue.component.html', + styleUrls: ['./catalogue.component.scss'], standalone: false }) -export class CatalogueComponent {} +export class CatalogueComponent implements OnDestroy { + veilVisible = false; + + private readonly subscription = new Subscription(); + private showTimer?: number; + private hideTimer?: number; + private readonly reduceMotion = + typeof window !== 'undefined' && !!window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches; + + constructor(private readonly router: Router) { + document.body.classList.remove('catalogue-ready'); + + if (!this.reduceMotion) { + this.veilVisible = true; + this.hideTimer = window.setTimeout(() => this.finishTransition(), 900); + } else { + document.body.classList.add('catalogue-ready'); + } + + this.subscription.add( + this.router.events.subscribe((event) => { + if (!(event instanceof NavigationStart) || this.reduceMotion) { + return; + } + + window.clearTimeout(this.showTimer); + window.clearTimeout(this.hideTimer); + document.body.classList.remove('catalogue-ready'); + this.veilVisible = false; + this.showTimer = window.setTimeout(() => (this.veilVisible = true), 20); + this.hideTimer = window.setTimeout(() => this.finishTransition(), 900); + }), + ); + } + + ngOnDestroy(): void { + this.subscription.unsubscribe(); + window.clearTimeout(this.showTimer); + window.clearTimeout(this.hideTimer); + document.body.classList.remove('catalogue-ready'); + } + + private finishTransition(): void { + this.veilVisible = false; + document.body.classList.add('catalogue-ready'); + } +} diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index cda7a4e..4d208fe 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,66 +1,219 @@ -
-
- Search an item by name: +
+
+

AzerothCore · Catalogue

+

Modules, tools and scripts for your server.

+

+ Browse everything the community maintains. Search by name, description or topic. Can't find a repository? + Learn how to add it +

-
-
- - - +
+ - -
- +
+ - -
+
+ + +
+
+
+
-
-
-

Want to submit your repository? Check the instructions here

+ @if (activeFilterCount) { +
+ Active + @for (topic of selectedTopics; track topic) { + + } + @if (selectedLanguage) { + + } + @if (minStars > 0) { + + } +
-
-
+ } -
-
- - -
-
- - -
+ @if (catalogueService.tabIndex !== -1) { +
+ + @for (key of catalogueService.confTabsKeys; track key) { + + @if (catalogueService.items$[key] | async; as items) { +
+ @if (filtersOpen) { +
+
+
+ Topics +
+ @for (topic of topTopics(items); track topic) { + + } @empty { + No topics in this tab + } +
+
- - -
- - -
-
+
+ + +
+ +
+ + +
+
+ +

+ Tip: topic:lua, lang:TypeScript, owner:azerothcore, stars:>100 +

+
+ } + + + + + + +
+ {{ + search ? searchStatus(filteredLength(items)) : repositoryCount(filteredLength(items)) + }} +
+ @if (search || activeFilterCount) { + + } + @if (filteredLength(items) > 0) { + + } +
+
+ + @if (filteredLength(items) > 0) { +
+ @for (item of currentPageItems(items); track item.id; let i = $index) { + + } +
+ + + } @else if (search || activeFilterCount) { +
+ +
No repositories found
+ @if (search) { +

Nothing matches “{{ search }}”. Try a different name, description or topic.

+ } @else { +

No repositories match the selected filters.

+ } + +
+ } +
+ } @else { +
+

Loading repositories…

+ +
+ } + + } + +
+ } +
diff --git a/src/app/home/home.component.scss b/src/app/home/home.component.scss new file mode 100644 index 0000000..7fd0864 --- /dev/null +++ b/src/app/home/home.component.scss @@ -0,0 +1,730 @@ +:host { + display: block; + min-height: 100vh; + padding: 0 2.5rem 4rem; + background: #f6f7f9; + color: #14171c; +} + +.catalogue-v2 { + max-width: 1120px; + margin: 0 auto; +} + +.masthead { + padding: 3.5rem 0 0; + animation: rise 0.5s ease both; +} + +@keyframes rise { + from { + opacity: 0; + transform: translateY(12px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +.eyebrow { + display: inline-flex; + align-items: center; + gap: 0.7rem; + margin: 0 0 1.15rem; + color: #4a5563; + font-size: 0.84rem; + font-weight: 600; + letter-spacing: 0.2em; + text-transform: uppercase; + + &::before { + content: ''; + width: 30px; + height: 2px; + background: #b4232a; + transform: scaleX(0); + transform-origin: left center; + animation: eyebrow-line 0.7s cubic-bezier(0.22, 0.61, 0.36, 1) 0.1s forwards; + } + + &::after { + content: ''; + width: 5px; + height: 5px; + border-radius: 50%; + background: #b4232a; + animation: eyebrow-dot 2.6s ease-in-out 1.2s infinite; + } +} + +.eyebrow-text { + display: inline-block; + animation: eyebrow-text 0.7s cubic-bezier(0.22, 0.61, 0.36, 1) 0.18s both; +} + +@keyframes eyebrow-line { + to { + transform: scaleX(1); + } +} + +@keyframes eyebrow-text { + from { + opacity: 0; + transform: translateY(4px); + letter-spacing: 0.28em; + } + + to { + opacity: 1; + transform: translateY(0); + letter-spacing: 0.2em; + } +} + +@keyframes eyebrow-dot { + 0%, + 100% { + opacity: 0.3; + box-shadow: 0 0 0 0 rgba(180, 35, 42, 0.16); + } + + 50% { + opacity: 1; + box-shadow: 0 0 0 4px rgba(180, 35, 42, 0.08); + } +} + +h1 { + margin: 0; + color: #0e1116; + font-size: clamp(1.9rem, 4vw, 2.7rem); + font-weight: 700; + letter-spacing: -0.03em; + line-height: 1.12; +} + +.lede { + margin: 1rem 0 0; + color: #5f6b7a; + font-size: 0.98rem; + line-height: 1.6; + + a { + color: #14171c; + text-decoration: underline; + text-decoration-color: #c9cfd8; + text-underline-offset: 3px; + + &:hover { + text-decoration-color: #b4232a; + } + } +} + +.search-row { + display: grid; + grid-template-columns: minmax(0, 1fr) auto; + gap: 0.85rem; + align-items: center; + margin-top: 2rem; +} + +.search-box { + position: relative; + + .search-icon { + position: absolute; + top: 50%; + left: 1.15rem; + transform: translateY(-50%); + color: #8a94a3; + font-size: 0.95rem; + pointer-events: none; + } + + input { + width: 100%; + height: 56px; + padding: 0 3.2rem 0 2.9rem; + border: 1px solid #dfe3e9; + border-radius: 14px; + background: #fff; + color: #14171c; + font-size: 1rem; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); + transition: border-color 0.15s ease, box-shadow 0.15s ease; + + &::placeholder { + color: #8a94a3; + } + + &:focus { + outline: none; + border-color: #b4232a; + box-shadow: 0 0 0 4px rgba(180, 35, 42, 0.12); + } + } + + .search-clear { + position: absolute; + top: 50%; + right: 0.9rem; + display: flex; + align-items: center; + justify-content: center; + width: 2rem; + height: 2rem; + padding: 0; + transform: translateY(-50%); + border: 0; + border-radius: 8px; + background: transparent; + color: #6b7686; + font-size: 1.25rem; + line-height: 1; + cursor: pointer; + + &:hover { + background: #eef0f3; + color: #14171c; + } + } + + .search-hint { + position: absolute; + top: 50%; + right: 1rem; + padding: 0.15rem 0.45rem; + transform: translateY(-50%); + border: 1px solid #dfe3e9; + border-radius: 6px; + background: #f8f9fb; + color: #8a94a3; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.7rem; + } +} + +.toolbar-actions { + display: flex; + gap: 0.6rem; + align-items: stretch; +} + +.filter-toggle { + display: inline-flex; + align-items: center; + gap: 0.5rem; + height: 56px; + padding: 0 1rem; + border: 1px solid #dfe3e9; + border-radius: 14px; + background: #fff; + color: #14171c; + font-size: 0.85rem; + font-weight: 500; + white-space: nowrap; + cursor: pointer; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); + + &:hover { + border-color: #c9cfd8; + } + + &.is-active { + border-color: #b4232a; + color: #b4232a; + + .filter-badge { + background: #b4232a; + color: #fff; + } + } +} + +.filter-badge { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 1.25rem; + height: 1.25rem; + padding: 0 0.3rem; + border-radius: 999px; + background: #eef0f3; + color: #5f6b7a; + font-size: 0.7rem; + font-weight: 600; +} + +.sort-box { + position: relative; + display: flex; + align-items: center; + height: 56px; + border: 1px solid #dfe3e9; + border-radius: 14px; + background: #fff; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); + transition: border-color 0.15s ease, box-shadow 0.15s ease; + + &:focus-within { + border-color: #b4232a; + box-shadow: 0 0 0 4px rgba(180, 35, 42, 0.12); + } + + .sort-icon { + position: absolute; + left: 0.95rem; + color: #8a94a3; + font-size: 0.8rem; + pointer-events: none; + } + + select { + width: 100%; + height: 100%; + padding: 0 2.2rem 0 2.5rem; + border: 0; + border-radius: 14px; + background: transparent; + color: #14171c; + font-size: 0.85rem; + cursor: pointer; + + &:focus { + outline: none; + } + } +} + +.active-filters { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.4rem; + margin-top: 1rem; + animation: rise 0.4s ease both; +} + +.active-label { + margin-right: 0.2rem; + color: #8a94a3; + font-size: 0.65rem; + font-weight: 600; + letter-spacing: 0.12em; + text-transform: uppercase; +} + +.active-filters .filter-chip { + display: inline-flex; + align-items: center; + gap: 0.35rem; +} + +.clear-all { + margin-left: 0.25rem; + border: 0; + background: transparent; + color: #6b7686; + font-size: 0.75rem; + text-decoration: underline; + cursor: pointer; + + &:hover { + color: #b4232a; + } +} + +.tabs-wrap { + margin-top: 1.25rem; + animation: rise 0.5s ease 0.12s both; +} + +.filter-panel { + margin: 1rem 0 0.25rem; + padding: 1.1rem 1.2rem; + border: 1px solid #e4e7ec; + border-radius: 16px; + background: #fff; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); + animation: rise 0.25s ease both; +} + +.filter-grid { + display: grid; + grid-template-columns: minmax(0, 2fr) minmax(160px, 1fr) minmax(140px, 1fr); + gap: 1rem 1.5rem; + align-items: start; +} + +.filter-block { + display: flex; + flex-direction: column; + gap: 0.6rem; +} + +.filter-label { + color: #8a94a3; + font-size: 0.65rem; + font-weight: 600; + letter-spacing: 0.12em; + text-transform: uppercase; +} + +.filter-chips { + display: flex; + flex-wrap: wrap; + gap: 0.35rem; + max-height: 7.5rem; + overflow-y: auto; +} + +.filter-chip { + padding: 0.3rem 0.6rem; + border: 1px solid #e4e7ec; + border-radius: 999px; + background: #fff; + color: #47505d; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.7rem; + cursor: pointer; + + &:hover { + border-color: #c9cfd8; + } + + &.selected { + border-color: #b4232a; + background: rgba(180, 35, 42, 0.06); + color: #b4232a; + } +} + +.filter-empty { + color: #8a94a3; + font-size: 0.78rem; +} + +.filter-block select { + width: 100%; + padding: 0.5rem 0.8rem; + border: 1px solid #dfe3e9; + border-radius: 10px; + background: #fff; + color: #14171c; + font-size: 0.82rem; + + &:focus { + outline: none; + border-color: #b4232a; + box-shadow: 0 0 0 3px rgba(180, 35, 42, 0.12); + } +} + +.filter-tip { + margin: 0.9rem 0 0; + color: #8a94a3; + font-size: 0.75rem; + + code { + padding: 0.08rem 0.3rem; + border: 1px solid #e4e7ec; + border-radius: 4px; + background: #f8f9fb; + color: #47505d; + font-size: 0.72rem; + } +} + +.results-head { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 0.25rem 1rem; + padding: 0.6rem 0; + + ::ng-deep mat-paginator { + .mat-mdc-paginator-container { + min-height: 0; + padding: 0; + } + + .mat-mdc-paginator-range-label { + margin: 0 0.5rem 0 0; + } + + .mat-mdc-icon-button { + --mat-icon-button-state-layer-size: 32px; + // the default 48px touch target sticks out of a 32px button and makes the tab body scroll sideways + --mat-icon-button-touch-target-display: none; + padding: 4px; + } + } +} + +.results-actions { + display: flex; + align-items: center; + gap: 1rem; + margin-left: auto; +} + +.results-count { + color: #8a94a3; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.72rem; + letter-spacing: 0.08em; + text-transform: uppercase; + + &.is-query { + letter-spacing: 0.02em; + text-transform: none; + } +} + +.clear-link { + padding: 0; + border: 0; + background: transparent; + color: #5f6b7a; + font-size: 0.78rem; + text-decoration: underline; + text-underline-offset: 3px; + cursor: pointer; + + &:hover { + color: #b4232a; + } +} + +.result-list { + border-top: 1px solid #e4e7ec; +} + +.empty-state { + margin: 2rem 0; + padding: 3.5rem 1rem; + border: 1px dashed #d5dae1; + border-radius: 16px; + background: #fff; + color: #6b7686; + text-align: center; + + fa-icon { + color: #b8c0cb; + font-size: 1.9rem; + } + + h5 { + margin: 1rem 0 0.35rem; + color: #14171c; + font-size: 1.05rem; + font-weight: 600; + } + + p { + margin: 0 0 1.1rem; + font-size: 0.9rem; + } + + .btn-outline-light { + border-color: #dfe3e9; + color: #14171c; + + &:hover { + border-color: #b4232a; + background: #b4232a; + color: #fff; + } + } +} + +.skeleton-list { + border-top: 1px solid #e4e7ec; +} + +.skeleton-row { + display: flex; + align-items: center; + gap: 1rem; + padding: 1.05rem 0.65rem; + border-bottom: 1px solid #e4e7ec; +} + +.skeleton-icon { + flex: none; + width: 40px; + height: 40px; + border-radius: 10px; + background: #dfe5ec; +} + +.skeleton-body { + display: flex; + flex: 1; + flex-direction: column; + gap: 0.55rem; +} + +.skeleton-line { + height: 10px; + border-radius: 6px; + background: linear-gradient(90deg, #dbe1e8 25%, #eef1f5 37%, #dbe1e8 63%); + background-size: 400% 100%; + animation: shimmer 1.2s ease infinite; +} + +@keyframes shimmer { + from { + background-position: 100% 0; + } + + to { + background-position: 0 0; + } +} + +::ng-deep .catalogue-tabs { + .mat-mdc-tab-header { + border-bottom: 1px solid #e4e7ec; + } + + .mat-mdc-tab .mdc-tab__text-label { + color: #5f6b7a; + font-weight: 600; + letter-spacing: 0.02em; + } + + .mat-mdc-tab.mdc-tab--active .mdc-tab__text-label { + color: #14171c; + } + + .mat-mdc-tab-indicator__content--underline, + .mdc-tab-indicator__content--underline { + border-color: #b4232a !important; + } + + .mat-mdc-tab-header-pagination { + background: transparent; + } + + .mat-mdc-tab-header-pagination-chevron { + border-color: #5f6b7a; + } +} + +::ng-deep mat-paginator, +::ng-deep mat-paginator.mat-mdc-paginator { + background: transparent !important; + + .mat-mdc-paginator { + background: transparent !important; + } + + .mat-mdc-paginator-container { + background: transparent; + } + + .mat-mdc-paginator-range-label { + color: #8a94a3; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.72rem; + } + + .mat-mdc-icon-button { + color: #5f6b7a; + + &[disabled] { + color: #c3c9d2; + } + } + + .mat-mdc-paginator-icon { + fill: #5f6b7a; + } + + .mat-mdc-icon-button[disabled] .mat-mdc-paginator-icon { + fill: #c3c9d2; + } +} + +@media (max-width: 991px) { + .filter-grid { + grid-template-columns: minmax(0, 1fr) minmax(140px, 1fr); + } +} + +@media (max-width: 767px) { + :host { + padding: 0 1.15rem 3rem; + } + + .masthead { + padding-top: 2.25rem; + } + + .search-row { + grid-template-columns: minmax(0, 1fr); + } + + .toolbar-actions { + width: 100%; + } + + .filter-toggle { + flex: 0 0 auto; + } + + .sort-box { + flex: 1; + } + + .search-box input { + height: 52px; + } + + .filter-grid { + grid-template-columns: minmax(0, 1fr); + } +} + +@media (max-width: 575px) { + ::ng-deep .catalogue-tabs .mat-mdc-tab { + min-width: 0; + padding: 0 0.5rem; + } + + ::ng-deep .catalogue-tabs .mdc-tab__text-label { + font-size: 0.8rem; + } +} + +@media (prefers-reduced-motion: reduce) { + .masthead, + .active-filters, + .tabs-wrap { + animation: none; + } + + .eyebrow::before, + .eyebrow::after, + .eyebrow-text { + animation: none; + } + + .eyebrow::before { + transform: none; + } + + .eyebrow::after { + opacity: 0.8; + } + + .skeleton-line { + animation: none; + } +} diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index a7b1056..5e18403 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -1,156 +1,266 @@ -import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { ActivatedRoute } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; -import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; -import { MatTabChangeEvent, MatTabsModule } from '@angular/material/tabs'; -import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { FormsModule } from '@angular/forms'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { APP_CONFIG } from '../services/config/config.token'; -import { Config } from '../services/catalogue/catalogue.model'; -import { Repository } from 'src/@types'; - -import { HomeComponent } from './home.component'; -import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; - -describe('HomeComponent', () => { - let component: HomeComponent; - let fixture: ComponentFixture; - - const REPOS = [ - { name: 'popular', stargazers_count: 100, created_at: '2019-01-01T00:00:00Z', pushed_at: '2019-06-01T00:00:00Z' }, - { name: 'recently-pushed', stargazers_count: 10, created_at: '2020-01-01T00:00:00Z', pushed_at: '2024-06-01T00:00:00Z' }, - { name: 'newest', stargazers_count: 1, created_at: '2023-01-01T00:00:00Z', pushed_at: '2023-06-01T00:00:00Z' }, - ] as unknown as Repository[]; - - beforeEach(async () => { - const MOCK_CONFIG: Config = { - page: 0, - perPage: 10, - pageSize: 8, - globalSearch: true, - tabs: { - Test: { topic: '', org: '', path: '/test', globalSearch: true }, - }, - usePreGeneratedFile: false, - }; - await TestBed.configureTestingModule({ - declarations: [HomeComponent], - schemas: [NO_ERRORS_SCHEMA], - imports: [RouterTestingModule, - FontAwesomeModule, - MatTabsModule, - MatPaginatorModule, - BrowserAnimationsModule, - FormsModule], - providers: [ - { provide: APP_CONFIG, useValue: MOCK_CONFIG }, - { - provide: ActivatedRoute, - useValue: { - snapshot: { - paramMap: { - get: () => null - } - } - } - }, - provideHttpClient(withInterceptorsFromDi()), - provideHttpClientTesting() - ] -}).compileComponents(); - }); - - beforeEach(() => { - sessionStorage.clear(); - fixture = TestBed.createComponent(HomeComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - afterEach(() => { - sessionStorage.clear(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); - - it('should restore the current page from session storage', () => { - sessionStorage.setItem('azerothcore.catalogue.page', '2'); - - const restoredFixture = TestBed.createComponent(HomeComponent); - - expect(restoredFixture.componentInstance.page).toBe(2); - restoredFixture.destroy(); - }); - - it('should save the current page and route when pagination changes', () => { - component.onPageChange({ pageIndex: 2 } as PageEvent); - - expect(sessionStorage.getItem('azerothcore.catalogue.page')).toBe('2'); - expect(sessionStorage.getItem('azerothcore.catalogue.returnHash')).toBe('#/home'); - }); - - it('should sort by stars by default', () => { - const items = component.currentPageItems(REPOS); - - expect(items.map((item) => item.name)).toEqual(['popular', 'recently-pushed', 'newest']); - }); - - it('should sort by last push when picking the updated sort', () => { - component.sort = 'updated'; - - const items = component.currentPageItems(REPOS); - - expect(items.map((item) => item.name)).toEqual(['recently-pushed', 'newest', 'popular']); - }); - - it('should sort by creation date when picking the created sort', () => { - component.sort = 'created'; - - const items = component.currentPageItems(REPOS); - - expect(items.map((item) => item.name)).toEqual(['newest', 'recently-pushed', 'popular']); - }); - - it('should save the sort and reset the page when the sort changes', () => { - component.page = 2; - component.sort = 'updated'; - - component.onSortChange('updated'); - - expect(component.page).toBe(0); - expect(sessionStorage.getItem('azerothcore.catalogue.sort')).toBe('updated'); - }); - - it('should restore the sort from session storage', () => { - sessionStorage.setItem('azerothcore.catalogue.sort', 'created'); - - const restoredFixture = TestBed.createComponent(HomeComponent); - - expect(restoredFixture.componentInstance.sort).toBe('created'); - restoredFixture.destroy(); - }); - - it('should fall back to the star sort when session storage holds an unknown sort', () => { - sessionStorage.setItem('azerothcore.catalogue.sort', 'whatever'); - - const restoredFixture = TestBed.createComponent(HomeComponent); - - expect(restoredFixture.componentInstance.sort).toBe('stars'); - restoredFixture.destroy(); - }); - - it('should reset the page when changing tabs', () => { - component.page = 2; - - component.onTabChange({ index: 0 } as MatTabChangeEvent); - - expect(component.page).toBe(0); - expect(sessionStorage.getItem('azerothcore.catalogue.page')).toBe('0'); - expect(sessionStorage.getItem('azerothcore.catalogue.returnHash')).toBe('#/tab/test'); - }); -}); +import { provideHttpClientTesting } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; +import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; +import { MatTabChangeEvent, MatTabsModule } from '@angular/material/tabs'; +import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { FormsModule } from '@angular/forms'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { APP_CONFIG } from '../services/config/config.token'; +import { Config } from '../services/catalogue/catalogue.model'; +import { Repository } from 'src/@types'; + +import { HomeComponent } from './home.component'; +import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; + +describe('HomeComponent', () => { + let component: HomeComponent; + let fixture: ComponentFixture; + + const REPOS = [ + { name: 'popular', stargazers_count: 100, created_at: '2019-01-01T00:00:00Z', pushed_at: '2019-06-01T00:00:00Z' }, + { name: 'recently-pushed', stargazers_count: 10, created_at: '2020-01-01T00:00:00Z', pushed_at: '2024-06-01T00:00:00Z' }, + { name: 'newest', stargazers_count: 1, created_at: '2023-01-01T00:00:00Z', pushed_at: '2023-06-01T00:00:00Z' }, + ] as unknown as Repository[]; + + const SEARCH_REPOS = [ + { + name: 'mod-eluna', + description: 'Lua engine for AzerothCore', + topics: ['azerothcore-lua'], + language: 'C++', + owner: { login: 'azerothcore' }, + stargazers_count: 5, + created_at: '2020-01-01T00:00:00Z', + pushed_at: '2020-01-01T00:00:00Z', + }, + { + name: 'mod-transmog', + description: 'Transmogrification module', + topics: ['azerothcore-module'], + language: 'C++', + owner: { login: 'azerothcore' }, + stargazers_count: 50, + created_at: '2020-01-01T00:00:00Z', + pushed_at: '2020-01-01T00:00:00Z', + }, + { + name: 'Rápido', + description: 'Accents test', + topics: [], + language: 'Lua', + owner: { login: 'someone' }, + stargazers_count: 1, + created_at: '2020-01-01T00:00:00Z', + pushed_at: '2020-01-01T00:00:00Z', + }, + ] as unknown as Repository[]; + + beforeEach(async () => { + const MOCK_CONFIG: Config = { + page: 0, + perPage: 10, + pageSize: 8, + globalSearch: true, + tabs: { + Test: { topic: '', org: '', path: '/test', globalSearch: true }, + }, + usePreGeneratedFile: false, + }; + await TestBed.configureTestingModule({ + declarations: [HomeComponent], + schemas: [NO_ERRORS_SCHEMA], + imports: [RouterTestingModule, + FontAwesomeModule, + MatTabsModule, + MatPaginatorModule, + BrowserAnimationsModule, + FormsModule], + providers: [ + { provide: APP_CONFIG, useValue: MOCK_CONFIG }, + { + provide: ActivatedRoute, + useValue: { + snapshot: { + paramMap: { + get: () => null + } + } + } + }, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting() + ] +}).compileComponents(); + }); + + beforeEach(() => { + sessionStorage.clear(); + fixture = TestBed.createComponent(HomeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + afterEach(() => { + sessionStorage.clear(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should restore the current page from session storage', () => { + sessionStorage.setItem('azerothcore.catalogue.page', '2'); + + const restoredFixture = TestBed.createComponent(HomeComponent); + + expect(restoredFixture.componentInstance.page).toBe(2); + restoredFixture.destroy(); + }); + + it('should save the current page and route when pagination changes', () => { + component.onPageChange({ pageIndex: 2 } as PageEvent); + + expect(sessionStorage.getItem('azerothcore.catalogue.page')).toBe('2'); + expect(sessionStorage.getItem('azerothcore.catalogue.returnHash')).toBe('#/home'); + }); + + it('should sort by stars by default', () => { + const items = component.currentPageItems(REPOS); + + expect(items.map((item) => item.name)).toEqual(['popular', 'recently-pushed', 'newest']); + }); + + it('should sort by last push when picking the updated sort', () => { + component.sort = 'updated'; + + const items = component.currentPageItems(REPOS); + + expect(items.map((item) => item.name)).toEqual(['recently-pushed', 'newest', 'popular']); + }); + + it('should sort by creation date when picking the created sort', () => { + component.sort = 'created'; + + const items = component.currentPageItems(REPOS); + + expect(items.map((item) => item.name)).toEqual(['newest', 'recently-pushed', 'popular']); + }); + + it('should save the sort and reset the page when the sort changes', () => { + component.page = 2; + component.sort = 'updated'; + + component.onSortChange('updated'); + + expect(component.page).toBe(0); + expect(sessionStorage.getItem('azerothcore.catalogue.sort')).toBe('updated'); + }); + + it('should restore the sort from session storage', () => { + sessionStorage.setItem('azerothcore.catalogue.sort', 'created'); + + const restoredFixture = TestBed.createComponent(HomeComponent); + + expect(restoredFixture.componentInstance.sort).toBe('created'); + restoredFixture.destroy(); + }); + + it('should fall back to the star sort when session storage holds an unknown sort', () => { + sessionStorage.setItem('azerothcore.catalogue.sort', 'whatever'); + + const restoredFixture = TestBed.createComponent(HomeComponent); + + expect(restoredFixture.componentInstance.sort).toBe('stars'); + restoredFixture.destroy(); + }); + + it('should reset the page when changing tabs', () => { + component.page = 2; + + component.onTabChange({ index: 0 } as MatTabChangeEvent); + + expect(component.page).toBe(0); + expect(sessionStorage.getItem('azerothcore.catalogue.page')).toBe('0'); + expect(sessionStorage.getItem('azerothcore.catalogue.returnHash')).toBe('#/tab/test'); + }); + + it('should match repositories by name, description, topic, language or author', () => { + component.search = 'transmogrification'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(1); + + component.search = 'azerothcore-lua'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(1); + + component.search = 'C++'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(2); + + component.search = 'someone'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(1); + }); + + it('should require every search term to match', () => { + component.search = 'module azerothcore'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(1); + + component.search = 'eluna module'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(0); + }); + + it('should ignore case and accents when searching', () => { + component.search = 'ELUNA'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(1); + + component.search = 'rapido'; + expect(component.filteredLength(SEARCH_REPOS)).toBe(1); + }); + + it('should report how many results match', () => { + component.search = 'eluna'; + expect(component.searchStatus(1)).toBe('1 result for “eluna”'); + + component.search = 'nothing'; + expect(component.searchStatus(0)).toBe('No results for “nothing”'); + }); + + it('should save the search and reset the page when the query changes', () => { + component.page = 2; + + component.onSearchChange('eluna'); + + expect(component.page).toBe(0); + expect(sessionStorage.getItem('azerothcore.catalogue.search')).toBe('eluna'); + }); + + it('should clear the search and forget it', () => { + component.search = 'eluna'; + component.page = 2; + sessionStorage.setItem('azerothcore.catalogue.search', 'eluna'); + + component.clearSearch(); + + expect(component.search).toBe(''); + expect(component.page).toBe(0); + expect(sessionStorage.getItem('azerothcore.catalogue.search')).toBeNull(); + }); + + it('should restore the search from session storage', () => { + sessionStorage.setItem('azerothcore.catalogue.search', 'eluna'); + + const restoredFixture = TestBed.createComponent(HomeComponent); + + expect(restoredFixture.componentInstance.search).toBe('eluna'); + restoredFixture.destroy(); + }); + + it('should focus the search input when pressing /', () => { + const input = fixture.nativeElement.querySelector('#search-input') as HTMLInputElement; + spyOn(input, 'focus'); + + document.dispatchEvent(new KeyboardEvent('keydown', { key: '/' })); + + expect(input.focus).toHaveBeenCalled(); + }); +}); diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index c9bd74e..47147d0 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,146 +1,382 @@ -import { Location } from '@angular/common'; -import { ChangeDetectorRef, Component } from '@angular/core'; -import { PageEvent } from '@angular/material/paginator'; -import { MatTabChangeEvent } from '@angular/material/tabs'; -import { faSearch, IconDefinition } from '@fortawesome/free-solid-svg-icons'; -import { Repository } from 'src/@types'; -import { CatalogueService } from '../services/catalogue/catalogue.service'; - -const PAGE_STORAGE_KEY = 'azerothcore.catalogue.page'; -const RETURN_HASH_STORAGE_KEY = 'azerothcore.catalogue.returnHash'; -const SORT_STORAGE_KEY = 'azerothcore.catalogue.sort'; - -export type SortKey = 'stars' | 'updated' | 'created'; - -export const SORT_OPTIONS: { key: SortKey; label: string }[] = [ - { key: 'stars', label: 'Most stars' }, - { key: 'updated', label: 'Recently updated' }, - { key: 'created', label: 'Recently added' }, -]; - -@Component({ - selector: 'app-home', - templateUrl: './home.component.html', - standalone: false -}) -export class HomeComponent { - constructor(public catalogueService: CatalogueService, public cdRef: ChangeDetectorRef, private location: Location) { - window.parent.document.title = 'GitCatalogue'; - this.saveRoute(); - } - - page = this.readPage(); - sort: SortKey = this.readSort(); - search: string; - readonly faSearch: IconDefinition = faSearch; - readonly sortOptions = SORT_OPTIONS; - - readPage(): number { - try { - const page = parseInt(sessionStorage.getItem(PAGE_STORAGE_KEY) || '0', 10); - return isNaN(page) || page < 0 ? 0 : page; - } catch (error) { - return 0; - } - } - - savePage(): void { - try { - sessionStorage.setItem(PAGE_STORAGE_KEY, String(this.page)); - } catch (error) {} - } - - readSort(): SortKey { - try { - const sort = sessionStorage.getItem(SORT_STORAGE_KEY) as SortKey; - return SORT_OPTIONS.some((option) => option.key === sort) ? sort : 'stars'; - } catch (error) { - return 'stars'; - } - } - - saveSort(): void { - try { - sessionStorage.setItem(SORT_STORAGE_KEY, this.sort); - } catch (error) {} - } - - saveRoute(path?: string): void { - try { - const route = path || this.location.path() || '/home'; - sessionStorage.setItem(RETURN_HASH_STORAGE_KEY, `#${route}`); - } catch (error) {} - } - - resetPage(): void { - this.page = 0; - this.savePage(); - this.saveRoute(); - this.refresh(); - } - - refresh(): void { - this.cdRef.detectChanges(); - } - - onSearchChange(value: string): void { - this.resetPage(); - } - - onSortChange(value: SortKey): void { - this.saveSort(); - this.resetPage(); - } - - onPageChange(page: PageEvent): void { - this.page = page.pageIndex; - this.savePage(); - this.saveRoute(); - } - - onTabChange(tab: MatTabChangeEvent): void { - const index = tab.index; - const tabName = Object.keys(this.catalogueService.CONF.tabs)[index]; - const path = `/tab${this.catalogueService.CONF.tabs[tabName].path}`; - - this.page = 0; - this.savePage(); - this.saveRoute(path); - - if (this.location.path() !== path) { - this.location.go(path); - } - } - - currentPageItems(modules: Repository[]): Repository[] { - const items = this.sortItems(this.matchingItems(modules)); - return items.slice(this.catalogueService.CONF.pageSize * this.page, this.catalogueService.CONF.pageSize * (this.page + 1)); - } - - filteredLength(modules: Repository[]): number { - return this.matchingItems(modules).length; - } - - private matchingItems(modules: Repository[]): Repository[] { - if (!this.search) { - return modules; - } - const search = this.search.toLowerCase(); - return modules.filter((item) => item.name.toLowerCase().indexOf(search) > -1); - } - - private sortItems(modules: Repository[]): Repository[] { - if (this.sort === 'stars') { - return [...modules].sort((a, b) => b.stargazers_count - a.stargazers_count); - } - - // pushed_at tracks the last commit, unlike updated_at which also moves on metadata changes - const dateOf = (item: Repository) => (this.sort === 'updated' ? item.pushed_at : item.created_at); - return [...modules].sort((a, b) => this.time(dateOf(b)) - this.time(dateOf(a))); - } - - private time(date: Date | string): number { - const time = date ? new Date(date).getTime() : 0; - return isNaN(time) ? 0 : time; - } -} +import { Location } from '@angular/common'; +import { ChangeDetectorRef, Component, ElementRef, HostListener, ViewChild } from '@angular/core'; +import { PageEvent } from '@angular/material/paginator'; +import { MatTabChangeEvent } from '@angular/material/tabs'; +import { faFilter, faSearch, faSortAmountDown, IconDefinition } from '@fortawesome/free-solid-svg-icons'; +import { Repository } from 'src/@types'; +import { CatalogueService } from '../services/catalogue/catalogue.service'; + +const PAGE_STORAGE_KEY = 'azerothcore.catalogue.page'; +const RETURN_HASH_STORAGE_KEY = 'azerothcore.catalogue.returnHash'; +const SORT_STORAGE_KEY = 'azerothcore.catalogue.sort'; +const SEARCH_STORAGE_KEY = 'azerothcore.catalogue.search'; + +type ParsedQuery = { + text: string[]; + topic?: string; + lang?: string; + owner?: string; + minStars?: number; +}; + +export type SortKey = 'stars' | 'updated' | 'created'; + +export const SORT_OPTIONS: { key: SortKey; label: string }[] = [ + { key: 'stars', label: 'Most stars' }, + { key: 'updated', label: 'Recently updated' }, + { key: 'created', label: 'Recently added' }, +]; + +@Component({ + selector: 'app-home', + templateUrl: './home.component.html', + styleUrls: ['./home.component.scss'], + standalone: false +}) +export class HomeComponent { + @ViewChild('searchInput') searchInput?: ElementRef; + + constructor(public catalogueService: CatalogueService, public cdRef: ChangeDetectorRef, private location: Location) { + window.parent.document.title = 'GitCatalogue'; + this.saveRoute(); + } + + page = this.readPage(); + sort: SortKey = this.readSort(); + search = this.readSearch(); + readonly faSearch: IconDefinition = faSearch; + readonly faFilter: IconDefinition = faFilter; + readonly faSortAmountDown: IconDefinition = faSortAmountDown; + readonly sortOptions = SORT_OPTIONS; + readonly starOptions = [0, 10, 50, 100, 500]; + readonly skeletonRows = [0, 1, 2, 3, 4, 5]; + + filtersOpen = false; + selectedTopics: string[] = []; + selectedLanguage = ''; + minStars = 0; + + private facetCache = new WeakMap(); + + readPage(): number { + try { + const page = parseInt(sessionStorage.getItem(PAGE_STORAGE_KEY) || '0', 10); + return isNaN(page) || page < 0 ? 0 : page; + } catch (error) { + return 0; + } + } + + savePage(): void { + try { + sessionStorage.setItem(PAGE_STORAGE_KEY, String(this.page)); + } catch (error) {} + } + + readSort(): SortKey { + try { + const sort = sessionStorage.getItem(SORT_STORAGE_KEY) as SortKey; + return SORT_OPTIONS.some((option) => option.key === sort) ? sort : 'stars'; + } catch (error) { + return 'stars'; + } + } + + saveSort(): void { + try { + sessionStorage.setItem(SORT_STORAGE_KEY, this.sort); + } catch (error) {} + } + + readSearch(): string { + try { + return sessionStorage.getItem(SEARCH_STORAGE_KEY) || ''; + } catch (error) { + return ''; + } + } + + private writeSearch(value: string): void { + try { + if (value) { + sessionStorage.setItem(SEARCH_STORAGE_KEY, value); + } else { + sessionStorage.removeItem(SEARCH_STORAGE_KEY); + } + } catch (error) {} + } + + saveRoute(path?: string): void { + try { + const route = path || this.location.path() || '/home'; + sessionStorage.setItem(RETURN_HASH_STORAGE_KEY, `#${route}`); + } catch (error) {} + } + + resetPage(): void { + this.page = 0; + this.savePage(); + this.saveRoute(); + this.refresh(); + } + + refresh(): void { + this.cdRef.detectChanges(); + } + + onSearchChange(value: string): void { + this.writeSearch(value); + this.resetPage(); + } + + clearSearch(): void { + if (!this.search) { + return; + } + this.search = ''; + this.writeSearch(''); + this.resetPage(); + this.searchInput?.nativeElement.focus(); + } + + @HostListener('document:keydown', ['$event']) + onDocumentKeydown(event: KeyboardEvent): void { + if (event.key !== '/' || event.ctrlKey || event.metaKey || event.altKey) { + return; + } + + const target = event.target as HTMLElement | null; + const isTyping = + !!target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT' || target.isContentEditable); + if (isTyping) { + return; + } + + event.preventDefault(); + this.searchInput?.nativeElement.focus(); + } + + onSortChange(value: SortKey): void { + this.saveSort(); + this.resetPage(); + } + + onPageChange(page: PageEvent): void { + this.page = page.pageIndex; + this.savePage(); + this.saveRoute(); + } + + onTabChange(tab: MatTabChangeEvent): void { + const index = tab.index; + const tabName = Object.keys(this.catalogueService.CONF.tabs)[index]; + const path = `/tab${this.catalogueService.CONF.tabs[tabName].path}`; + + this.page = 0; + this.savePage(); + this.saveRoute(path); + + if (this.location.path() !== path) { + this.location.go(path); + } + } + + currentPageItems(modules: Repository[]): Repository[] { + const items = this.sortItems(this.matchingItems(modules)); + return items.slice(this.catalogueService.CONF.pageSize * this.page, this.catalogueService.CONF.pageSize * (this.page + 1)); + } + + filteredLength(modules: Repository[]): number { + return this.matchingItems(modules).length; + } + + searchStatus(count: number): string { + const query = this.search.trim(); + if (count === 0) { + return `No results for “${query}”`; + } + return `${count} ${count === 1 ? 'result' : 'results'} for “${query}”`; + } + + repositoryCount(count: number): string { + return `${count} ${count === 1 ? 'repository' : 'repositories'}`; + } + + get activeFilterCount(): number { + return this.selectedTopics.length + (this.selectedLanguage ? 1 : 0) + (this.minStars > 0 ? 1 : 0); + } + + toggleFilters(): void { + this.filtersOpen = !this.filtersOpen; + } + + isTopicSelected(topic: string): boolean { + return this.selectedTopics.includes(topic); + } + + toggleTopic(topic: string): void { + this.selectedTopics = this.isTopicSelected(topic) + ? this.selectedTopics.filter((selected) => selected !== topic) + : [...this.selectedTopics, topic]; + this.resetPage(); + } + + onLanguageChange(value: string): void { + this.selectedLanguage = value; + this.resetPage(); + } + + onMinStarsChange(value: string): void { + this.minStars = Number(value) || 0; + this.resetPage(); + } + + clearFilters(): void { + this.selectedTopics = []; + this.selectedLanguage = ''; + this.minStars = 0; + this.resetPage(); + } + + clearAll(): void { + this.search = ''; + this.writeSearch(''); + this.selectedTopics = []; + this.selectedLanguage = ''; + this.minStars = 0; + this.resetPage(); + this.searchInput?.nativeElement.focus(); + } + + enterDelay(index: number): number { + // Rows fade in pairs, so the list feels like it arrives in small batches. + return Math.floor(index / 2) * 90; + } + + topTopics(items: Repository[]): string[] { + return this.facets(items).topics.slice(0, 14); + } + + languages(items: Repository[]): string[] { + return this.facets(items).languages; + } + + private facets(items: Repository[]): { topics: string[]; languages: string[] } { + let facets = this.facetCache.get(items); + if (!facets) { + const counts = new Map(); + const languages = new Set(); + for (const item of items) { + for (const topic of item.topics || []) { + counts.set(topic, (counts.get(topic) ?? 0) + 1); + } + if (item.language) { + languages.add(item.language); + } + } + facets = { + topics: [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([topic]) => topic), + languages: [...languages].sort((a, b) => a.localeCompare(b)), + }; + this.facetCache.set(items, facets); + } + return facets; + } + + private matchingItems(modules: Repository[]): Repository[] { + const query = this.parsedQuery; + const hasQuery = query.text.length > 0 || !!query.topic || !!query.lang || !!query.owner || (query.minStars ?? 0) > 0; + if (!hasQuery && this.activeFilterCount === 0) { + return modules; + } + return modules.filter((item) => this.matches(item, query)); + } + + private matches(item: Repository, query: ParsedQuery): boolean { + if (!query.text.every((term) => this.searchableText(item).includes(term))) { + return false; + } + if (query.topic && !(item.topics || []).some((topic) => this.normalize(topic) === query.topic)) { + return false; + } + if (query.lang && this.normalize(item.language || '') !== query.lang) { + return false; + } + if (query.owner && this.normalize(item.owner?.login || '') !== query.owner) { + return false; + } + if ((query.minStars ?? 0) > 0 && (item.stargazers_count || 0) < query.minStars) { + return false; + } + if (this.selectedTopics.length > 0 && !this.selectedTopics.every((topic) => (item.topics || []).includes(topic))) { + return false; + } + if (this.selectedLanguage && item.language !== this.selectedLanguage) { + return false; + } + if (this.minStars > 0 && (item.stargazers_count || 0) < this.minStars) { + return false; + } + return true; + } + + private get parsedQuery(): ParsedQuery { + const parsed: ParsedQuery = { text: [] }; + const raw = (this.search || '').trim(); + if (!raw) { + return parsed; + } + + for (const token of raw.split(/\s+/)) { + const match = token.match(/^(topic|lang|language|owner|stars):(.+)$/i); + if (!match) { + parsed.text.push(this.normalize(token)); + continue; + } + + const key = match[1].toLowerCase(); + const value = match[2]; + if (key === 'topic') { + parsed.topic = this.normalize(value); + } else if (key === 'lang' || key === 'language') { + parsed.lang = this.normalize(value); + } else if (key === 'owner') { + parsed.owner = this.normalize(value); + } else { + parsed.minStars = parseInt(value.replace(/^[<>]=?/, ''), 10) || 0; + } + } + + return parsed; + } + + private searchableText(item: Repository): string { + return this.normalize( + [item.name, item.full_name, item.description, item.language, item.owner?.login, ...(item.topics || [])] + .filter(Boolean) + .join(' '), + ); + } + + private normalize(value: string): string { + return value + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLowerCase(); + } + + private sortItems(modules: Repository[]): Repository[] { + if (this.sort === 'stars') { + return [...modules].sort((a, b) => b.stargazers_count - a.stargazers_count); + } + + // pushed_at tracks the last commit, unlike updated_at which also moves on metadata changes + const dateOf = (item: Repository) => (this.sort === 'updated' ? item.pushed_at : item.created_at); + return [...modules].sort((a, b) => this.time(dateOf(b)) - this.time(dateOf(a))); + } + + private time(date: Date | string): number { + const time = date ? new Date(date).getTime() : 0; + return isNaN(time) ? 0 : time; + } +} diff --git a/src/app/howto/howto.component.html b/src/app/howto/howto.component.html index 78c629a..090aa00 100644 --- a/src/app/howto/howto.component.html +++ b/src/app/howto/howto.component.html @@ -18,18 +18,20 @@

Step 1: Add GitHub Topics to Your Repository

Available Categories & Required Topics:
-
-
-
-
{{ tab.key }}
-

- Required topic: - {{ tab.value.topic }} -

- Organization: {{ tab.value.org || 'default-org' }} + @for (tab of catalogueService.CONF.tabs | keyvalue; track tab.key) { +
+
+
+
{{ tab.key }}
+

+ Required topic: + {{ tab.value.topic }} +

+ Organization: {{ tab.value.org || 'default-org' }} +
-
+ }
diff --git a/src/app/repo-details/repo-details.component.html b/src/app/repo-details/repo-details.component.html index 179ad25..6b0204b 100644 --- a/src/app/repo-details/repo-details.component.html +++ b/src/app/repo-details/repo-details.component.html @@ -1,67 +1,146 @@ -   back to Catalogue +
+ @if (data$ | async; as data) { + -
-
- -
-

{{ data.repo.name }}

-

- by {{ data.repo.owner.login }} -

-
-
+
+ -
-
- - {{ data.readme | emojiFixup }} - -
-
-
- Download +
+
+

{{ data.repo.name }}

+ + by + {{ data.repo.owner.login }} + +
+ + @if (data.repo.description) { +

{{ data.repo.description }}

+ } + + @if (data.repo.topics?.length) { +
+ @for (topic of data.repo.topics; track topic) { + {{ topic }} + } +
+ } +
+ + +
-

About this repo

-
    -
  • - Repo ID: {{ data.repo.id }} -
  • -
  • - Author: {{ data.repo.owner.login }} -
  • -
  • - Repo: - View on Github -
  • -
  • - Watchers: {{ data.repo.subscribers_count }} -
  • -
  • - Stars: {{ data.repo.stargazers_count }} -
  • -
  • - Forks: {{ data.repo.forks_count }} -
  • -
  • - Created: {{ data.repo.created_at | amTimeAgo }} -
  • -
  • - Last update: {{ data.repo.pushed_at | amTimeAgo }} -
  • -
  • - License: {{ data.repo.license.spdx_id }} -
  • -
+
+
+ {{ data.repo.stargazers_count }} + Stars
+
+ {{ data.repo.forks_count }} + Forks +
+
+ {{ data.repo.subscribers_count }} + Watchers +
+
+ {{ data.repo.open_issues_count || 0 }} + Open issues +
+ @if (data.repo.language) { +
+ {{ data.repo.language }} + Language +
+ } + @if (data.repo.license) { +
+ {{ data.repo.license.spdx_id }} + License +
+ } +
+ +
+
+

README

+
+ + {{ data.readme | emojiFixup }} + +
+
+ +
-
+ }
diff --git a/src/app/repo-details/repo-details.component.scss b/src/app/repo-details/repo-details.component.scss index c9d7b3b..c79a1f9 100644 --- a/src/app/repo-details/repo-details.component.scss +++ b/src/app/repo-details/repo-details.component.scss @@ -1,11 +1,490 @@ -.logo { - width: 80px; - height: 80px; +:host { + display: block; + min-height: 100vh; + padding: 0 2.5rem 4rem; + background: #f6f7f9; + color: #14171c; } -#about { - background-color: #fff; - border: solid 2px #888; - padding: 25px; +.details { + max-width: 1120px; + margin: 0 auto; + padding-top: 2rem; } +.breadcrumb { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.4rem; + margin-bottom: 1.25rem; + color: #8a94a3; + font-size: 0.8rem; + + a { + display: inline-flex; + align-items: center; + gap: 0.35rem; + color: #6b7686; + text-decoration: none; + + &:hover { + color: #14171c; + } + } + + .sep { + color: #c3c9d2; + } + + .current { + color: #14171c; + font-weight: 500; + } +} + +.repo-hero { + display: flex; + align-items: flex-start; + gap: 1.25rem; + padding: 1.75rem; + border: 1px solid #e4e7ec; + border-radius: 18px; + background: #fff; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); +} + +.repo-hero-logo { + flex: none; + width: 76px; + height: 76px; + border-radius: 16px; + object-fit: cover; + background: #eef0f3; +} + +.repo-hero-body { + flex: 1; + min-width: 0; +} + +.repo-hero-title { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 0.35rem 0.8rem; + + h1 { + margin: 0; + color: #0e1116; + font-size: 1.75rem; + font-weight: 700; + letter-spacing: -0.02em; + line-height: 1.2; + word-break: break-word; + } +} + +.repo-hero-owner { + color: #8a94a3; + font-size: 0.85rem; + + a { + color: #47505d; + text-decoration: none; + + &:hover { + color: #b4232a; + text-decoration: underline; + } + } +} + +.repo-hero-description { + margin: 0.55rem 0 0; + color: #5f6b7a; + font-size: 0.95rem; + line-height: 1.55; +} + +.repo-topics { + display: flex; + flex-wrap: wrap; + gap: 0.35rem; + margin-top: 0.85rem; + + .badge { + padding: 0.16rem 0.5rem; + border: 1px solid #e4e7ec; + border-radius: 5px; + background: #fbfbfc; + color: #6b7686; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.65rem; + font-weight: 500; + } +} + +.repo-hero-actions { + display: flex; + flex: none; + flex-wrap: wrap; + gap: 0.5rem; + + .btn { + display: inline-flex; + align-items: center; + gap: 0.45rem; + font-size: 0.8rem; + } + + .btn-dark { + border-color: #b4232a; + background: #b4232a; + color: #fff; + + &:hover { + border-color: #c93038; + background: #c93038; + color: #fff; + } + } + + .btn-outline-secondary { + border-color: #dfe3e9; + color: #14171c; + + &:hover { + border-color: #c9cfd8; + background: #f3f4f6; + color: #14171c; + } + } +} + +.stats { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); + gap: 0.75rem; + margin: 1rem 0; +} + +.stat { + padding: 0.8rem 1rem; + border: 1px solid #e4e7ec; + border-radius: 12px; + background: #fff; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); +} + +.stat-value { + display: block; + color: #0e1116; + font-size: 1.2rem; + font-weight: 700; + letter-spacing: -0.01em; + line-height: 1.2; + word-break: break-word; +} + +.stat-label { + display: inline-flex; + align-items: center; + gap: 0.35rem; + margin-top: 0.2rem; + color: #8a94a3; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.65rem; + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.details-layout { + display: grid; + grid-template-columns: minmax(0, 1fr) 330px; + gap: 1rem; + align-items: start; +} + +.card { + padding: 1.5rem 1.75rem; + border: 1px solid #e4e7ec; + border-radius: 18px; + background: #fff; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); +} + +.section-title { + margin: 0 0 1rem; + color: #8a94a3; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.68rem; + font-weight: 600; + letter-spacing: 0.14em; + text-transform: uppercase; +} + +.about-list { + display: grid; + gap: 0.6rem; + margin: 0 0 1.1rem; + + div { + display: flex; + justify-content: space-between; + gap: 1rem; + } + + dt { + margin: 0; + color: #8a94a3; + font-size: 0.8rem; + font-weight: 500; + } + + dd { + max-width: 62%; + margin: 0; + color: #2f3742; + font-size: 0.8rem; + text-align: right; + overflow-wrap: anywhere; + } + + a { + color: #47505d; + text-decoration: none; + + &:hover { + color: #b4232a; + text-decoration: underline; + } + } +} + +.about-card { + .btn-outline-primary { + border-color: #dfe3e9; + color: #14171c; + font-size: 0.8rem; + + &:hover { + border-color: #b4232a; + background: #b4232a; + color: #fff; + } + } +} + +// The README is rendered from HTML, so these rules need to pierce encapsulation. +:host ::ng-deep #readme-markdown { + color: #2f3742; + font-size: 0.95rem; + line-height: 1.7; + word-wrap: break-word; + + h1, + h2, + h3, + h4 { + margin: 1.6rem 0 0.65rem; + color: #0e1116; + font-weight: 700; + letter-spacing: -0.01em; + line-height: 1.3; + } + + h1 { + padding-bottom: 0.45rem; + border-bottom: 1px solid #e4e7ec; + font-size: 1.5rem; + } + + h2 { + padding-bottom: 0.4rem; + border-bottom: 1px solid #e4e7ec; + font-size: 1.25rem; + } + + h3 { + font-size: 1.08rem; + } + + h4 { + font-size: 1rem; + } + + p { + margin: 0 0 0.95rem; + } + + ul, + ol { + margin: 0 0 0.95rem; + padding-left: 1.4rem; + } + + li { + margin-bottom: 0.3rem; + } + + a { + color: #b4232a; + text-decoration-color: rgba(180, 35, 42, 0.35); + + &:hover { + text-decoration-color: #b4232a; + } + } + + strong { + color: #0e1116; + font-weight: 600; + } + + img { + max-width: 100%; + height: auto; + border-radius: 10px; + } + + code { + padding: 0.12rem 0.35rem; + border: 1px solid #e4e7ec; + border-radius: 5px; + background: #f3f4f6; + color: #14171c; + font-size: 0.85em; + } + + pre { + margin: 0 0 1rem; + padding: 1rem 1.1rem; + border-radius: 12px; + background: #111827; + color: #e5e7eb; + overflow-x: auto; + + code { + padding: 0; + border: 0; + background: transparent; + color: inherit; + } + } + + blockquote { + margin: 0 0 1rem; + padding: 0.3rem 0 0.3rem 1rem; + border-left: 3px solid #b4232a; + color: #5f6b7a; + } + + table { + width: 100%; + margin: 0 0 1rem; + border-collapse: collapse; + font-size: 0.9rem; + + th, + td { + padding: 0.5rem 0.65rem; + border: 1px solid #e4e7ec; + } + + th { + background: #f8f9fb; + color: #14171c; + text-align: left; + } + } + + hr { + margin: 1.6rem 0; + border: 0; + border-top: 1px solid #e4e7ec; + } +} + +.breadcrumb, +.repo-hero, +.stats, +.details-layout { + animation: rise 0.45s ease both; +} + +.repo-hero { + animation-delay: 0.04s; +} + +.stats { + animation-delay: 0.1s; +} + +.details-layout { + animation-delay: 0.16s; +} + +@keyframes rise { + from { + opacity: 0; + transform: translateY(12px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +@media (prefers-reduced-motion: reduce) { + .breadcrumb, + .repo-hero, + .stats, + .details-layout { + animation: none; + } +} + +@media (max-width: 991px) { + .details-layout { + grid-template-columns: minmax(0, 1fr); + } + + .repo-hero { + flex-wrap: wrap; + } + + .repo-hero-actions { + width: 100%; + } +} + +@media (min-width: 992px) { + .about-card { + position: sticky; + top: 1rem; + } +} + +@media (max-width: 767px) { + :host { + padding: 0 1.15rem 3rem; + } + + .details { + padding-top: 1.25rem; + } + + .repo-hero { + padding: 1.25rem; + } + + .repo-hero-title h1 { + font-size: 1.4rem; + } + + .card { + padding: 1.1rem; + } +} diff --git a/src/app/repo-details/repo-details.component.spec.ts b/src/app/repo-details/repo-details.component.spec.ts index 9514a86..07ba323 100644 --- a/src/app/repo-details/repo-details.component.spec.ts +++ b/src/app/repo-details/repo-details.component.spec.ts @@ -1,10 +1,112 @@ import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { ActivatedRoute } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; +import { MarkdownComponent, MarkdownModule } from 'ngx-markdown'; +import { MomentModule } from 'ngx-moment'; +import { of } from 'rxjs'; +import { take } from 'rxjs/operators'; +import { Repository } from 'src/@types'; +import { EmojiFixupPipe } from '../pipes/emoji-fixup.pipe'; import { RepoDetailsComponent } from './repo-details.component'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +describe('RepoDetailsComponent README images', () => { + const renderReadme = async (readme: string, defaultBranch = 'master'): Promise => { + const repo = { + id: 215361574, + name: 'mod-bg-twinpeaks', + full_name: 'Helias/mod-bg-twinpeaks', + description: 'Twin Peaks battleground', + html_url: 'https://github.com/Helias/mod-bg-twinpeaks', + default_branch: defaultBranch, + owner: { login: 'Helias' }, + stargazers_count: 31, + forks_count: 4, + subscribers_count: 2, + open_issues_count: 1, + created_at: '2019-10-15T00:00:00Z', + pushed_at: '2026-01-01T00:00:00Z', + topics: ['azerothcore-module'], + } as unknown as Repository; + + await TestBed.configureTestingModule({ + declarations: [RepoDetailsComponent, EmojiFixupPipe], + imports: [RouterTestingModule, FontAwesomeModule, MomentModule, MarkdownModule.forRoot()], + providers: [{ provide: ActivatedRoute, useValue: { data: of({ data: { repo, readme, logo: 'https://example.com/logo.png' } }) } }], + }).compileComponents(); + + const fixture = TestBed.createComponent(RepoDetailsComponent); + fixture.detectChanges(); + const markdown: MarkdownComponent = fixture.debugElement.query(By.directive(MarkdownComponent)).componentInstance; + await markdown.ready.pipe(take(1)).toPromise(); + return fixture.nativeElement.querySelector('#readme-markdown'); + }; + + const sources = (readme: HTMLElement): string[] => Array.from(readme.querySelectorAll('img')).map((img) => img.getAttribute('src')); + + const cases: { name: string; readme: string; want: string[] }[] = [ + { + name: 'a relative markdown image', + readme: '![icon](icon.png)', + want: ['https://github.com/Helias/mod-bg-twinpeaks/raw/master/icon.png'], + }, + { + name: 'a relative html image', + readme: 'Twin Peaks World Map', + want: ['https://github.com/Helias/mod-bg-twinpeaks/raw/master/images/TP-WorldMap.png'], + }, + { + name: 'a path starting with ./', + readme: '![map](./images/map.png)', + want: ['https://github.com/Helias/mod-bg-twinpeaks/raw/master/images/map.png'], + }, + { + name: 'a path starting with / as the repository root', + readme: '![map](/images/map.png)', + want: ['https://github.com/Helias/mod-bg-twinpeaks/raw/master/images/map.png'], + }, + { + name: 'every image in the README', + readme: '![one](one.png)\n\n![two](two.png)', + want: ['https://github.com/Helias/mod-bg-twinpeaks/raw/master/one.png', 'https://github.com/Helias/mod-bg-twinpeaks/raw/master/two.png'], + }, + { + name: 'nothing for an https url', + readme: '![shot](https://example.com/shot.png)', + want: ['https://example.com/shot.png'], + }, + { + name: 'nothing for a protocol-relative url', + readme: 'shot', + want: ['//cdn.example.com/shot.png'], + }, + { + name: 'nothing for a data url', + readme: 'dot', + want: ['data:image/gif;base64,R0lGODlhAQABAAAAACw='], + }, + ]; + + cases.forEach(({ name, readme, want }) => { + it(`should resolve ${name}`, async () => { + expect(sources(await renderReadme(readme))).toEqual(want); + }); + }); + + it('should resolve against the default branch of the repository', async () => { + expect(sources(await renderReadme('![icon](icon.png)', 'main'))).toEqual(['https://github.com/Helias/mod-bg-twinpeaks/raw/main/icon.png']); + }); + + it('should leave image examples inside code blocks untouched', async () => { + const readme = await renderReadme('```html\n\n```'); + + expect(readme.querySelector('code').textContent).toContain(''); + }); +}); + describe('RepoDetailsComponent', () => { let component: RepoDetailsComponent; let fixture: ComponentFixture; diff --git a/src/app/repo-details/repo-details.component.ts b/src/app/repo-details/repo-details.component.ts index a6ec8d0..b33c7d2 100644 --- a/src/app/repo-details/repo-details.component.ts +++ b/src/app/repo-details/repo-details.component.ts @@ -1,64 +1,72 @@ -import { Component } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; -import { faGithub } from '@fortawesome/free-brands-svg-icons'; -import { - faBalanceScale, - faCaretLeft, - faClock, - faCodeBranch, - faExternalLinkAlt, - faEye, - faGlobe, - faStar, - faUserCircle, - faSync, -} from '@fortawesome/free-solid-svg-icons'; -import { Observable } from 'rxjs'; -import { pluck, tap } from 'rxjs/operators'; -import { RepoDetailsData } from '../services/resolvers/repo-details-resolver.service'; - -const RETURN_HASH_STORAGE_KEY = 'azerothcore.catalogue.returnHash'; - -@Component({ - selector: 'app-repo-details', - templateUrl: './repo-details.component.html', - styleUrls: ['./repo-details.component.scss'], - standalone: false -}) -export class RepoDetailsComponent { - constructor(private readonly route: ActivatedRoute) { - this.data$ = route.data.pipe(pluck('data')).pipe( - tap((data) => { - if (data && data.repo) { - window.parent.document.title = data.repo.name; - } - }), - ); - } - - readonly faCaretLeft = faCaretLeft; - readonly faGlobe = faGlobe; - readonly faUserCircle = faUserCircle; - readonly faGithub = faGithub; - readonly faExternalLinkAlt = faExternalLinkAlt; - readonly faEye = faEye; - readonly faStar = faStar; - readonly faCodeBranch = faCodeBranch; - readonly faClock = faClock; - readonly faBalanceScale = faBalanceScale; - readonly faSync = faSync; - readonly returnHash = this.readReturnHash(); - - data$: Observable; - - private readReturnHash(): string { - try { - const returnHash = sessionStorage.getItem(RETURN_HASH_STORAGE_KEY); - if (returnHash && returnHash.indexOf('#/') === 0 && returnHash.indexOf('#/details/') !== 0) { - return returnHash; - } - } catch (error) {} - - return '#/home'; - } -} +import { Component } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { faGithub } from '@fortawesome/free-brands-svg-icons'; +import { + faBalanceScale, + faCaretLeft, + faCode, + faCodeBranch, + faExclamationCircle, + faEye, + faStar, +} from '@fortawesome/free-solid-svg-icons'; +import { Observable } from 'rxjs'; +import { pluck, tap } from 'rxjs/operators'; +import { Repository } from 'src/@types'; +import { RepoDetailsData } from '../services/resolvers/repo-details-resolver.service'; + +const RETURN_HASH_STORAGE_KEY = 'azerothcore.catalogue.returnHash'; +const ABSOLUTE_URL = /^([a-z][a-z\d+.-]*:|\/\/)/i; + +@Component({ + selector: 'app-repo-details', + templateUrl: './repo-details.component.html', + styleUrls: ['./repo-details.component.scss'], + standalone: false +}) +export class RepoDetailsComponent { + constructor(private readonly route: ActivatedRoute) { + this.data$ = route.data.pipe(pluck('data')).pipe( + tap((data) => { + if (data && data.repo) { + window.parent.document.title = data.repo.name; + } + }), + ); + } + + readonly faCaretLeft = faCaretLeft; + readonly faGithub = faGithub; + readonly faEye = faEye; + readonly faStar = faStar; + readonly faCodeBranch = faCodeBranch; + readonly faBalanceScale = faBalanceScale; + readonly faCode = faCode; + readonly faExclamationCircle = faExclamationCircle; + readonly returnHash = this.readReturnHash(); + + data$: Observable; + + resolveReadmeImages(readme: HTMLElement, repo: Repository): void { + const base = `https://github.com/${repo.full_name}/raw/${repo.default_branch}/`; + + readme.querySelectorAll('img').forEach((img) => { + const src = img.getAttribute('src'); + if (src && !ABSOLUTE_URL.test(src)) { + // on GitHub a leading slash means the repository root, not the root of github.com + img.src = new URL(src.replace(/^\/+/, ''), base).href; + } + }); + } + + private readReturnHash(): string { + try { + const returnHash = sessionStorage.getItem(RETURN_HASH_STORAGE_KEY); + if (returnHash && returnHash.indexOf('#/') === 0 && returnHash.indexOf('#/details/') !== 0) { + return returnHash; + } + } catch (error) {} + + return '#/home'; + } +} diff --git a/src/app/repo/repo.component.html b/src/app/repo/repo.component.html index 3dd5c7c..a9ee520 100644 --- a/src/app/repo/repo.component.html +++ b/src/app/repo/repo.component.html @@ -1,18 +1,47 @@ -
+ {{ fullName }} -
-

- {{ name }} -

- - {{ stars }} | Created {{ created | amTimeAgo }} - | Updated {{ updated | amTimeAgo }} + +
+
+

{{ name }}

+ {{ fullName }} +
+ + @if (description) { +

{{ description }}

+ } + + @if (topics?.length) { +
+ @for (topic of (topics || []).slice(0, 4); track topic) { + {{ topic }} + } +
+ } +
+ +
+ + + @for (star of starList; track $index; let i = $index) { + + } + + {{ stars }} -

{{ description }}

+ @if (updated) { + {{ updated | amTimeAgo }} + } +
-
+ diff --git a/src/app/repo/repo.component.scss b/src/app/repo/repo.component.scss index 9bd85b4..9c862e5 100644 --- a/src/app/repo/repo.component.scss +++ b/src/app/repo/repo.component.scss @@ -1,4 +1,229 @@ -.logo-small { - height: 80px; - width: 80px; +:host { + display: block; + animation: row-enter 0.4s cubic-bezier(0.2, 0.6, 0.2, 1) both; +} + +@keyframes row-enter { + from { + opacity: 0; + transform: translateY(10px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +@media (prefers-reduced-motion: reduce) { + :host { + animation: none; + } +} + +.repo-row { + display: grid; + grid-template-columns: 40px minmax(0, 1fr) auto; + gap: 1rem; + align-items: start; + padding: 1.05rem 0.65rem; + border-bottom: 1px solid #e4e7ec; + color: inherit; + text-decoration: none; + transition: background 0.15s ease; + + &:hover { + background: #fff; + text-decoration: none; + + .repo-row-name { + color: #b4232a; + } + + .repo-row-arrow { + color: #b4232a; + transform: translateX(3px); + } + } +} + +.repo-row-icon { + width: 40px; + height: 40px; + border-radius: 10px; + object-fit: cover; + background: #eef0f3; +} + +.repo-row-body { + min-width: 0; +} + +.repo-row-head { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 0.25rem 0.7rem; +} + +.repo-row-name { + margin: 0; + overflow: hidden; + color: #14171c; + font-size: 0.98rem; + font-weight: 600; + letter-spacing: -0.01em; + text-overflow: ellipsis; + white-space: nowrap; + transition: color 0.15s ease; +} + +.repo-row-author { + overflow: hidden; + color: #98a1af; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.7rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.repo-row-description { + margin: 0.3rem 0 0; + overflow: hidden; + color: #5f6b7a; + font-size: 0.86rem; + line-height: 1.5; + text-overflow: ellipsis; + white-space: nowrap; +} + +.repo-row-topics { + display: flex; + flex-wrap: wrap; + gap: 0.3rem; + margin-top: 0.5rem; + + span { + padding: 0.12rem 0.45rem; + border: 1px solid #e4e7ec; + border-radius: 5px; + background: #fff; + color: #6b7686; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.65rem; + } +} + +.repo-row-meta { + display: grid; + grid-template-columns: auto auto 1rem; + gap: 1rem; + align-items: center; + padding-top: 0.15rem; + color: #8a94a3; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.72rem; + white-space: nowrap; +} + +.repo-row-stars { + display: inline-flex; + align-items: center; + gap: 0.35rem; + color: #47505d; + + fa-icon { + font-size: 0.68rem; + } + + &.is-gold { + color: #b8860b; + + fa-icon { + color: #d4a017; + } + } + + .star-stack { + display: inline-flex; + align-items: center; + gap: 1px; + } + + .star-stack--triple { + display: grid; + grid-template-columns: repeat(2, auto); + justify-items: center; + gap: 1px 2px; + + fa-icon:first-child { + grid-column: 1 / -1; + } + } +} + +:host-context(.catalogue-ready) fa-icon.is-animated { + transform-origin: center; + animation: star-spin-in 0.8s cubic-bezier(0.22, 0.61, 0.36, 1) both; +} + +@keyframes star-spin-in { + 0% { + opacity: 0; + transform: rotate(-360deg) scale(0.2); + filter: drop-shadow(0 0 0 rgba(212, 160, 23, 0)); + } + + 70% { + opacity: 1; + transform: rotate(18deg) scale(1.18); + } + + 100% { + opacity: 1; + transform: rotate(0) scale(1); + filter: drop-shadow(0 0 4px rgba(212, 160, 23, 0.45)); + } +} + +@media (prefers-reduced-motion: reduce) { + :host-context(.catalogue-ready) fa-icon.is-animated { + animation: none !important; + } +} + +.repo-row-arrow { + color: #c3c9d2; + transition: color 0.15s ease, transform 0.15s ease; +} + +@media (max-width: 575px) { + .repo-row { + grid-template-columns: 34px minmax(0, 1fr); + gap: 0.75rem; + } + + .repo-row-icon { + width: 34px; + height: 34px; + border-radius: 8px; + } + + .repo-row-meta { + grid-column: 2; + grid-template-columns: auto auto; + justify-content: start; + padding-top: 0; + } + + .repo-row-arrow { + display: none; + } + + .repo-row-description { + white-space: normal; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + } } diff --git a/src/app/repo/repo.component.ts b/src/app/repo/repo.component.ts index 33d9604..48d6a50 100644 --- a/src/app/repo/repo.component.ts +++ b/src/app/repo/repo.component.ts @@ -1,20 +1,27 @@ -import { Component, Input } from '@angular/core'; -import { faStar, IconDefinition } from '@fortawesome/free-solid-svg-icons'; - -@Component({ - selector: 'app-repo', - templateUrl: './repo.component.html', - styleUrls: ['./repo.component.scss'], - standalone: false -}) -export class RepoComponent { - @Input() id: number; - @Input() name: string; - @Input() stars: number; - @Input() created: Date; - @Input() updated: Date; - @Input() description: string; - @Input() fullName: string; - - readonly faStar: IconDefinition = faStar; -} +import { Component, Input } from '@angular/core'; +import { faStar, IconDefinition } from '@fortawesome/free-solid-svg-icons'; + +@Component({ + selector: 'app-repo', + templateUrl: './repo.component.html', + styleUrls: ['./repo.component.scss'], + standalone: false +}) +export class RepoComponent { + @Input() id: number; + @Input() name: string; + @Input() stars: number; + @Input() created: Date; + @Input() updated: Date; + @Input() description: string; + @Input() fullName: string; + @Input() topics: string[] = []; + @Input() starDelay = 0; + + get starList(): number[] { + const count = this.stars > 300 ? 3 : this.stars > 100 ? 2 : 1; + return Array.from({ length: count }, (_, index) => index); + } + + readonly faStar: IconDefinition = faStar; +} diff --git a/src/app/services/catalogue/catalogue.service.ts b/src/app/services/catalogue/catalogue.service.ts index 35cbbd7..2ca1c47 100644 --- a/src/app/services/catalogue/catalogue.service.ts +++ b/src/app/services/catalogue/catalogue.service.ts @@ -135,7 +135,7 @@ export class CatalogueService { } getLocalRepo(id: number): Observable { - const key = 'repo-' + id; + const key = `repo-${id}`; const item = localStorage.getItem(key); if (item && !this.expireMinutes(30, JSON.parse(item).timeDate)) { diff --git a/src/styles.scss b/src/styles.scss index ceb3bc1..b281e39 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -1,7 +1,7 @@ @import "node_modules/bootstrap/scss/bootstrap.scss"; html, body { height: 100%; } -body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } +body { margin: 0; background: #f6f7f9; color: #14171c; font-family: Roboto, "Helvetica Neue", sans-serif; } /* Ensure images inside README markdown scale correctly. Using a global rule so it applies to content rendered via innerHTML/ngx-markdown