mirror of
https://github.com/jlengrand/web-brain.git
synced 2026-03-10 08:51:21 +00:00
Clears fields better
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { Timestamp } from 'firebase/firestore';
|
||||||
import { LitElement, html, css } from 'lit';
|
import { LitElement, html, css } from 'lit';
|
||||||
import { customElement, property } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
import { IPerson } from './models/people.js';
|
import { IPerson } from './models/people.js';
|
||||||
@@ -9,10 +10,25 @@ export class PersonView extends LitElement {
|
|||||||
|
|
||||||
@property({type: Object}) person! : IPerson;
|
@property({type: Object}) person! : IPerson;
|
||||||
|
|
||||||
|
|
||||||
static styles = css``;
|
static styles = css``;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`<li>${this.personId} - ${this.person.name}</li>`;
|
return html`
|
||||||
|
<li>
|
||||||
|
${this.formatTime(this.person.updatedAt)} - ${this.person.name}
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
${this.person.entries.map((entry) =>
|
||||||
|
html`<li>${this.formatTime(entry.updatedAt)} - ${entry.content}</li>`
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line class-methods-use-this
|
||||||
|
formatTime(zeTime? : Timestamp | null) {
|
||||||
|
return zeTime ? zeTime.toDate().toLocaleDateString() : "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/PersonsView.ts
Normal file
26
src/PersonsView.ts
Normal file
@@ -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`
|
||||||
|
<ul>
|
||||||
|
${this.persons.filter( p => p[1].name.includes(this.search) ).map((person) =>
|
||||||
|
html`<person-view personId="${person[0]}" .person="${person[1]}"></person-view>`
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,12 +15,12 @@ import {
|
|||||||
onAuthStateChanged
|
onAuthStateChanged
|
||||||
} from 'firebase/auth';
|
} 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 { FIREBASE_CONFIG } from './constants.js';
|
||||||
import { IEntry, IPerson } from './models/people.js';
|
import { IEntry, IPerson } from './models/people.js';
|
||||||
import "./PersonView.js"
|
import "./PersonsView.js"
|
||||||
|
|
||||||
@customElement('web-brain')
|
@customElement('web-brain')
|
||||||
export class WebBrain extends LitElement {
|
export class WebBrain extends LitElement {
|
||||||
@@ -52,7 +52,6 @@ export class WebBrain extends LitElement {
|
|||||||
this.auth = getAuth();
|
this.auth = getAuth();
|
||||||
|
|
||||||
onAuthStateChanged(this.auth, (user) => {
|
onAuthStateChanged(this.auth, (user) => {
|
||||||
console.log(`onAuthStateChanged ${user}`);
|
|
||||||
if (user) {
|
if (user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.peopleCollection = collection(this.firestore, `/users/${this.user.uid}/people`);
|
this.peopleCollection = collection(this.firestore, `/users/${this.user.uid}/people`);
|
||||||
@@ -72,7 +71,6 @@ export class WebBrain extends LitElement {
|
|||||||
static styles = css``;
|
static styles = css``;
|
||||||
|
|
||||||
async logIn() {
|
async logIn() {
|
||||||
console.log('Logging in');
|
|
||||||
try {
|
try {
|
||||||
await setPersistence(this.auth,browserLocalPersistence);
|
await setPersistence(this.auth,browserLocalPersistence);
|
||||||
const result = await signInWithPopup(this.auth, this.provider);
|
const result = await signInWithPopup(this.auth, this.provider);
|
||||||
@@ -84,19 +82,18 @@ export class WebBrain extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async logout() {
|
async logout() {
|
||||||
console.log('Logging out');
|
|
||||||
try {
|
try {
|
||||||
await signOut(this.auth);
|
await signOut(this.auth);
|
||||||
console.log('logged out');
|
console.log('logged out');
|
||||||
this.user = null;
|
this.user = null;
|
||||||
|
this.persons = [];
|
||||||
|
this.search = "";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error while logging out', error);
|
console.log('Error while logging out', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async savePerson() {
|
async savePerson() {
|
||||||
console.log(`saving ${JSON.stringify(this.newPerson)}`);
|
|
||||||
|
|
||||||
if(this.peopleCollection){
|
if(this.peopleCollection){
|
||||||
try {
|
try {
|
||||||
const docRef = await addDoc(this.peopleCollection, this.newPerson);
|
const docRef = await addDoc(this.peopleCollection, this.newPerson);
|
||||||
@@ -145,9 +142,10 @@ export class WebBrain extends LitElement {
|
|||||||
Adding a new person
|
Adding a new person
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
.value = "${this.newPerson ? this.newPerson.name : ''}"
|
||||||
@input="${(e: any) => {
|
@input="${(e: any) => {
|
||||||
const entry : IEntry = { content : "Met at the 6th floor at SC"};
|
// 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: [entry] }
|
const p : IPerson = { name: e.target.value, entries: [], createdAt : Timestamp.fromDate(new Date()), updatedAt : Timestamp.fromDate(new Date())};
|
||||||
this.newPerson = p;
|
this.newPerson = p;
|
||||||
}}"
|
}}"
|
||||||
/>
|
/>
|
||||||
@@ -159,14 +157,7 @@ export class WebBrain extends LitElement {
|
|||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<main>
|
<main>
|
||||||
<h2>The content will come here</h2>
|
<h2>The content will come here</h2>
|
||||||
|
<persons-view .persons="${this.persons}" .search="${this.search}"></persons-view>
|
||||||
<ul>
|
|
||||||
${this.persons.filter( p => p[1].name.includes(this.search) ).map((person) =>
|
|
||||||
// html`<li>${person[0]} - ${person[1].name}</li>`
|
|
||||||
html`<person-view personId="${person[0]}" .person="${person[1]}"></person-view>`
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>Web brain, because you forget everything</footer>
|
<footer>Web brain, because you forget everything</footer>
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
|
import { Timestamp } from "firebase/firestore";
|
||||||
|
|
||||||
export interface IEntry {
|
export interface IEntry {
|
||||||
content: string,
|
content: string,
|
||||||
createdAt?: Date | null,
|
createdAt?: Timestamp | null,
|
||||||
updatedAt?: Date | null,
|
updatedAt?: Timestamp | null,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPerson {
|
export interface IPerson {
|
||||||
name: string,
|
name: string,
|
||||||
createdAt?: Date | null,
|
createdAt?: Timestamp | null,
|
||||||
updatedAt?: Date | null,
|
updatedAt?: Timestamp | null,
|
||||||
entries: Array<IEntry>,
|
entries: Array<IEntry>,
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user