-
-
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
5b27e21
commit d24bb4c
Showing
10 changed files
with
96 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"deno.enable": true | ||
} |
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,33 +1,9 @@ | ||
import { StorageMap } from "datex-core-legacy/datex_all.ts"; | ||
import { SharedList } from "./lists.ts"; | ||
|
||
/** | ||
* Create a new list storage map with default values. | ||
* Because this is an exported value from a ".eternal.ts" module, | ||
* the state will be saved persistently and can still be accessed after restart | ||
*/ | ||
export const listStorage = new Map<string, SharedList>([[ | ||
"jonas", | ||
{ | ||
title: "Jonas Shopping List", | ||
items: new Set([ | ||
{ | ||
name: "Milk", | ||
amount: 1, | ||
type: "Bottle", | ||
checked: false | ||
}, | ||
{ | ||
name: "Butter", | ||
amount: 4, | ||
type: "Piece", | ||
checked: false | ||
}, | ||
{ | ||
name: "Beer", | ||
amount: 2, | ||
type: "Bottle", | ||
checked: false | ||
} | ||
]) | ||
} | ||
]]); | ||
export const listStorage = new StorageMap<string, SharedList>(); |
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,73 +1,74 @@ | ||
import { ListItem, type SharedList } from "backend/lists.ts"; | ||
import { map, always } from "datex-core-legacy/functions.ts"; | ||
import { type ListItem } from "backend/lists.ts"; | ||
import { template } from "uix/html/template.ts"; | ||
import { Component } from "uix/components/Component.ts"; | ||
import type { Ref } from "datex-core-legacy/datex_all.ts"; | ||
|
||
@template(function(this: List) { | ||
const { title, items } = this.properties; | ||
return <div> | ||
<div class="header"> | ||
<h1>{this.options.$.list.$.title}</h1> | ||
<h1>{title}</h1> | ||
</div> | ||
<ol> | ||
{ | ||
map(this.options.list.items, (item, index) => { | ||
const reactiveItem = item.$ as unknown as ListItem; | ||
return <li> | ||
<input type="checkbox" checked={reactiveItem.checked} id={`checkbox-${index}`}/> | ||
<label for={`checkbox-${index}`}>{reactiveItem.name}</label> | ||
<span>{reactiveItem.amount} {reactiveItem.type}{always(()=>item.amount! > 1 ? 's': '')}</span> | ||
</li> | ||
}) | ||
items.map((item, index) => <li> | ||
<input type="checkbox" checked={item.checked} id={`checkbox-${index}`}/> | ||
<label for={`checkbox-${index}`}>{item.name}</label> | ||
<span>{item.amount} {item.type}{item.amount! > 1 ? 's': ''}</span> | ||
</li>) | ||
} | ||
</ol> | ||
<button class="add-button" onclick:frontend={() => this.dialog.showModal()}> | ||
<button class="add-button" | ||
onclick:frontend={() => this.dialog.showModal()}> | ||
Add item | ||
</button> | ||
<button class="remove-button" onclick:frontend={() => this.removeChecked()}> | ||
Cleanup | ||
</button> | ||
<dialog id="dialog" onclick:frontend={function (e) { if (e.target == this) this.close()}}> | ||
<input placeholder="Enter item name" type="text" id="name"/> | ||
<input placeholder="Enter amount" type="number" id="amount" value={1} max={99}/> | ||
<select id="type"> | ||
<option>Bottle</option> | ||
<option>Piece</option> | ||
<option>Whatever</option> | ||
<input placeholder="Enter item name" type="text" value={this.name}/> | ||
<input placeholder="Enter amount" type="number" value={this.amount} max={99}/> | ||
<select id="type" value={this.type}> | ||
<option name={"bottle"}>Bottle</option> | ||
<option name={"piece"}>Piece</option> | ||
<option name={"whatever"}>Whatever</option> | ||
</select> | ||
<div id="add" onclick:frontend={() => this.addItem()}>Add</div> | ||
<div id="add" onclick:frontend={() => this.addItem()}> | ||
Add | ||
</div> | ||
</dialog> | ||
</div> | ||
}) | ||
export class List extends Component<{list: SharedList}> { | ||
export class List extends Component<{title: string, items: ListItem[]}> { | ||
|
||
/** references to the DOM elements */ | ||
@id name!: HTMLInputElement; | ||
@id amount!: HTMLInputElement; | ||
@id type!: HTMLOptionElement; | ||
@property name = ''; | ||
@property amount = 1; | ||
@property type = 'bottle'; | ||
@id dialog!: HTMLDialogElement; | ||
|
||
/** | ||
* Remove all checked items | ||
*/ | ||
private removeChecked() { | ||
[...this.options.list.items] | ||
.filter(item => item.checked) | ||
.forEach(item => this.options.list.items.delete(item)) | ||
const items = this.properties.items; | ||
items.val = val(items).filter(e => !e.checked); | ||
globalThis.location.reload(); | ||
} | ||
|
||
/** | ||
* Add a new item to the list | ||
*/ | ||
private addItem() { | ||
if (!this.name.value) | ||
if (!this.name) | ||
return alert("Please enter a name"); | ||
|
||
this.options.list.items.add({ | ||
val(this.properties.items).push({ | ||
checked: false, | ||
name: this.name.value, | ||
amount: Number(this.amount.value), | ||
type: this.type.value, | ||
name: val(this.name), | ||
amount: val(this.amount), | ||
type: val(this.type), | ||
}); | ||
this.dialog.close() | ||
this.dialog.close(); | ||
this.name = ''; | ||
} | ||
} |
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,16 +1,16 @@ | ||
import { SharedList } from "backend/lists.ts"; | ||
import { map } from "datex-core-legacy/functions.ts"; | ||
import { template } from "uix/html/template.ts"; | ||
import { Component } from "uix/components/Component.ts"; | ||
import { StorageMap } from 'datex-core-legacy/datex_all.ts'; | ||
|
||
@template(function(this: Overview) { | ||
@template(async function(this: Overview) { | ||
return <div> | ||
<h1>Overview</h1> | ||
{ | ||
...map(this.options.lists, ([key, val]) => ( | ||
(await this.properties.lists.entriesArray()).map(([key, val]) => | ||
<a href={`/${key}`}>{val.title}</a> | ||
)) | ||
) | ||
} | ||
</div> | ||
}) | ||
export class Overview extends Component<{lists: Map<string, SharedList>}> {} | ||
export class Overview extends Component<{lists: StorageMap<string, SharedList>}> {} |
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,12 +1,14 @@ | ||
import { Lists } from "../backend/lists.ts"; | ||
import { List } from "../common/List.tsx"; | ||
import { Entrypoint } from "uix/html/entrypoints.ts"; | ||
import { lazy } from "uix/html/entrypoint-providers.tsx"; | ||
import { type Entrypoint } from "uix/providers/entrypoints.ts"; | ||
import { lazy } from "uix/providers/common.tsx"; | ||
|
||
|
||
export default { | ||
'/:id': lazy(async (_, {id}) => { | ||
return <List list={await Lists.get(id)}/> // render the list component | ||
const list = await Lists.get(id); | ||
|
||
return <List items={list.items} title={list.title}/> // render the list component | ||
}) | ||
} satisfies Entrypoint; | ||
|
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,12 +1,11 @@ | ||
{ | ||
"imports": { | ||
"datex-core-legacy": "https://cdn.unyt.org/[email protected]/datex.ts", | ||
"datex-core-legacy/": "https://cdn.unyt.org/[email protected]/", | ||
"unyt_core": "https://cdn.unyt.org/[email protected]/datex.ts", | ||
"unyt_core/": "https://cdn.unyt.org/[email protected]/", | ||
"uix": "https://cdn.unyt.org/[email protected]/uix.ts", | ||
"uix/": "https://cdn.unyt.org/[email protected]/src/", | ||
"uix/jsx-runtime": "https://cdn.unyt.org/[email protected]/src/jsx-runtime/jsx.ts", | ||
"unyt-tests/": "https://cdn.unyt.org/unyt-tests/" | ||
"datex-core-legacy": "https://cdn.unyt.org/[email protected]/datex.ts", | ||
"datex-core-legacy/": "https://cdn.unyt.org/[email protected]/", | ||
"uix": "https://cdn.unyt.org/[email protected]/uix.ts", | ||
"uix/": "https://cdn.unyt.org/[email protected]/src/", | ||
"uix/jsx-runtime": "https://cdn.unyt.org/[email protected]/src/jsx-runtime/jsx.ts", | ||
"jusix/jsx-runtime": "https://cdn.unyt.org/[email protected]/src/jsx-runtime/jsx.ts", | ||
"unyt-tests/": "https://cdn.unyt.org/unyt_tests/" | ||
} | ||
} |