Skip to content
Snippets Groups Projects

Refactor Cart into checkerboard table

Merged Mateusz Kudela requested to merge mkudela/issue-173 into develop
1 file
+ 18
2
Compare changes
  • Side-by-side
  • Inline
@@ -26,6 +26,7 @@ from clive.__private.ui.widgets.scrolling import ScrollablePart
if TYPE_CHECKING:
from textual.app import ComposeResult
from textual.widget import Widget
from clive.models import Operation
@@ -65,7+66,7 @@
super().__init__()
class Move(Message):
def __init__(self, from_idx: int, to_idx: int) -> None:
self.from_idx = from_idx
self.to_idx = to_idx
super().__init__()
@@ -221,7+222,7 @@
row.reactive_idx = row.idx - 1
self._cart_table.set_evenness_styles(rows, starting_index=start_index)
def _update_values_of_swapped_rows(self, from_index: int, to_index: int) -> None:
def get_cells_with_values(row_index: int) -> tuple[list[CliveCheckerBoardTableCell], list[str | Widget]]:
row = self.query(CartItem)[row_index]
start_index = 1 # exclude value of first cell - index
end_index = -1 # exclude value of last cell - horizontal with buttons
cells = row.query(CliveCheckerBoardTableCell)[start_index:end_index]
data = [cell.content for cell in cells]
return cells, data
from_cells, from_data = get_cells_with_values(from_index)
to_cells, to_data = get_cells_with_values(to_index)
for cells, data in [(to_cells, from_data), (from_cells, to_data)]:
for cell, value in zip(cells, data):
cell.update_content(value) # type: ignore[arg-type]
@on(CartItem.Delete)
async def remove_item(self, event: CartItem.Delete) -> None:
self.app.world.profile_data.cart.remove(event.widget.operation)
@@ -242,8 +259,7 @@ class Cart(BaseScreen):
self.app.world.profile_data.cart.swap(event.from_idx, event.to_idx)
self.app.trigger_profile_data_watchers()
start, end = (event.from_idx, event.to_idx) if event.from_idx < event.to_idx else (event.to_idx, event.from_idx)
await self.__rebuild_items(from_index=start, to_index=end)
self._update_values_of_swapped_rows(from_index=event.from_idx, to_index=event.to_idx)
# focus item that was moved
for cart_item in self.query(CartItem):
Loading