From eb0f1c7f6a44a5175627f024f3ff353d17d02c9f Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Tue, 31 May 2022 22:18:31 +0200 Subject: [PATCH] Clears fields better --- src/PersonView.ts | 20 ++++++++++++++++++-- src/PersonsView.ts | 26 ++++++++++++++++++++++++++ src/WebBrain.ts | 25 ++++++++----------------- src/models/people.ts | 10 ++++++---- 4 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 src/PersonsView.ts diff --git a/src/PersonView.ts b/src/PersonView.ts index fb7d58d..00027e9 100644 --- a/src/PersonView.ts +++ b/src/PersonView.ts @@ -1,3 +1,4 @@ +import { Timestamp } from 'firebase/firestore'; import { LitElement, html, css } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { IPerson } from './models/people.js'; @@ -9,10 +10,25 @@ export class PersonView extends LitElement { @property({type: Object}) person! : IPerson; - static styles = css``; render() { - return html`
  • ${this.personId} - ${this.person.name}
  • `; + return html` +
  • + ${this.formatTime(this.person.updatedAt)} - ${this.person.name} +
    +
      + ${this.person.entries.map((entry) => + html`
    • ${this.formatTime(entry.updatedAt)} - ${entry.content}
    • ` + )} +
    +
    +
  • + `; + } + + // eslint-disable-next-line class-methods-use-this + formatTime(zeTime? : Timestamp | null) { + return zeTime ? zeTime.toDate().toLocaleDateString() : "unknown"; } } diff --git a/src/PersonsView.ts b/src/PersonsView.ts new file mode 100644 index 0000000..708cdc5 --- /dev/null +++ b/src/PersonsView.ts @@ -0,0 +1,26 @@ +import { css, html, LitElement } from "lit"; +import { customElement, property } from 'lit/decorators.js'; + +import { IPerson } from "./models/people.js"; + +import "./PersonView.js"; + +@customElement("persons-view") +export class PersonsView extends LitElement{ + + @property({type: String}) search : string = ""; + + @property({type: Array}) persons : Array<[string, IPerson]> = []; + + static styles = css``; + + render(){ + return html` + + `; + } +} \ No newline at end of file diff --git a/src/WebBrain.ts b/src/WebBrain.ts index dc96014..e013910 100644 --- a/src/WebBrain.ts +++ b/src/WebBrain.ts @@ -15,12 +15,12 @@ import { onAuthStateChanged } from 'firebase/auth'; -import { getFirestore, collection, Firestore, onSnapshot, addDoc, CollectionReference } from "firebase/firestore"; +import { getFirestore, collection, Firestore, onSnapshot, addDoc, CollectionReference, Timestamp } from "firebase/firestore"; import { FIREBASE_CONFIG } from './constants.js'; import { IEntry, IPerson } from './models/people.js'; -import "./PersonView.js" +import "./PersonsView.js" @customElement('web-brain') export class WebBrain extends LitElement { @@ -52,7 +52,6 @@ export class WebBrain extends LitElement { this.auth = getAuth(); onAuthStateChanged(this.auth, (user) => { - console.log(`onAuthStateChanged ${user}`); if (user) { this.user = user; this.peopleCollection = collection(this.firestore, `/users/${this.user.uid}/people`); @@ -72,7 +71,6 @@ export class WebBrain extends LitElement { static styles = css``; async logIn() { - console.log('Logging in'); try { await setPersistence(this.auth,browserLocalPersistence); const result = await signInWithPopup(this.auth, this.provider); @@ -84,19 +82,18 @@ export class WebBrain extends LitElement { } async logout() { - console.log('Logging out'); try { await signOut(this.auth); console.log('logged out'); this.user = null; + this.persons = []; + this.search = ""; } catch (error) { console.log('Error while logging out', error); } } async savePerson() { - console.log(`saving ${JSON.stringify(this.newPerson)}`); - if(this.peopleCollection){ try { const docRef = await addDoc(this.peopleCollection, this.newPerson); @@ -145,9 +142,10 @@ export class WebBrain extends LitElement { Adding a new person @@ -159,14 +157,7 @@ export class WebBrain extends LitElement {

    The content will come here

    - - - +
    diff --git a/src/models/people.ts b/src/models/people.ts index 2be38a1..afc1346 100644 --- a/src/models/people.ts +++ b/src/models/people.ts @@ -1,12 +1,14 @@ +import { Timestamp } from "firebase/firestore"; + export interface IEntry { content: string, - createdAt?: Date | null, - updatedAt?: Date | null, + createdAt?: Timestamp | null, + updatedAt?: Timestamp | null, } export interface IPerson { name: string, - createdAt?: Date | null, - updatedAt?: Date | null, + createdAt?: Timestamp | null, + updatedAt?: Timestamp | null, entries: Array, } \ No newline at end of file