Skip to content

Commit

Permalink
🔀 Merge pull request #115 from davep/tag-suggestion-styling
Browse files Browse the repository at this point in the history
Style locally-used tag suggestions different from others
  • Loading branch information
davep authored Jan 20, 2025
2 parents 6b0ae47 + a3f410e commit cd6f7b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

0 comments on commit cd6f7b7

Please sign in to comment.