content.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { MultipleCodeBlock } from 'ui-patterns/MultipleCodeBlock'
  2. import type { StepContentProps } from '@/components/interfaces/ConnectSheet/Connect.types'
  3. const ContentFile = ({ projectKeys }: StepContentProps) => {
  4. const files = [
  5. {
  6. name: 'environments/environment.ts',
  7. language: 'ts',
  8. code: `
  9. export const environment = {
  10. brivenUrl: '${projectKeys.apiUrl ?? 'your-project-url'}',
  11. brivenKey: '${projectKeys.publishableKey ?? '<prefer publishable key instead of anon key for mobile apps>'}',
  12. };
  13. `,
  14. },
  15. {
  16. name: 'src/app/briven.service.ts',
  17. language: 'ts',
  18. code: `
  19. import { Injectable } from '@angular/core';
  20. import { createClient, BrivenClient } from '@supabase/supabase-js';
  21. import { environment } from '../environments/environment';
  22. @Injectable({
  23. providedIn: 'root',
  24. })
  25. export class BrivenService {
  26. private briven: BrivenClient;
  27. constructor() {
  28. this.briven = createClient(
  29. environment.brivenUrl,
  30. environment.brivenKey
  31. );
  32. }
  33. getTodos() {
  34. return this.briven.from('todos').select('*');
  35. }
  36. }
  37. `,
  38. },
  39. {
  40. name: 'src/app/app.component.ts',
  41. language: 'ts',
  42. code: `
  43. import { Component, OnInit } from '@angular/core';
  44. import { BrivenService } from './briven.service';
  45. @Component({
  46. selector: 'app-root',
  47. templateUrl: 'app.component.html',
  48. styleUrls: ['app.component.scss'],
  49. })
  50. export class AppComponent implements OnInit {
  51. todos: any[] = [];
  52. constructor(private brivenService: BrivenService) {}
  53. async ngOnInit() {
  54. await this.loadTodos();
  55. }
  56. async loadTodos() {
  57. const { data, error } = await this.brivenService.getTodos();
  58. if (error) {
  59. console.error('Error fetching todos:', error);
  60. } else {
  61. this.todos = data;
  62. }
  63. }
  64. }
  65. `,
  66. },
  67. {
  68. name: 'src/app/app.component.html',
  69. language: 'html',
  70. code: `
  71. <ion-header>
  72. <ion-toolbar>
  73. <ion-title>Todo List</ion-title>
  74. </ion-toolbar>
  75. </ion-header>
  76. <ion-content>
  77. <ion-list>
  78. <ion-item *ngFor="let todo of todos">
  79. <ion-label>{{ todo.name }}</ion-label>
  80. </ion-item>
  81. </ion-list>
  82. </ion-content>
  83. `,
  84. },
  85. {
  86. name: 'src/app/app.module.ts',
  87. language: 'ts',
  88. code: `
  89. import { NgModule } from '@angular/core';
  90. import { FormsModule } from '@angular/forms';
  91. import { BrowserModule } from '@angular/platform-browser';
  92. import { RouterModule } from '@angular/router';
  93. import { IonicModule } from '@ionic/angular';
  94. import { AppComponent } from './app.component';
  95. import { BrivenService } from './briven.service';
  96. @NgModule({
  97. imports: [
  98. BrowserModule,
  99. FormsModule,
  100. RouterModule.forRoot([]),
  101. IonicModule.forRoot({ mode: 'ios' }),
  102. ],
  103. declarations: [AppComponent],
  104. providers: [BrivenService],
  105. bootstrap: [AppComponent],
  106. })
  107. export class AppModule {}
  108. `,
  109. },
  110. ]
  111. return <MultipleCodeBlock files={files} />
  112. }
  113. export default ContentFile