From a3f410e717f9924ce8d038ca22af821f409b458c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Jan 2025 09:19:16 +0000 Subject: [PATCH] :lipstick: Style locally-used tag suggestions different from others When displaying suggested tags for a given URL, style those that the user has already used in a more positive light vs suggestions that are novel to the user. This way it's a wee bit easier to stick with your own tag convention. --- ChangeLog.md | 8 ++++++++ src/braindrop/app/screens/raindrop_input.py | 22 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 46e7c70..50f3c46 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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** diff --git a/src/braindrop/app/screens/raindrop_input.py b/src/braindrop/app/screens/raindrop_input.py index 50eb3a1..82e04b3 100644 --- a/src/braindrop/app/screens/raindrop_input.py +++ b/src/braindrop/app/screens/raindrop_input.py @@ -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 @@ -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.""" @@ -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"