Add a functionality that automatically opens the diary after creation, Change the responsibility of diary creation to the new_diary_modal.py instead of the diary_list_screen.py

This commit is contained in:
Gustavo Henrique Santos Souza de Miranda
2025-07-15 02:14:53 -03:00
parent 3bef353939
commit 18760e174c
2 changed files with 32 additions and 24 deletions
+9 -21
View File
@@ -206,29 +206,17 @@ 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):
self.notify(str(result))
if result:
self.notify(f"Creating Diary:{result}'...")
self.call_later(self._async_create_diary,result)
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()
else:
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)}")
self.notify(f"Creation canceled...")
def _on_screen_resume(self) -> None:
self.refresh_diaries()
def action_edit_selected_diary(self):
"""Action to edit selected diary"""