-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87fc100
commit 3f691d3
Showing
4 changed files
with
147 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,49 @@ | ||
import { property, state } from "lit/decorators.js"; | ||
import { ScopedRegistryHost } from "@lit-labs/scoped-registry-mixin"; | ||
import { LitElement, css, html } from "lit"; | ||
import { property } from "lit/decorators.js"; | ||
import { html } from "lit"; | ||
import { TaskItem } from "./task-item"; | ||
import { TodoStore } from "../todo-store"; | ||
import { get } from "svelte/store"; | ||
import { List } from '@scoped-elements/material-web' | ||
import { SensemakerStore } from "@neighbourhoods/client"; | ||
import { SensemakeResource } from "./sensemaker/sensemake-resource"; | ||
import { StoreSubscriber } from "lit-svelte-stores"; | ||
import {repeat} from 'lit/directives/repeat.js'; | ||
import { variables } from "../styles/variables"; | ||
import { getHashesFromResourceDefNames } from "../utils"; | ||
import { decodeHashFromBase64 } from "@holochain/client"; | ||
import { NHComponent } from "@neighbourhoods/design-system-components"; | ||
|
||
// add item at the bottom | ||
export class TaskList extends ScopedRegistryHost(LitElement) { | ||
export class TaskList extends NHComponent { | ||
@property() todoStore!: TodoStore | ||
@property() sensemakerStore!: SensemakerStore | ||
@property() listName: string | undefined | ||
|
||
@property() | ||
public todoStore!: TodoStore | ||
|
||
@property() | ||
public sensemakerStore!: SensemakerStore | ||
|
||
@property() | ||
listName: string | undefined | ||
|
||
@state() | ||
tasks = html`` | ||
|
||
/** | ||
* component subscribers | ||
*/ | ||
listTasks = new StoreSubscriber(this, () => this.todoStore.getTasks(this.listName!)); | ||
// not sure if I can use a reactive value in the subscriber callback | ||
// listTasksAssessments = new StoreSubscriber(this, () => this.sensemakerStore.resourceAssessments(this.listTasks.value.map((task) => encodeHashToBase64(task.entry_hash)))); | ||
listTasks = new StoreSubscriber(this as any, () => this.todoStore.getTasks(this.listName!)); | ||
|
||
render() { | ||
this.updateTaskList() | ||
|
||
if (this.listName) { | ||
return html` | ||
<div class="task-list-container"> | ||
<mwc-list> | ||
${this.tasks} | ||
</mwc-list> | ||
<div class="task-list-container" style="display: flex; flex-direction: column; gap: 8px; margin-top: 8px;"> | ||
${this.renderTaskList()} | ||
</div> | ||
` | ||
} | ||
else { | ||
return html` | ||
<div>select a list!</div> | ||
` | ||
} | ||
} | ||
// TODO: update this function name to be more descriptive/accurate | ||
updateTaskList() { | ||
|
||
renderTaskList() { | ||
if (this.listName) { | ||
const tasks = this.listTasks.value; | ||
console.log('tasks subscribed', tasks) | ||
this.tasks = html` | ||
${tasks.length > 0 ? repeat(tasks, (task) => task.entry_hash, (task, index) => { | ||
return html` | ||
<sensemake-resource | ||
.resourceEh=${task.entry_hash} | ||
.resourceDefEh=${decodeHashFromBase64(getHashesFromResourceDefNames(["task_item"], get(this.sensemakerStore.resourceDefinitions))[0])} | ||
> | ||
<task-item | ||
.task=${task} | ||
.todoStore=${this.todoStore} | ||
.completed=${('Complete' in task.entry.status)} | ||
@task-toggle=${() => this.todoStore.toggleTaskStatus(task)} | ||
></task-item> | ||
</sensemake-resource> | ||
`}) : html``} | ||
|
||
return html` | ||
${tasks.length > 0 ? repeat(tasks, (task) => task.entry_hash, (task, _idx) => { | ||
return html` | ||
<task-item | ||
.task=${task} | ||
.todoStore=${this.todoStore} | ||
.completed=${('Complete' in task.entry.status)} | ||
@task-toggle=${() => this.todoStore.toggleTaskStatus(task)} | ||
></task-item> | ||
` | ||
}) : null} | ||
` | ||
} | ||
} | ||
static get styles() { | ||
return [ | ||
variables, | ||
css` | ||
mwc-list { | ||
position: relative; | ||
} | ||
add-item { | ||
} | ||
task-list-container { | ||
height: 100vh; | ||
} | ||
`] | ||
} | ||
static get elementDefinitions() { | ||
return { | ||
|
||
static elementDefinitions = { | ||
'task-item': TaskItem, | ||
'mwc-list': List, | ||
'sensemake-resource': SensemakeResource, | ||
}; | ||
} | ||
}; | ||
} |
Oops, something went wrong.