Skip to content

Commit

Permalink
feat(list): Added arrows for navigation to next item in list item det…
Browse files Browse the repository at this point in the history
…ail screen
  • Loading branch information
Nickelza committed Aug 19, 2024
1 parent 1d6dbce commit 1229178
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/chat/private/screens/screen_bounty_loan_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ async def manage(
context,
bounty_loan_list_page.get_item_detail_text(),
update=update,
keyboard=inline_keyboard,
keyboard=bounty_loan_list_page.get_previous_and_next_object_keyboard(inbound_keyboard)
+ inline_keyboard,
inbound_keyboard=inbound_keyboard,
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,24 @@ async def manage(
]
)

is_direct_item = False
if (
ReservedKeyboardKeys.DIRECT_ITEM in inbound_keyboard.info
and inbound_keyboard.info[ReservedKeyboardKeys.DIRECT_ITEM]
):
# Show list button
inline_keyboard.append([get_show_list_button(inbound_keyboard)])
is_direct_item = True

await full_message_send(
context,
dbf_list_page.get_item_detail_text(),
update=update,
keyboard=inline_keyboard,
keyboard=(
dbf_list_page.get_previous_and_next_object_keyboard(inbound_keyboard)
if not is_direct_item
else []
)
+ inline_keyboard,
inbound_keyboard=inbound_keyboard,
)
3 changes: 2 additions & 1 deletion src/chat/private/screens/screen_crew_search_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ async def manage(
crew_search_list_page.get_item_detail_text(),
update=update,
inbound_keyboard=inbound_keyboard,
keyboard=inline_keyboard,
keyboard=crew_search_list_page.get_previous_and_next_object_keyboard(inbound_keyboard)
+ inline_keyboard,
)
3 changes: 2 additions & 1 deletion src/chat/private/screens/screen_devil_fruit_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async def manage(
context,
devil_fruit_list_page.get_item_detail_text(),
update=update,
keyboard=inline_keyboard,
keyboard=devil_fruit_list_page.get_previous_and_next_object_keyboard(inbound_keyboard)
+ inline_keyboard,
inbound_keyboard=inbound_keyboard,
)
3 changes: 2 additions & 1 deletion src/chat/private/screens/screen_devil_fruit_shop_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async def manage(
context,
devil_fruit_shop_list_page.get_item_detail_text(),
update=update,
keyboard=inline_keyboard,
keyboard=devil_fruit_shop_list_page.get_previous_and_next_object_keyboard(inbound_keyboard)
+ inline_keyboard,
inbound_keyboard=inbound_keyboard,
)
5 changes: 4 additions & 1 deletion src/chat/private/screens/screen_logs_type_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ async def manage(
log.get_item_detail_text(),
update=update,
inbound_keyboard=inbound_keyboard,
keyboard=log.get_keyboard(),
keyboard=log.get_previous_and_next_object_keyboard(
inbound_keyboard, LogTypeReservedKeys.ITEM_ID
)
+ log.get_keyboard(),
)
3 changes: 2 additions & 1 deletion src/chat/private/screens/screen_prediction_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ async def manage(
context,
prediction_list_page.get_item_detail_text(),
update=update,
keyboard=inline_keyboard,
keyboard=prediction_list_page.get_previous_and_next_object_keyboard(inbound_keyboard)
+ inline_keyboard,
inbound_keyboard=inbound_keyboard,
)

Expand Down
2 changes: 2 additions & 0 deletions src/model/BaseModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class BaseModel(Model):
Used to manage Entities and Database connection
"""

id: int | PrimaryKeyField = PrimaryKeyField()

class Meta:
database = db_obj.get_db()
only_save_dirty = True
47 changes: 47 additions & 0 deletions src/model/enums/ListPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from src.model.enums.GameStatus import GameStatus
from src.model.enums.ReservedKeyboardKeys import ReservedKeyboardKeys
from src.model.error.CustomException import UnauthorizedToViewItemException
from src.model.pojo.Keyboard import Keyboard


class EmojiLegend:
Expand Down Expand Up @@ -94,6 +95,8 @@ def __init__(self):
self.default_limit = c.STANDARD_LIST_SIZE
self.legend: EmojiLegend | None = None
self.show_legend_list: bool = True # If to show legend list if available
self.previous_object: BaseModel | None = None
self.next_object: BaseModel | None = None

# Adding list of all items grouped by legend emoji, as to find out the emoji for each item
self.legend_filter_results: dict[EmojiLegend, list[BaseModel]] = {}
Expand Down Expand Up @@ -186,6 +189,16 @@ def get_item_detail_text(self) -> str:
if self.object not in self.get_all_items():
raise UnauthorizedToViewItemException()

# Set previous and next items
all_items = list(self.get_all_items())
current_item_index = all_items.index(self.object)
self.previous_object = (
all_items[current_item_index - 1] if current_item_index > 0 else None
)
self.next_object = (
all_items[current_item_index + 1] if current_item_index < len(all_items) - 1 else None
)

return ""

def get_emoji_legend(self) -> EmojiLegend:
Expand Down Expand Up @@ -332,3 +345,37 @@ def has_direct_item(self) -> bool:
"""

return self.get_direct_item() is not None

def get_previous_and_next_object_keyboard(
self, inbound_keyboard: Keyboard, item_key: str = ReservedKeyboardKeys.DEFAULT_PRIMARY_KEY
) -> list[list[Keyboard]]:
"""
Get the previous and next object keyboard
:param inbound_keyboard: The inbound keyboard
:param item_key: Key to access the item
return The keyboard for previous and next object
"""

keyboard_line: list[Keyboard] = []

# Previous object button
if self.previous_object is not None:
keyboard_line.append(
Keyboard(
Emoji.LEFT_ARROW,
info={item_key: self.previous_object.id},
inbound_info=inbound_keyboard.info,
)
)

# Next object button
if self.next_object is not None:
keyboard_line.append(
Keyboard(
Emoji.RIGHT_ARROW,
info={item_key: self.next_object.id},
inbound_info=inbound_keyboard.info,
)
)

return [keyboard_line]
2 changes: 1 addition & 1 deletion src/model/enums/Log.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def get_keyboard(self) -> list[list[Keyboard]]:
:return: The keyboard
"""

pass
return []


# noinspection DuplicatedCode
Expand Down

0 comments on commit 1229178

Please sign in to comment.