summaryrefslogtreecommitdiff
path: root/web/templates/partials/shopping-tab.html
blob: e3742d95527f0b64e38522625219f9305adfa108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{{define "shopping-tab"}}
<div class="space-y-6 text-shadow-sm" id="shopping-tab-container"
     hx-get="/tabs/shopping"
     hx-trigger="refresh-tasks from:body"
     hx-target="#tab-content"
     hx-swap="innerHTML">

    <!-- Header with View Toggle -->
    <div class="flex items-center justify-between">
        <h2 class="text-lg font-medium text-white/80">Shopping List</h2>
        <div class="flex gap-2">
            <button hx-get="/tabs/shopping?grouped=true"
                    hx-target="#tab-content"
                    hx-swap="innerHTML"
                    class="px-3 py-1.5 rounded-lg text-sm transition-colors {{if .Grouped}}bg-white/20 text-white{{else}}bg-white/5 text-white/50 hover:bg-white/10{{end}}">
                Grouped
            </button>
            <button hx-get="/tabs/shopping?grouped=false"
                    hx-target="#tab-content"
                    hx-swap="innerHTML"
                    class="px-3 py-1.5 rounded-lg text-sm transition-colors {{if not .Grouped}}bg-white/20 text-white{{else}}bg-white/5 text-white/50 hover:bg-white/10{{end}}">
                Flat
            </button>
        </div>
    </div>

    <!-- Quick Add Form -->
    <form id="shopping-quick-add"
          hx-post="/shopping/add"
          hx-target="#shopping-items-list"
          hx-swap="innerHTML scroll:#shopping-quick-add:top"
          hx-indicator="#shopping-add-indicator"
          class="bg-panel backdrop-blur-sm rounded-xl p-4 sm:p-5">
        <input type="hidden" name="grouped" value="{{.Grouped}}">
        <div class="flex gap-2">
            <input type="text" name="name" placeholder="Add item..."
                   class="flex-1 bg-white/10 border border-white/20 rounded-lg px-3 py-2 text-white placeholder-white/40 focus:outline-none focus:ring-2 focus:ring-white/30 text-sm"
                   required autocomplete="off">
            <select name="store" class="bg-white/10 border border-white/20 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:ring-2 focus:ring-white/30" required>
                {{range .Stores}}
                <option value="{{.Name}}">{{.Name}}</option>
                {{end}}
            </select>
            <button type="submit" class="bg-white/20 hover:bg-white/30 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors">
                <span id="shopping-add-indicator" class="htmx-indicator">...</span>
                <span class="htmx-hide-indicator">Add</span>
            </button>
        </div>
    </form>

    <!-- Items List Container -->
    <div id="shopping-items-list">
        {{template "shopping-items-content" .}}
    </div>

    <script>
    (function() {
        document.body.addEventListener('htmx:afterRequest', function(evt) {
            if (evt.detail.elt.id === 'shopping-quick-add' && evt.detail.successful) {
                var form = evt.detail.elt;
                var input = form.querySelector('input[name="name"]');
                if (input) {
                    input.value = '';
                    input.focus();
                }
                form.classList.add('flash-success');
                setTimeout(function() { form.classList.remove('flash-success'); }, 300);
            }
            // Handle inline add forms
            if (evt.detail.elt.classList.contains('inline-add-form') && evt.detail.successful) {
                var form = evt.detail.elt;
                var input = form.querySelector('input[name="name"]');
                if (input) {
                    input.value = '';
                    input.focus();
                }
            }
        });
    })();
    </script>
    <style>
        .flash-success { background: rgba(34, 197, 94, 0.2) !important; transition: background 0.3s; }
        .htmx-indicator { display: none; }
        .htmx-request .htmx-indicator { display: inline; }
        .htmx-request .htmx-hide-indicator { display: none; }
    </style>
</div>
{{end}}

{{define "shopping-items-content"}}
    {{if .Stores}}
    {{if .Grouped}}
    <!-- Grouped View: Items by Store -->
    {{range .Stores}}
    <section class="bg-panel backdrop-blur-sm rounded-xl p-4 sm:p-5 mb-6">
        <div class="flex items-center justify-between mb-4">
            <h2 class="text-xl font-medium text-white">{{.Name}}</h2>
            <a href="/shopping/mode/{{.Name}}"
               class="px-3 py-1.5 bg-white/10 hover:bg-white/20 rounded-lg text-sm text-white/70 hover:text-white transition-colors flex items-center gap-1.5">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3h2l.4 2M7 13h10l4-8H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"></path>
                </svg>
                Shop
            </a>
        </div>
        {{range .Categories}}
        <div class="mb-4 last:mb-0">
            {{if .Name}}<h3 class="text-sm text-white/60 mb-2 uppercase tracking-wide">{{.Name}}</h3>{{end}}
            <ul class="space-y-2">
                {{range .Items}}
                {{if not .Checked}}
                <li class="flex items-center gap-3 p-3 bg-card bg-card-hover transition-colors rounded-lg border border-white/5">
                    <span class="flex-1 text-white">{{.Name}}</span>
                    {{if .Quantity}}<span class="text-white/50 text-sm">{{.Quantity}}</span>{{end}}
                    <span class="text-xs px-2 py-0.5 rounded {{if eq .Source "trello"}}bg-blue-900/50 text-blue-300{{else if eq .Source "user"}}bg-purple-900/50 text-purple-300{{else}}bg-green-900/50 text-green-300{{end}}">
                        {{.Source}}
                    </span>
                </li>
                {{end}}
                {{end}}
            </ul>
        </div>
        {{end}}
        <!-- Inline Add Item -->
        <form class="inline-add-form mt-3 flex gap-2"
              hx-post="/shopping/add"
              hx-target="#shopping-items-list"
              hx-swap="innerHTML">
            <input type="hidden" name="store" value="{{.Name}}">
            <input type="hidden" name="grouped" value="true">
            <input type="text" name="name" placeholder="Add to {{.Name}}..."
                   class="flex-1 bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white placeholder-white/30 focus:outline-none focus:ring-1 focus:ring-white/20 text-sm"
                   required autocomplete="off">
            <button type="submit" class="bg-white/10 hover:bg-white/20 text-white/70 hover:text-white px-3 py-2 rounded-lg text-sm transition-colors">
                +
            </button>
        </form>
    </section>
    {{end}}
    {{else}}
    <!-- Flat View: All Items in One List -->
    <section class="bg-panel backdrop-blur-sm rounded-xl p-4 sm:p-5">
        <ul class="space-y-2">
            {{range .Stores}}
            {{range .Categories}}
            {{range .Items}}
            {{if not .Checked}}
            <li class="flex items-center gap-3 p-3 bg-card bg-card-hover transition-colors rounded-lg border border-white/5">
                <span class="flex-1 text-white">{{.Name}}</span>
                {{if .Quantity}}<span class="text-white/50 text-sm">{{.Quantity}}</span>{{end}}
                <span class="text-xs px-2 py-0.5 rounded bg-white/10 text-white/50">
                    {{.Store}}
                </span>
                <span class="text-xs px-2 py-0.5 rounded {{if eq .Source "trello"}}bg-blue-900/50 text-blue-300{{else if eq .Source "user"}}bg-purple-900/50 text-purple-300{{else}}bg-green-900/50 text-green-300{{end}}">
                    {{.Source}}
                </span>
            </li>
            {{end}}
            {{end}}
            {{end}}
            {{end}}
        </ul>
    </section>
    {{end}}
    {{else}}
    <div class="text-center py-16 text-white/50">
        <p class="text-lg mb-2">No shopping items</p>
        <p class="text-sm">Use the form above to add items quickly</p>
    </div>
    {{end}}
{{end}}