Compare commits

..

2 commits

Author SHA1 Message Date
020f3cbd74
support months split type + fix requireloggedin bug 2023-11-01 21:28:48 +00:00
48964d27e4
hide duplicate button 2023-11-01 21:18:08 +00:00
3 changed files with 38 additions and 18 deletions

View file

@ -33,16 +33,17 @@
You have no lists yet! <Link to="/lists/create" class="text-blue-400" You have no lists yet! <Link to="/lists/create" class="text-blue-400"
>Create one now</Link >Create one now</Link
> >
{:else}
{#each lists.teams as list}
<Link class="text-blue-400" to="/list/{list['$id']}"
>{list["name"]}</Link
><br />
{/each}
<Link
class="text-blue-400 dark:bg-gray-600 bg-gray-400 border p-1 mt-4 rounded"
to="/lists/create">Create new list</Link
>
{/if} {/if}
{#each lists.teams as list}
<Link class="text-blue-400" to="/list/{list['$id']}"
>{list["name"]}</Link
><br />
{/each}
<Link
class="text-blue-400 dark:bg-gray-600 bg-gray-400 border p-1 mt-4 rounded"
to="/lists/create">Create new list</Link
>
{/await} {/await}
</div> </div>
</main> </main>

View file

@ -15,6 +15,7 @@
let listname = ""; let listname = "";
let requireLoggedIn = false; let requireLoggedIn = false;
let list_type = "";
function createList(e) { function createList(e) {
e.preventDefault(); e.preventDefault();
@ -22,8 +23,9 @@
database database
.createDocument("tehillim-split", "lists", ID.unique(), { .createDocument("tehillim-split", "lists", ID.unique(), {
title: listname, title: listname,
require_logged_in: requireLoggedIn, require_logged_in: !!requireLoggedIn,
owner_id: loggedInUser["$id"], owner_id: loggedInUser["$id"],
list_type: list_type
}) })
.then((r) => { .then((r) => {
teams.create(r["$id"], listname, ["owner"]).then((r) => { teams.create(r["$id"], listname, ["owner"]).then((r) => {
@ -66,13 +68,24 @@
<legend class="text-2xl">Create new list</legend> <legend class="text-2xl">Create new list</legend>
<input <input
class="dark:bg-gray-500 dark:placeholder-white border border-black dark:border-current rounded p-1" class="dark:bg-gray-500 dark:placeholder-white border border-black dark:border-current rounded p-2 w-72"
type="text" type="text"
placeholder="List name" placeholder="List name"
bind:value={listname} bind:value={listname}
required required
/> <br /> /> <br />
<select
class="dark:bg-gray-500 dark:placeholder-white border border-black dark:border-current rounded p-2 mt-2 w-72"
placeholder="Split Tehillim by"
bind:value={list_type}
required
>
<option value="" selected disabled>Split Tehillim by</option>
<option value="perakim">Perakim</option>
<option value="month">Days of the month</option>
</select> <br />
<input <input
class="w-5 h-5 border-solid border-white my-3" class="w-5 h-5 border-solid border-white my-3"
name="requireLoggedIn" name="requireLoggedIn"

View file

@ -7,7 +7,14 @@
export let id; export let id;
let elementsNumbers = 0;
let list = database.getDocument("tehillim-split", "lists", id); let list = database.getDocument("tehillim-split", "lists", id);
list.then((r) => {
if (r.list_type == "perakim") elementsNumbers = 151;
if (r.list_type == "month") elementsNumbers = 31;
});
let perakim = []; let perakim = [];
let perakimPromise = database let perakimPromise = database
.listDocuments("tehillim-split", "perakim", [Query.equal("list_id", [id])]) .listDocuments("tehillim-split", "perakim", [Query.equal("list_id", [id])])
@ -142,6 +149,7 @@
Loading... Loading...
{:then list} {:then list}
<h1 class="text-2xl">List {list.title}</h1> <h1 class="text-2xl">List {list.title}</h1>
<p>List split by {list.list_type=="perakim"?"perek":""}{list.list_type=="month"?"days of month":""}</p>
<br /> <br />
<Link class="text-blue-400" to="/list/{id}/members">Members</Link> <Link class="text-blue-400" to="/list/{id}/members">Members</Link>
{#await teamDetails then team} {#await teamDetails then team}
@ -155,17 +163,17 @@
{/if} {/if}
{/await}<br /> {/await}<br />
{#await perakimPromise then perakimResolved} {#await perakimPromise then perakimResolved}
{#each Array.from(Array(150 + 1).keys()).slice(1) as i} {#each Array.from(Array(elementsNumbers).keys()).slice(1) as i}
{list.list_type == "perakim" ? "Perek " + i : ""}
{list.list_type == "month" ? "Day " + i : ""}
{#if perekIndex(i) !== -1} {#if perekIndex(i) !== -1}
{#if perakim[perekIndex(i)].taken == false} {#if perakim[perekIndex(i)].taken == false}
Perek {i}
<button <button
on:click={() => takePerek(i)} on:click={() => takePerek(i)}
class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded" class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded"
>Take</button >Take</button
> >
{:else if perakim[perekIndex(i)].taken_by == loggedInUser["$id"] && perakim[perekIndex(i)].completed !== true} {:else if perakim[perekIndex(i)].taken_by == loggedInUser["$id"] && perakim[perekIndex(i)].completed !== true}
Perek {i}
<button <button
on:click={() => untakePerek(i)} on:click={() => untakePerek(i)}
class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded" class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded"
@ -177,19 +185,17 @@
>Complete</button >Complete</button
> >
{:else if perakim[perekIndex(i)].taken_by == loggedInUser["$id"] && perakim[perekIndex(i)].completed == true} {:else if perakim[perekIndex(i)].taken_by == loggedInUser["$id"] && perakim[perekIndex(i)].completed == true}
Perek {i}
<button <button
on:click={() => uncompletePerek(i)} on:click={() => uncompletePerek(i)}
class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded" class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded"
>Uncomplete</button >Uncomplete</button
> >
{:else if perakim[perekIndex(i)].completed == false} {:else if perakim[perekIndex(i)].completed == false}
Perek {i} - Taken by {perakim[perekIndex(i)].taken_by_name} - Taken by {perakim[perekIndex(i)].taken_by_name}
{:else} {:else}
Perek {i} - Completed by {perakim[perekIndex(i)].taken_by_name} - Completed by {perakim[perekIndex(i)].taken_by_name}
{/if} {/if}
{:else} {:else}
Perek {i}
<button <button
on:click={() => takeNewPerek(i)} on:click={() => takeNewPerek(i)}
class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded" class="dark:bg-gray-600 bg-gray-400 border p-1 mt-2 rounded"