Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/Enable overriding Flatfile default loading component #216

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/proud-books-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flatfile/angular-sdk': minor
---

Allow overriding the default loading component in Angular by assigning a custom TemplateRef to the ISpace['loading'] property. This enables users to replace the default loading spinner with their own loading template.
22 changes: 15 additions & 7 deletions packages/angular/angular-sdk/src/lib/sdk/space.component.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<div *ngIf="!this.closeInstance">
<spinner *ngIf="this.loading"/>
<div *ngIf="!closeInstance">
<ng-container
*ngIf="spaceProps.loading && loading"
[ngTemplateOutlet]="spaceProps.loading"
/>
<spinner *ngIf="loading && !spaceProps.loading" />
mattheri marked this conversation as resolved.
Show resolved Hide resolved

<div *ngIf="this.spaceFrameProps !== undefined;else error_content">
<space-frame *ngIf="this.spaceFrameProps.localAccessToken" [loading]="this.loading" [spaceFrameProps]="this.spaceFrameProps" />
<div *ngIf="spaceFrameProps !== undefined; else error_content">
<space-frame
*ngIf="spaceFrameProps.localAccessToken"
[loading]="loading"
[spaceFrameProps]="spaceFrameProps"
/>
mattheri marked this conversation as resolved.
Show resolved Hide resolved
</div>
<ng-template #error_content>
<div *ngIf="this.error" class="ff_error_container">
<div *ngIf="error" class="ff_error_container">
<h3 class="ff_error_heading">Something Went Wrong</h3>
<p class="ff_error_text">
{{this.error.message}}
<p class="ff_error_text" *ngIf="error.message">
{{ error.message }}
mattheri marked this conversation as resolved.
Show resolved Hide resolved
</p>
</div>
</ng-template>
Expand Down
33 changes: 28 additions & 5 deletions packages/angular/angular-sdk/src/lib/sdk/space.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Component, Input, OnInit } from '@angular/core'
import {
ChangeDetectorRef,
Component,
Input,
OnChanges,
OnInit,
SimpleChanges,
} from '@angular/core'
import { Flatfile } from '@flatfile/api'
import {
type ISpace,
InitialResourceData,
type ReusedSpaceWithAccessToken,
type SimpleOnboarding,
createWorkbookFromSheet,
initNewSpace,
InitialResourceData,
} from '@flatfile/embedded-utils'
import getSpace from '../../utils/getSpace'
import { SpaceFramePropsType } from './space-frame/spaceFrame.component'
import { SpaceService } from './space.service'
import { Flatfile } from '@flatfile/api'

type ReusedOrOnboarding = ReusedSpaceWithAccessToken | SimpleOnboarding

Expand All @@ -19,7 +26,7 @@ type ReusedOrOnboarding = ReusedSpaceWithAccessToken | SimpleOnboarding
templateUrl: './space.component.html',
styleUrls: ['./space.component.scss'],
})
export class Space implements OnInit {
export class Space implements OnInit, OnChanges {
@Input() spaceProps!: ISpace
@Input() openDirectly: boolean = false

Expand All @@ -30,7 +37,10 @@ export class Space implements OnInit {
loading: boolean = false
closeInstance: boolean = false

constructor(private readonly appService: SpaceService) {}
constructor(
private readonly appService: SpaceService,
private readonly changeDetectorRef: ChangeDetectorRef
) {}

async ngOnInit() {
if (!this.spaceProps) throw new Error('Please define the space props')
Expand All @@ -44,6 +54,16 @@ export class Space implements OnInit {
}
}

ngOnChanges(changes: SimpleChanges): void {
if ('spaceProps' in changes && !changes['spaceProps'].firstChange) {
this.spaceProps = {
...this.spaceProps,
...changes['spaceProps'].currentValue,
}
this.changeDetectorRef.markForCheck()
}
}
mattheri marked this conversation as resolved.
Show resolved Hide resolved

handleCloseInstance() {
this.closeInstance = true
}
Expand Down Expand Up @@ -91,6 +111,7 @@ export class Space implements OnInit {
}

initSpace = async (spaceProps: ReusedOrOnboarding) => {
this.changeDetectorRef.markForCheck()
this.closeInstance = false

try {
Expand Down Expand Up @@ -128,6 +149,8 @@ export class Space implements OnInit {
this.loading = false
this.error = error as Error
throw error
} finally {
this.changeDetectorRef.markForCheck()
}
}
}