From efcac3ee132ab3a15a2b07c5cac8b8c195757a8b Mon Sep 17 00:00:00 2001 From: Quildra Date: Thu, 18 Jul 2024 14:27:43 +0100 Subject: [PATCH] placeholder goost sheets create button --- src/app/app.component.html | 4 ++++ src/app/app.component.ts | 32 ++++++++++++++++++++++++++++---- src/app/auth.service.ts | 8 +++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 36093e1..089a58e 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -334,3 +334,7 @@ + +
+ +
diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 40d1abc..f0f9063 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,13 +1,37 @@ -import { Component } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; +import { Component, OnInit } from '@angular/core'; +import { RouterOutlet, Router } from '@angular/router'; +import { CommonModule } from '@angular/common'; + +import { AuthService } from './auth.service'; @Component({ selector: 'app-root', standalone: true, - imports: [RouterOutlet], + imports: [ + RouterOutlet, + CommonModule + ], templateUrl: './app.component.html', styleUrl: './app.component.css' }) -export class AppComponent { +export class AppComponent implements OnInit { title = 'jedi-archive-frontend'; + isAuthenticated = false; + + constructor(private authService: AuthService, private router: Router) {} + + ngOnInit(): void { + this.isAuthenticated = !!localStorage.getItem('token'); + } + + createSheet() { + this.authService.createSheet('My New Sheet').subscribe( + res => { + console.log('Sheet created with ID:', res.sheetId); + alert('Sheet created with ID: ' + res.sheetId); + }, + err => console.error(err) + ); + } + } diff --git a/src/app/auth.service.ts b/src/app/auth.service.ts index 55d7590..bad3936 100644 --- a/src/app/auth.service.ts +++ b/src/app/auth.service.ts @@ -1,6 +1,6 @@ // src/app/auth.service.ts import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; @Injectable({ @@ -26,4 +26,10 @@ export class AuthService { handleGoogleCallback(code: string): Observable { return this.http.get(`${this.apiUrl}/google/callback?code=${code}`); } + + createSheet(title: string): Observable { + const token = localStorage.getItem('token'); + const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`); + return this.http.post(`${this.apiUrl}/create-sheet`, { title }, { headers }); + } }