Skip to content

Commit

Permalink
feat(client): sort list command by query id
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkasa committed Nov 12, 2024
1 parent bc9c748 commit 40dfffc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ulauncher_toggl_extension/commands/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
EDIT_IMG,
REFRESH_IMG,
)
from ulauncher_toggl_extension.utils import get_distance

from .meta import QueryResults, SubCommand

Expand Down Expand Up @@ -42,7 +43,19 @@ def get_models(self, query: Query, **kwargs: Any) -> list[TogglClient]:
self.handle_error(err)
clients = endpoint.collect()

clients.sort(key=lambda x: x.timestamp, reverse=query.sort_order)
if isinstance(query.id, int):
clients.sort(
key=lambda x: get_distance(query.id, x.id),
reverse=query.sort_order,
)
elif isinstance(query.id, str):
clients.sort(
key=lambda x: get_distance(query.id, x.name),
reverse=query.sort_order,
)
else:
clients.sort(key=lambda x: x.timestamp, reverse=query.sort_order)

return clients

def get_model(
Expand Down

0 comments on commit 40dfffc

Please sign in to comment.