Compare commits

..

No commits in common. "35f37f592684eaff29f974d172be4d04b9d9688e" and "7dbb89b6924000a9adf3c5ab45b8d745288ea71a" have entirely different histories.

2 changed files with 24 additions and 38 deletions

View File

@ -206,17 +206,29 @@ class DiaryListScreen(Screen):
"""Action to create new diary"""
self.app.push_screen(NewDiaryModal(),self._on_new_diary_submitted)
def _on_new_diary_submitted(self, result):
"""Callback after diary creation"""
if result: # Se result não é string vazia, o diário foi criado
self.notify(f"Returning to diary list...")
# Atualiza a lista de diários
self.refresh_diaries()
def _on_new_diary_submitted(self,result):
self.notify(str(result))
if result:
self.notify(f"Creating Diary:{result}'...")
self.call_later(self._async_create_diary,result)
else:
self.notify(f"Creation canceled...")
self.notify(f"Canceled...")
async def _async_create_diary(self,name: str):
try:
service = self.app.service_manager.get_travel_diary_service()
created_diary = await service.async_create(name)
if created_diary:
self.diary_id_map[created_diary.id] = created_diary.id
await self.async_refresh_diaries()
self.notify(f"Diary: '{name}' created!")
else:
self.notify("Error Creating the diary")
except Exception as e:
self.notify(f"Exception on creating the diary: {str(e)}")
def _on_screen_resume(self) -> None:
self.refresh_diaries()
def action_edit_selected_diary(self):
"""Action to edit selected diary"""

View File

@ -4,17 +4,14 @@ from textual.containers import Vertical, Horizontal
from textual.screen import ModalScreen
from textual.widgets import Label, Input, Button
from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen
class NewDiaryModal(ModalScreen[str]):
BINDINGS = [
Binding("escape", "cancel", "Cancel"),
Binding("enter", "create_diary", "Create",priority=True),
]
def __init__(self,autoopen=True):
def __init__(self):
super().__init__()
self.auto_open = autoopen
self.name_input = Input(id="NewDiaryModal-NameInput",classes="NewDiaryModal-NameInput") # This ID is fine, it's specific to the input
def compose(self) -> ComposeResult:
@ -37,7 +34,7 @@ class NewDiaryModal(ModalScreen[str]):
if event.button.id == "create_diary_button":
self.action_create_diary()
elif event.button.id == "cancel_button":
self.dismiss()
self.dismiss("")
def action_cancel(self) -> None:
"""Action to cancel the modal."""
@ -46,9 +43,7 @@ class NewDiaryModal(ModalScreen[str]):
def action_create_diary(self) -> None:
diary_name = self.name_input.value.strip()
if diary_name:
self.call_later(self._async_create_diary, diary_name)
self.dismiss(diary_name)
else:
self.notify("Diary name cannot be empty.", severity="warning")
self.name_input.focus()
@ -57,24 +52,3 @@ class NewDiaryModal(ModalScreen[str]):
if event.input.id == "NewDiaryModal-NameInput":
self.action_create_diary()
async def _async_create_diary(self, name: str):
try:
service = self.app.service_manager.get_travel_diary_service()
created_diary = await service.async_create(name)
if created_diary:
self.dismiss(name)
if self.auto_open:
self.app.push_screen(EditEntryScreen(diary_id=created_diary.id))
self.notify(f"Diary: '{name}' created!")
else:
self.notify("Error Creating the diary")
except Exception as e:
self.notify(f"Exception on creating the diary: {str(e)}")