Skip to content

Commit

Permalink
lobsters user avatars update (raycast#174)
Browse files Browse the repository at this point in the history
* Update lobsters with author's avatars; add filtering by author

* Add 512x512 logo for Lobster

* Add CHANGELOG to lobsters extension
  • Loading branch information
dev99problems authored and FezVrasta committed Nov 24, 2021
1 parent c1b29a8 commit a18fc16
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
14 changes: 14 additions & 0 deletions extensions/lobsters/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# lobsters

## 1.0.2
### Patch Changes
- 284052e: Update lobsters with author's avatars; add filtering by author
- 3582a21: Add 512x512 logo for Lobster

## 1.0.1
### Patch Changes
- 2ee17c6: Change lobste.rs to lobsters to avoid url issue in Store

## 1.0.0
### Major Changes
- 1cbba09: Add lobste.rs homepage extension
Binary file modified extensions/lobsters/assets/lobster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions extensions/lobsters/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 35 additions & 19 deletions extensions/lobsters/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
OpenInBrowserAction,
showToast,
ToastStyle,
Icon,
ImageMask,
} from "@raycast/api";

const parser = new Parser();
Expand All @@ -34,15 +34,22 @@ export default function Command() {
const feed = await parser.parseURL("https://lobste.rs/rss");
setState({ items: feed.items as ParsedItem[] });
} catch (error) {
setState({ error: error instanceof Error ? error : new Error("Something went wrong") });
setState({
error:
error instanceof Error ? error : new Error("Something went wrong"),
});
}
}

void fetchStories();
}, []);

if (state.error) {
void showToast(ToastStyle.Failure, "Failed loading stories", state.error.message);
void showToast(
ToastStyle.Failure,
"Failed loading stories",
state.error.message
);
}

const isLoading = !state.items && !state.error;
Expand All @@ -57,16 +64,17 @@ export default function Command() {
}

function StoryListItem({ item }: { item: ParsedItem }) {
const icon = getIcon();
const author = getAuthor(item.creator);
const { authoredBy, nickname } = getAuthor(item.creator);
const icon = getIcon(nickname);
const keywords = [...(item?.categories ?? []), nickname];

return (
<List.Item
icon={icon}
title={item.title ?? "No title"}
subtitle={item.categories?.join(", ")}
keywords={item.categories}
accessoryTitle={author}
keywords={keywords}
accessoryTitle={authoredBy}
actions={<Actions title={item.title} link={item.link} guid={item.guid} />}
/>
);
Expand All @@ -79,27 +87,35 @@ function Actions({ title, link, guid }: ActionItem) {
<ActionPanel title={title}>
<ActionPanel.Section>
{link && <OpenInBrowserAction url={link} />}
{guid && <OpenInBrowserAction url={guid} title="Open Comments in Browser" />}
{guid && (
<OpenInBrowserAction url={guid} title="Open Comments in Browser" />
)}
</ActionPanel.Section>
<ActionPanel.Section>
{link && <CopyToClipboardAction content={link} title="Copy Link" shortcut={{ modifiers: ["cmd"], key: "." }} />}
{link && (
<CopyToClipboardAction
content={link}
title="Copy Link"
shortcut={{ modifiers: ["cmd"], key: "." }}
/>
)}
</ActionPanel.Section>
</ActionPanel>
);
}

function randomNum(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1) + min);
}

function getIcon() {
const colors = ["Brown", "Green", "Orange", "PrimaryText", "Purple", "Red", "SecondaryText"];

return { source: Icon.Document, tintColor: colors[randomNum(0, colors?.length)] };
function getIcon(nickname: string) {
return {
source: `https://lobste.rs/avatars/${nickname}-100.png`,
mask: ImageMask.Circle,
};
}

function getAuthor(creator: string) {
const author = creator?.match(/\((.*)\)/)?.[1];
const nickname = creator?.match(/\((.*)\)/)?.[1];

return author ? `by ${author} 🦞` : "untitled";
return {
authoredBy: nickname ? `by ${nickname} 🦞` : "untitled",
nickname: nickname ?? "",
};
}

0 comments on commit a18fc16

Please sign in to comment.