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`
+
+ ${this.persons.filter( p => p[1].name.includes(this.search) ).map((person) =>
+ 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
{
- const entry : IEntry = { content : "Met at the 6th floor at SC"};
- const p : IPerson = { name: e.target.value, entries: [entry] }
+ // const entry : IEntry = { content : "Met at the 6th floor at SC", createdAt : new Date(), updatedAt : new Date() };
+ const p : IPerson = { name: e.target.value, entries: [], createdAt : Timestamp.fromDate(new Date()), updatedAt : Timestamp.fromDate(new Date())};
this.newPerson = p;
}}"
/>
@@ -159,14 +157,7 @@ export class WebBrain extends LitElement {
The content will come here
-
-
- ${this.persons.filter( p => p[1].name.includes(this.search) ).map((person) =>
- // html`- ${person[0]} - ${person[1].name}
`
- html``
- )}
-
-
+
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