Skip to content

Commit

Permalink
chore(demo): show github star in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Oct 14, 2024
1 parent 9c91f0f commit d7bc432
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
1 change: 1 addition & 0 deletions projects/demo/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const environment = {
github: 'https://api.github.com/repos/taiga-family/taiga-ui',
production: true,
ym: 87890624,
};
37 changes: 35 additions & 2 deletions projects/demo/src/modules/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import {isPlatformServer} from '@angular/common';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import type {OnInit} from '@angular/core';
import {Component, DestroyRef, inject, ViewEncapsulation} from '@angular/core';
import {
Component,
DestroyRef,
inject,
PLATFORM_ID,
signal,
ViewEncapsulation,
} from '@angular/core';
import {takeUntilDestroyed, toSignal} from '@angular/core/rxjs-interop';
import {NavigationEnd, Router} from '@angular/router';
import {changeDetection} from '@demo/emulate/change-detection';
import {environment} from '@demo/environments/environment';
import {DemoRoute} from '@demo/routes';
import {TuiDemo} from '@demo/utils';
import {WA_LOCAL_STORAGE} from '@ng-web-apis/common';
import {ResizeObserverService} from '@ng-web-apis/resize-observer';
import {TuiButton, TuiDataList, TuiDropdown} from '@taiga-ui/core';
import {TuiButton, TuiDataList, TuiDropdown, TuiIcon} from '@taiga-ui/core';
import {TuiBadge, TuiBadgedContent} from '@taiga-ui/kit';
import {TuiSheetModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy';
import {distinctUntilChanged, filter, map, startWith} from 'rxjs';

Expand All @@ -23,11 +34,15 @@ import {TUI_VERSION_MANAGER_PROVIDERS} from './version-manager/version-manager.p
selector: 'app',
imports: [
CustomHost,
HttpClientModule,
TuiAlgoliaSearch,
TuiBadge,
TuiBadgedContent,
TuiButton,
TuiDataList,
TuiDemo,
TuiDropdown,
TuiIcon,
TuiSheetModule,
TuiTextfieldControllerModule,
VersionManager,
Expand All @@ -54,11 +69,14 @@ import {TUI_VERSION_MANAGER_PROVIDERS} from './version-manager/version-manager.p
],
})
export class App extends AbstractDemo implements OnInit {
private readonly isServer = isPlatformServer(inject(PLATFORM_ID));
private readonly destroyRef = inject(DestroyRef);
private readonly http = inject(HttpClient);
private readonly ym = inject(YaMetrikaService);
protected readonly router = inject(Router);
protected readonly storage = inject(WA_LOCAL_STORAGE);
protected readonly routes = DemoRoute;
protected readonly stars = signal('');

protected readonly isLanding = toSignal(
this.router.events.pipe(
Expand All @@ -73,6 +91,21 @@ export class App extends AbstractDemo implements OnInit {
public override async ngOnInit(): Promise<void> {
await super.ngOnInit();
this.enableYandexMetrika();

if (this.isServer) {
return;
}

this.http
.get<Record<string, any>>(environment.github)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((response) =>
this.stars.set(
Intl.NumberFormat('en', {notation: 'compact'}).format(
response['stargazers_count'],
),
),
);
}

private enableYandexMetrika(): void {
Expand Down
3 changes: 2 additions & 1 deletion projects/demo/src/modules/app/app.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ app {
}

@media @tui-mobile {
.app-link {
// Increasing specificity
.app-link.app-link {
display: none;
}

Expand Down
41 changes: 31 additions & 10 deletions projects/demo/src/modules/app/app.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,37 @@
</ng-template>
</button>

<a
appearance="icon"
href="https://github.com/taiga-family/taiga-ui"
iconStart="assets/images/github.svg"
rel="noreferrer"
target="_blank"
title="Taiga UI source code on GitHub"
tuiLink
class="app-link"
></a>
<tui-badged-content class="app-link">
<tui-icon
appearance="flat"
icon="@tui.star"
size="s"
style="color: orange"
tuiBadge
tuiSlot="bottom"
/>

<a
href="https://github.com/taiga-family/taiga-ui"
rel="noreferrer"
target="_blank"
title="Taiga UI source code on GitHub"
>
<button
appearance="whiteblock"
size="s"
tuiButton
type="button"
class="app-link"
>
<tui-icon
icon="@tui.github"
[style.height.rem]="1"
/>
{{ stars() }}
</button>
</a>
</tui-badged-content>

<a
appearance="icon"
Expand Down
3 changes: 2 additions & 1 deletion projects/demo/used-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const TUI_USED_ICONS = [
'@tui.settings',
'@tui.chevron-down',
'@tui.ellipsis',
'@tui.star',
'@tui.github',
'@tui.calendar',
'@tui.visa-mono',
'@tui.mastercard-mono',
Expand All @@ -19,7 +21,6 @@ export const TUI_USED_ICONS = [
'@tui.trash',
'@tui.layout-grid',
'@tui.x',
'@tui.star',
'@tui.check',
'@tui.user',
'@tui.chevron-left',
Expand Down

0 comments on commit d7bc432

Please sign in to comment.