Skip to content

Commit

Permalink
Remove deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
daya0576 committed Feb 5, 2025
1 parent 17cafa9 commit bb85b69
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 69 deletions.
57 changes: 2 additions & 55 deletions beaverhabits/frontend/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,6 @@ async def habit_tick(habit: Habit, day: datetime.date, value: bool):
await habit.tick(day, value)
logger.info(f"Day {day} ticked: {value}")

# Daily notes/short description
if habit.note and value:
result = await habit_tick_dialog(record)

yes, text = (False, None) if result is None else result

if text and len(text) > DAILY_NOTE_MAX_LENGTH:
ui.notify("Note is too long", color="negative")
yes = False

# Rollback if user cancel
if not yes:
await habit.tick(day, not value)
logger.info(f"Day {day} ticked: {value} (rollback)")

if yes:
await habit.tick(day, value, text)
logger.info(f"Habit ticked: {day} {value}, note: {text}")


class HabitCheckBox(ui.checkbox):
def __init__(self, habit: Habit, day: datetime.date, value: bool) -> None:
Expand Down Expand Up @@ -151,6 +132,7 @@ def _update_style(self, value: bool):
self.props("color=currentColor")

async def _mouse_down_event(self):
logger.info(f"Mouse down event: {self.day}")
self.hold.clear()
try:
async with asyncio.timeout(0.2):
Expand All @@ -166,6 +148,7 @@ async def _mouse_down_event(self):
await habit_tick(self.habit, self.day, value)

async def _mouse_up_event(self):
logger.info(f"Mouse up event: {self.day}")
self.hold.set()


Expand Down Expand Up @@ -527,42 +510,6 @@ def __init__(self, habit: Habit) -> None:
self.style("font-size: 80%; font-weight: 500")


class HabitNotesExpansion(ui.expansion):
def __init__(self, title, habit: Habit) -> None:
is_expanded = bool(habit.note)

super().__init__(
title,
icon=" ",
value=is_expanded,
on_value_change=self._async_task,
)
self.habit = habit
self.props("dense")
self.classes("w-full text-base text-center")

self.bind_value_from(self, "value")

async def _async_task(self, e: events.ValueChangeEventArguments):
if e.value == self.habit.note:
return
if not await self.confirm_dialog():
self.value = self.habit.note
return

self.habit.note = e.value
logger.info(f"Habit Note changed to {e.value}")

def confirm_dialog(self):
msg = "enable" if not self.habit.note else "disable"
with ui.dialog() as dialog, ui.card():
ui.label(f"Are you sure to {msg} notes?")
with ui.row():
ui.button("Yes", on_click=lambda: dialog.submit(True))
ui.button("No", on_click=lambda: dialog.submit(False))
return dialog


def habit_notes(records: List[CheckedRecord], limit: int = 10):
with ui.timeline(side="right").classes("w-full pt-5 px-3 whitespace-pre-line"):
for record in records[:limit]:
Expand Down
8 changes: 0 additions & 8 deletions beaverhabits/storage/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ def status(self, value: HabitStatus) -> None:
def records(self) -> list[DictRecord]:
return [DictRecord(d) for d in self.data["records"]]

@property
def note(self) -> bool:
return bool(self.data.get("note"))

@note.setter
def note(self, value: bool) -> None:
self.data["note"] = value

@property
def ticked_days(self) -> list[datetime.date]:
return self.cache.ticked_days
Expand Down
6 changes: 0 additions & 6 deletions beaverhabits/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ def status(self) -> HabitStatus: ...
@status.setter
def status(self, value: HabitStatus) -> None: ...

@property
def note(self) -> bool: ...

@note.setter
def note(self, value: bool) -> None: ...

@property
def ticked_days(self) -> list[datetime.date]: ...

Expand Down

0 comments on commit bb85b69

Please sign in to comment.