-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d970d12
commit 490a4fe
Showing
8 changed files
with
163 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
libs/goal/src/lib/modals/integrations/integrations.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<strive-header-modal (dismiss)="dismiss()"> | ||
<ion-title>Integrations</ion-title> | ||
</strive-header-modal> | ||
|
||
<ion-content class="ion-padding"> | ||
@if (view$ | async; as view) { | ||
|
||
<h5>Active Integrations</h5> | ||
<ul> | ||
@for (integration of activeIntegrations; track integration) { | ||
<li (click)="dismiss(integration.id)"> | ||
<img [asset]="integration.image" [alt]="integration.name" /> | ||
<span>{{ integration.name }}</span> | ||
<small>{{ view.strava | activities }}</small> | ||
</li> | ||
} | ||
</ul> | ||
|
||
@if (availableIntegrations.length) { | ||
<h5>Available Integrations</h5> | ||
<ul> | ||
@for (integration of availableIntegrations; track integration) { | ||
<li (click)="dismiss(integration.id)"> | ||
<img [asset]="integration.image" [alt]="integration.name" /> | ||
<span>{{ integration.name }}</span> | ||
</li> | ||
} | ||
</ul> | ||
} | ||
} @else { | ||
<strive-page-loading /> | ||
} | ||
|
||
</ion-content> |
17 changes: 17 additions & 0 deletions
17
libs/goal/src/lib/modals/integrations/integrations.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ul { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(100px, 150px)); | ||
grid-gap: 20px; | ||
|
||
li { | ||
cursor: pointer; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 8px; | ||
|
||
small { | ||
color: var(--ion-color-medium); | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
libs/goal/src/lib/modals/integrations/integrations.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { CommonModule, Location } from '@angular/common' | ||
import { ChangeDetectionStrategy, Component, Input, OnInit, Pipe, PipeTransform } from '@angular/core' | ||
|
||
import { IonContent, IonTitle, ModalController } from '@ionic/angular/standalone' | ||
import { BehaviorSubject, combineLatest, filter, map, switchMap, tap } from 'rxjs' | ||
import { where } from 'firebase/firestore' | ||
|
||
import { HeaderModalComponent } from '@strive/ui/header-modal/header-modal.component' | ||
import { PageLoadingComponent } from '@strive/ui/page-loading/page-loading.component' | ||
import { ModalDirective } from '@strive/utils/directives/modal.directive' | ||
import { ImageDirective } from '@strive/media/directives/image.directive' | ||
import { StravaIntegration } from '@strive/model' | ||
import { StravaService } from '@strive/strava/strava.service' | ||
import { AuthService } from '@strive/auth/auth.service' | ||
import { capitalizeFirstLetter } from '@strive/utils/helpers' | ||
|
||
interface Integration { | ||
id: string | ||
name: string | ||
image: string | ||
} | ||
|
||
@Pipe({ name: 'activities', standalone: true }) | ||
export class StravaActivitiesPipe implements PipeTransform { | ||
transform(strava: StravaIntegration | undefined) { | ||
return strava?.activityTypes.map(type => capitalizeFirstLetter(type)).join(', ') | ||
} | ||
} | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'strive-integrations', | ||
templateUrl: './integrations.component.html', | ||
styleUrls: ['./integrations.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [ | ||
CommonModule, | ||
StravaActivitiesPipe, | ||
HeaderModalComponent, | ||
PageLoadingComponent, | ||
ImageDirective, | ||
IonContent, | ||
IonTitle | ||
] | ||
}) | ||
export class IntegrationsComponent extends ModalDirective implements OnInit { | ||
|
||
@Input() goalId?: string | ||
|
||
activeIntegrations: Integration[] = [] | ||
availableIntegrations: Integration[] = [] | ||
|
||
private goalId$ = new BehaviorSubject(this.goalId) | ||
private strava$ = this.goalId$.pipe( | ||
filter(goalId => !!goalId), | ||
switchMap(goalId => this.stravaService.valueChanges([ | ||
where('goalId', '==', goalId), | ||
where('userId', '==', this.auth.uid)] | ||
)), | ||
map(integrations => integrations.length ? integrations[0] : undefined), | ||
tap(strava => { | ||
const integration: Integration = { | ||
id: 'strava', | ||
name: 'Strava', | ||
image: 'strava.png' | ||
} | ||
|
||
if (strava) { | ||
this.activeIntegrations.push(integration) | ||
} else { | ||
this.availableIntegrations.push(integration) | ||
} | ||
}) | ||
) | ||
|
||
view$ = combineLatest([ | ||
this.strava$ | ||
]).pipe( | ||
map(([strava]) => ({ strava })) | ||
) | ||
|
||
constructor( | ||
private auth: AuthService, | ||
protected override location: Location, | ||
protected override modalCtrl: ModalController, | ||
private stravaService: StravaService | ||
) { | ||
super(location, modalCtrl) | ||
} | ||
|
||
ngOnInit() { | ||
this.goalId$.next(this.goalId) | ||
} | ||
} |