Skip to main content

max / makenotwork

5.2 KB · 118 lines History Blame Raw
1 <div class="content-section">
2 <p class="form-hint mb-5">Curate lists of items — playlists, reading lists, bundles. Public collections appear on your profile.</p>
3
4 {% if collections.is_empty() %}
5 <p class="muted">No collections yet. Use the form below to create your first one, then add items from any item page.</p>
6 {% else %}
7 <div class="scroll-x">
8 <table class="data-table">
9 <thead>
10 <tr>
11 <th>Title</th>
12 <th>Items</th>
13 <th>Visibility</th>
14 <th>Created</th>
15 <th></th>
16 </tr>
17 </thead>
18 <tbody>
19 {% for c in collections %}
20 <tr>
21 <td><a href="/c/{{ username }}/{{ c.slug }}">{{ c.title }}</a></td>
22 <td>{{ c.item_count }}</td>
23 <td>{% if c.is_public %}<span class="badge">Public</span>{% else %}<span class="badge is-faded">Private</span>{% endif %}</td>
24 <td>{{ c.created_at }}</td>
25 <td>
26 <button class="btn-secondary small btn-compact"
27 hx-delete="/api/collections/{{ c.id }}"
28 hx-confirm="Delete this collection?"
29 hx-target="closest tr"
30 hx-swap="outerHTML">Delete</button>
31 </td>
32 </tr>
33 {% endfor %}
34 </tbody>
35 </table>
36 </div>
37 {% endif %}
38
39 <details class="lib-coll-new">
40 <summary class="lib-coll-new-summary">New Collection</summary>
41 <form id="new-collection-form"
42 class="lib-coll-new-form"
43 hx-post="/api/collections"
44 hx-swap="none">
45 <div class="form-group">
46 <label for="new-coll-title">Title</label>
47 <input type="text" id="new-coll-title" name="title" maxlength="100" required placeholder="My Reading List"
48 oninput="document.getElementById('new-coll-slug').value = this.value.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')">
49 </div>
50 <div class="form-group">
51 <label for="new-coll-slug">URL name</label>
52 <input type="text" id="new-coll-slug" name="slug" maxlength="100" required placeholder="my-reading-list" pattern="[a-zA-Z0-9\-]+">
53 <small class="form-hint">Letters, numbers, and hyphens only. Filled in for you from the title; edit if you want a shorter URL.</small>
54 </div>
55 <div class="form-group">
56 <label for="new-coll-desc">Description (optional)</label>
57 <textarea id="new-coll-desc" name="description" maxlength="500" rows="2"></textarea>
58 </div>
59 <label class="checkbox-group">
60 <input type="checkbox" id="new-coll-public" name="is_public" value="true"> Public (visible on your profile)
61 </label>
62 <button type="submit">Create Collection</button>
63 </form>
64 </details>
65 </div>
66
67 <script>
68 document.getElementById('new-collection-form').addEventListener('htmx:afterOnLoad', function(evt) {
69 if (evt.detail.xhr.status >= 200 && evt.detail.xhr.status < 300) {
70 htmx.ajax('GET', '/library/tabs/collections', { target: '#tab-content', swap: 'innerHTML' });
71 }
72 });
73 </script>
74
75 <h2 class="lib-coll-wishlist-heading">Wishlist</h2>
76 {% if wishlists.is_empty() %}
77 <div class="content-section">
78 <p class="muted">No wishlisted items. Add items from any item page to save them for later.</p>
79 </div>
80 {% else %}
81 <div class="content-section lib-coll-wishlist-wrap">
82 <table class="data-table lib-coll-wishlist-table">
83 <thead>
84 <tr>
85 <th>Title</th>
86 <th>Creator</th>
87 <th>Type</th>
88 <th>Price</th>
89 <th>Added</th>
90 <th></th>
91 </tr>
92 </thead>
93 <tbody>
94 {% for item in wishlists %}
95 <tr id="wishlist-row-{{ item.item_id }}">
96 <td><a href="/i/{{ item.item_id }}">{{ item.title }}</a></td>
97 <td><a href="/u/{{ item.creator }}">{{ item.creator }}</a></td>
98 <td><span class="badge">{{ item.item_type }}</span></td>
99 <td>{{ item.price_display() }}</td>
100 <td>{{ item.added_at.format("%b %d, %Y") }}</td>
101 <td class="lib-coll-row-actions">
102 <button class="btn-primary small btn-compact lib-coll-cart-btn"
103 hx-post="/api/cart/{{ item.item_id }}"
104 hx-swap="none"
105 hx-on::after-request="if(event.detail.successful){this.textContent='Added';this.disabled=true}">Add to Cart</button>
106 <button class="btn-secondary small btn-compact"
107 hx-post="/api/wishlists/{{ item.item_id }}"
108 hx-target="#wishlist-row-{{ item.item_id }}"
109 hx-swap="outerHTML swap:0.2s"
110 hx-confirm="Remove from wishlist?">Remove</button>
111 </td>
112 </tr>
113 {% endfor %}
114 </tbody>
115 </table>
116 </div>
117 {% endif %}
118