Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style locally-used tag suggestions different from others #115

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Braindrop ChangeLog

## Unreleased

**Released: WiP**

- Tag suggestions displayed below the tag input field in the raindrop
editing dialog now style locally-known tags differently from suggestions
that haven't ever been used by the user.

## v0.6.1

**Released: 2025-01-15**
Expand Down
22 changes: 20 additions & 2 deletions src/braindrop/app/screens/raindrop_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

##############################################################################
# Local imports.
from ...raindrop import API, Collection, Raindrop, SpecialCollection
from ...raindrop import API, Collection, Raindrop, SpecialCollection, Suggestions, Tag
from ..data import LocalData
from ..suggestions import SuggestTags

Expand Down Expand Up @@ -207,6 +207,24 @@ def _collection_names(self, collections: list[int]) -> Iterator[str]:
except KeyError:
yield f"Unknown#{collection})"

def _format_tag_suggestions(self, suggestions: Suggestions) -> list[str]:
"""Format the list of tag suggestions.

Args:
suggestions: The suggestions to get the tags from.

Returns:
A `str`ified list of tags for use in a `Label`. Tags that
already list locally will be styled differently from novel
suggestions so it's easier for the user to know which are part
of their tag scheme, and which aren't.
"""
local_tags = {tag.tag for tag in self._data.all.tags}
return [
f"{tag}" if tag in local_tags else f"[dim i]{tag}[/]"
for tag in suggestions.tags
]

@work(exclusive=True)
async def _get_suggestions(self) -> None:
"""Load up fresh suggestions based on the URL."""
Expand All @@ -228,7 +246,7 @@ async def _get_suggestions(self) -> None:
f"[b]Suggested:[/] {', '.join(self._collection_names(suggestions.collections))}"
)
self.query_one("#tag-suggestions", Label).update(
f"[b]Suggested:[/] {Raindrop.tags_to_string(suggestions.tags)}"
f"[b]Suggested:[/] {', '.join(self._format_tag_suggestions(suggestions))}"
)
self.query_one("#collection-suggestions").set_class(
bool(suggestions.collections), "got-suggestions"
Expand Down
Loading