Skip to content

Commit 8138d94

Browse files
committed
Rewrite done
1 parent 021f73d commit 8138d94

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
elixir 1.19.5-otp-28
2-
erlang 28.3.2
2+
erlang 28.1.1

tania_core/lib/tania_core_web/live/area_live/index.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule TaniaCoreWeb.AreaLive.Index do
1818
|> assign(:active_page, :areas)
1919
|> assign(:farm, farm)
2020
|> assign(:reservoirs, reservoirs)
21+
|> assign(:areas_count, length(areas))
2122
|> stream(:areas, areas)
2223
|> assign(:area, nil)
2324
|> assign(:show_form, false)}
@@ -83,6 +84,7 @@ defmodule TaniaCoreWeb.AreaLive.Index do
8384
{:noreply,
8485
socket
8586
|> stream_delete(:areas, area)
87+
|> update(:areas_count, &(&1 - 1))
8688
|> put_flash(:info, "Area deleted")}
8789

8890
{:error, _} ->
@@ -101,6 +103,7 @@ defmodule TaniaCoreWeb.AreaLive.Index do
101103
{:noreply,
102104
socket
103105
|> stream_insert(:areas, area)
106+
|> update(:areas_count, &(&1 + 1))
104107
|> assign(:show_form, false)
105108
|> put_flash(:info, "Area created")}
106109

@@ -141,7 +144,7 @@ defmodule TaniaCoreWeb.AreaLive.Index do
141144
</.header>
142145
143146
<div
144-
:if={@streams.areas |> Enum.any?()}
147+
:if={@areas_count > 0}
145148
class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 mt-6"
146149
>
147150
<div
@@ -181,7 +184,7 @@ defmodule TaniaCoreWeb.AreaLive.Index do
181184
</div>
182185
183186
<.empty_state
184-
:if={!(@streams.areas |> Enum.any?())}
187+
:if={@areas_count == 0}
185188
icon="hero-map"
186189
message={gettext("No areas yet. Create your first area to get started.")}
187190
>

tania_core/lib/tania_core_web/live/crop_live/index.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ defmodule TaniaCoreWeb.CropLive.Index do
2323
|> assign(:areas, areas)
2424
|> assign(:materials, materials)
2525
|> assign(:tab, "active")
26+
|> assign(:crops_count, length(crops))
2627
|> stream(:crops, crops)
2728
|> assign(:crop, nil)
2829
|> assign(:show_form, false)}
@@ -38,6 +39,7 @@ defmodule TaniaCoreWeb.CropLive.Index do
3839
{:noreply,
3940
socket
4041
|> assign(:tab, tab)
42+
|> assign(:crops_count, length(crops))
4143
|> stream(:crops, crops, reset: true)}
4244
end
4345

@@ -73,6 +75,7 @@ defmodule TaniaCoreWeb.CropLive.Index do
7375
{:noreply,
7476
socket
7577
|> stream_insert(:crops, crop)
78+
|> update(:crops_count, &(&1 + 1))
7679
|> assign(:show_form, false)
7780
|> put_flash(:info, "Crop batch created")}
7881

@@ -90,6 +93,7 @@ defmodule TaniaCoreWeb.CropLive.Index do
9093
{:noreply,
9194
socket
9295
|> stream_delete(:crops, crop)
96+
|> update(:crops_count, &(&1 - 1))
9397
|> put_flash(:info, "Crop deleted")}
9498

9599
{:error, _} ->
@@ -123,7 +127,7 @@ defmodule TaniaCoreWeb.CropLive.Index do
123127
124128
<div class="mt-6">
125129
<.table
126-
:if={@streams.crops |> Enum.any?()}
130+
:if={@crops_count > 0}
127131
id="crops"
128132
rows={@streams.crops}
129133
row_click={fn {_id, crop} -> JS.navigate("/crops/#{crop.id}") end}
@@ -162,7 +166,7 @@ defmodule TaniaCoreWeb.CropLive.Index do
162166
</.table>
163167
164168
<.empty_state
165-
:if={!(@streams.crops |> Enum.any?())}
169+
:if={@crops_count == 0}
166170
icon="hero-squares-2x2"
167171
message={
168172
if @tab == "active",

tania_core/lib/tania_core_web/live/material_live/index.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule TaniaCoreWeb.MaterialLive.Index do
1717
|> assign(:page_title, "Materials")
1818
|> assign(:active_page, :materials)
1919
|> assign(:farm, farm)
20+
|> assign(:materials_count, length(materials))
2021
|> stream(:materials, materials)
2122
|> assign(:material, nil)
2223
|> assign(:show_form, false)
@@ -83,6 +84,7 @@ defmodule TaniaCoreWeb.MaterialLive.Index do
8384
{:noreply,
8485
socket
8586
|> stream_delete(:materials, material)
87+
|> update(:materials_count, &(&1 - 1))
8688
|> put_flash(:info, "Material deleted")}
8789

8890
{:error, _} ->
@@ -99,6 +101,7 @@ defmodule TaniaCoreWeb.MaterialLive.Index do
99101
{:noreply,
100102
socket
101103
|> stream_insert(:materials, material)
104+
|> update(:materials_count, &(&1 + 1))
102105
|> assign(:show_form, false)
103106
|> put_flash(:info, "Material created")}
104107

@@ -163,7 +166,7 @@ defmodule TaniaCoreWeb.MaterialLive.Index do
163166
164167
<div class="mt-6">
165168
<.table
166-
:if={@streams.materials |> Enum.any?()}
169+
:if={@materials_count > 0}
167170
id="materials"
168171
rows={@streams.materials}
169172
>
@@ -192,7 +195,7 @@ defmodule TaniaCoreWeb.MaterialLive.Index do
192195
</.table>
193196
194197
<.empty_state
195-
:if={!(@streams.materials |> Enum.any?())}
198+
:if={@materials_count == 0}
196199
icon="hero-archive-box"
197200
message={gettext("No materials yet. Add seeds, chemicals, or other supplies.")}
198201
>

tania_core/lib/tania_core_web/live/reservoir_live/index.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule TaniaCoreWeb.ReservoirLive.Index do
1616
|> assign(:page_title, "Reservoirs")
1717
|> assign(:active_page, :reservoirs)
1818
|> assign(:farm, farm)
19+
|> assign(:reservoirs_count, length(reservoirs))
1920
|> stream(:reservoirs, reservoirs)
2021
|> assign(:reservoir, nil)
2122
|> assign(:show_form, false)}
@@ -66,6 +67,7 @@ defmodule TaniaCoreWeb.ReservoirLive.Index do
6667
{:noreply,
6768
socket
6869
|> stream_delete(:reservoirs, reservoir)
70+
|> update(:reservoirs_count, &(&1 - 1))
6971
|> put_flash(:info, "Reservoir deleted")}
7072

7173
{:error, _} ->
@@ -82,6 +84,7 @@ defmodule TaniaCoreWeb.ReservoirLive.Index do
8284
{:noreply,
8385
socket
8486
|> stream_insert(:reservoirs, reservoir)
87+
|> update(:reservoirs_count, &(&1 + 1))
8588
|> assign(:show_form, false)
8689
|> put_flash(:info, "Reservoir created")}
8790

@@ -121,7 +124,7 @@ defmodule TaniaCoreWeb.ReservoirLive.Index do
121124
122125
<div class="mt-6">
123126
<.table
124-
:if={@streams.reservoirs |> Enum.any?()}
127+
:if={@reservoirs_count > 0}
125128
id="reservoirs"
126129
rows={@streams.reservoirs}
127130
>
@@ -147,7 +150,7 @@ defmodule TaniaCoreWeb.ReservoirLive.Index do
147150
</.table>
148151
149152
<.empty_state
150-
:if={!(@streams.reservoirs |> Enum.any?())}
153+
:if={@reservoirs_count == 0}
151154
icon="hero-beaker"
152155
message={gettext("No reservoirs yet. Create your first water source.")}
153156
>

tania_core/lib/tania_core_web/live/task_live/index.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule TaniaCoreWeb.TaskLive.Index do
1818
|> assign(:active_page, :tasks)
1919
|> assign(:farm, farm)
2020
|> assign(:filter, "all")
21+
|> assign(:tasks_count, length(tasks))
2122
|> stream(:tasks, tasks)
2223
|> assign(:task, nil)
2324
|> assign(:show_form, false)}
@@ -45,6 +46,7 @@ defmodule TaniaCoreWeb.TaskLive.Index do
4546
{:noreply,
4647
socket
4748
|> assign(:filter, filter)
49+
|> assign(:tasks_count, length(tasks))
4850
|> stream(:tasks, tasks, reset: true)}
4951
end
5052

@@ -75,6 +77,7 @@ defmodule TaniaCoreWeb.TaskLive.Index do
7577
{:noreply,
7678
socket
7779
|> stream_insert(:tasks, task)
80+
|> update(:tasks_count, &(&1 + 1))
7881
|> assign(:show_form, false)
7982
|> put_flash(:info, "Task created")}
8083

@@ -124,6 +127,7 @@ defmodule TaniaCoreWeb.TaskLive.Index do
124127
{:noreply,
125128
socket
126129
|> stream_delete(:tasks, task)
130+
|> update(:tasks_count, &(&1 - 1))
127131
|> put_flash(:info, "Task deleted")}
128132

129133
{:error, _} ->
@@ -210,7 +214,7 @@ defmodule TaniaCoreWeb.TaskLive.Index do
210214
211215
<%!-- Task list --%>
212216
<div class="flex-1 min-w-0">
213-
<div :if={@streams.tasks |> Enum.any?()} class="space-y-3">
217+
<div :if={@tasks_count > 0} class="space-y-3">
214218
<div
215219
:for={{dom_id, task} <- @streams.tasks}
216220
id={dom_id}
@@ -272,7 +276,7 @@ defmodule TaniaCoreWeb.TaskLive.Index do
272276
</div>
273277
274278
<.empty_state
275-
:if={!(@streams.tasks |> Enum.any?())}
279+
:if={@tasks_count == 0}
276280
icon="hero-clipboard-document-list"
277281
message={gettext("No tasks found.")}
278282
>

0 commit comments

Comments
 (0)