Skip to content

Commit

Permalink
Apple Notes: Fix tags
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslombart committed May 16, 2024
1 parent 90b0d52 commit 2338968
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions extensions/apple-notes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Apple Notes Changelog

## [Bug Fix Update] - 2024-05-16

Fix crashes caused by empty links or tags.

## [Links, Backlinks, and Tags] - 2024-05-14

This update enhances the Apple Notes extension with several new features:
Expand Down
2 changes: 1 addition & 1 deletion extensions/apple-notes/src/components/NoteActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function NoteActions({ noteTitles, note, isDeleted, isDetail, mut
{note.links.length > 0 ? (
<ActionPanel.Submenu title="Open Links" icon={Icon.Link} shortcut={{ modifiers: ["cmd", "shift"], key: "l" }}>
{note.links.map((link) => {
if (link.url) {
if (link.url && link.text) {
return (
<Action.Open
key={link.id}
Expand Down
12 changes: 7 additions & 5 deletions extensions/apple-notes/src/components/NoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ export default function NoteDetail({ note, isDeleted, mutate }: NoteDetailProps)
) : null}
{note.tags.length > 0 ? (
<Detail.Metadata.TagList title="Tags">
{note.tags.map((tag) => (
<Detail.Metadata.TagList.Item key={tag.id} text={tag.text} />
))}
{note.tags.map((tag) => {
if (!tag.text) return null;
<Detail.Metadata.TagList.Item key={tag.id} text={tag.text} />;
})}
</Detail.Metadata.TagList>
) : null}
{note.links.length > 0 ? (
<Detail.Metadata.TagList title="Links">
{note.links.map((link) => {
const url = link.url;
if (url) {
const text = link.text;
if (url && text) {
return (
<Detail.Metadata.TagList.Item key={link.id} text={truncate(link.text)} onAction={() => open(url)} />
<Detail.Metadata.TagList.Item key={link.id} text={truncate(text)} onAction={() => open(url)} />
);
}
})}
Expand Down
9 changes: 7 additions & 2 deletions extensions/apple-notes/src/components/NoteListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export default function NoteListItem({ note, noteTitles, isDeleted, mutate }: No
text: `${note.tags.length}`,
icon: Icon.Hashtag,
// Display all tags inline and remove the leading # from the tag text
tooltip: `${note.tags.map((tag) => tag.text.slice(1)).join(", ")}`,
tooltip: `${note.tags
.map((tag) => {
if (!tag.text) return "";
return tag.text.slice(1);
})
.join(", ")}`,
});
}

Expand Down Expand Up @@ -96,7 +101,7 @@ export default function NoteListItem({ note, noteTitles, isDeleted, mutate }: No
}

if (note.tags) {
keywords.push(...note.tags.map((tag) => tag.text.slice(1)));
keywords.push(...note.tags.map((tag) => tag.text?.slice(1) ?? ""));
}

if (note.checklist) {
Expand Down
4 changes: 2 additions & 2 deletions extensions/apple-notes/src/useNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getOpenNoteURL } from "./helpers";

type Link = {
id: string;
text: string;
text: string | null;
url: string | null;
notePk: number;
};
Expand All @@ -21,7 +21,7 @@ type Backlink = {

type Tag = {
id: string;
text: string;
text: string | null;
notePk: number;
};

Expand Down

0 comments on commit 2338968

Please sign in to comment.