Skip to content

Commit

Permalink
simplying angular
Browse files Browse the repository at this point in the history
  • Loading branch information
Uttej Venkata Sastry committed Feb 21, 2025
1 parent 38b6b86 commit 2b68209
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
13 changes: 0 additions & 13 deletions packages/sdks-tests/src/snippet-tests/live-previewing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ test.describe('LivePreviewBlogData Component', () => {
await expect(blogPreview).toContainText('Blog Title: Welcome to Builder.io');
await expect(blogPreview).toContainText('Authored by: John Doe');
await expect(blogPreview).toContainText('Handle: john_doe');
await expect(blogPreview).toContainText('Published date: Tue Feb 11 2025');
});

test.describe('Live Preview blog data - Visual Editor', () => {
Expand All @@ -42,7 +41,6 @@ test.describe('LivePreviewBlogData Component', () => {
title: 'Welcome to Builder.io',
author: 'John Doe',
handle: 'john_doe',
publishedDate: 'Tue Feb 11 2025',
},
};
await expect(
Expand All @@ -54,18 +52,12 @@ test.describe('LivePreviewBlogData Component', () => {
await expect(
page.frameLocator('iframe').getByText(`Handle: ${INITIAL_CONTENT.data.handle}`)
).toBeVisible();
await expect(
page
.frameLocator('iframe')
.getByText(`Published date: ${INITIAL_CONTENT.data.publishedDate}`)
).toBeVisible();

const UPDATED_CONTENT = {
data: {
title: 'Welcome to Visual Editor',
author: 'Jane Doe',
handle: 'jane_doe',
publishedDate: `${new Date().toDateString()}`,
},
};

Expand All @@ -87,11 +79,6 @@ test.describe('LivePreviewBlogData Component', () => {
await expect(
page.frameLocator('iframe').getByText(`Handle: ${UPDATED_CONTENT.data.handle}`)
).toBeVisible();
await expect(
page
.frameLocator('iframe')
.getByText(`Published date: ${UPDATED_CONTENT.data.publishedDate}`)
).toBeVisible();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ import { subscribeToEditor } from '@builder.io/sdk-angular';
selector: 'app-live-preview',
imports: [CommonModule],
template: `
<div *ngIf="loading" class="loading-message">Loading Data...</div>
<div *ngIf="loading">Loading Data...</div>
<div *ngIf="!loading && content" class="blog-data-preview">
<div>Blog Title: {{ content.data?.title }}</div>
<div>Authored by: {{ content.data?.['author'] }}</div>
<div>Handle: {{ content.data?.['handle'] }}</div>
<div>
Published date:
{{ getFormattedDate(content.data?.['publishedDate']) }}
</div>
</div>
<div *ngIf="!loading && !content" class="no-data-message">No Data.</div>
`,
})
export class LivePreviewComponent implements OnInit, OnDestroy {
content: BuilderContent | null = null;
content: BuilderContent | undefined = undefined;
loading = true;

private unsubscribeFn?: () => void;
Expand All @@ -35,7 +30,7 @@ export class LivePreviewComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.content = this.route.snapshot.data['content'] || null;
this.content = this.route.snapshot.data['content'] || undefined;
this.loading = false;
this.unsubscribeFn = subscribeToEditor({
model: 'blog-data',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ import { fetchOneEntry, subscribeToEditor } from '@builder.io/sdk-angular';
selector: 'app-live-preview',
imports: [CommonModule],
template: `
<div *ngIf="loading" class="loading-message">Loading Data...</div>
<div *ngIf="loading">Loading Data...</div>
<div *ngIf="!loading && content" class="blog-data-preview">
<div>Blog Title: {{ content.data?.title }}</div>
<div>Authored by: {{ content.data?.['author'] }}</div>
<div>Handle: {{ content.data?.['handle'] }}</div>
<div>
Published date:
{{ getFormattedDate(content.data?.['publishedDate']) }}
</div>
</div>
<div *ngIf="!loading && !content" class="no-data-message">No Data.</div>
`,
})
export class LivePreviewComponent implements OnInit, OnDestroy {
content: BuilderContent | null = null;
content: BuilderContent | undefined = undefined;
loading = false;

private unsubscribeFn?: () => void;
Expand All @@ -44,7 +38,7 @@ export class LivePreviewComponent implements OnInit, OnDestroy {
userAttributes: { urlPath: this.router.url },
})
.then((data) => {
this.content = data || null;
this.content = data || undefined;
})
.finally(() => {
this.loading = false;
Expand Down

0 comments on commit 2b68209

Please sign in to comment.