Add save to Readwise Reader integration to Hacker News extension#16749
Add save to Readwise Reader integration to Hacker News extension#16749raycastbot merged 15 commits intoraycast:mainfrom russellyeo:ext/hacker-news
Conversation
- Add format script - Remove force unwrap and unused imports - Lint - Add publish script - Cache saved URLs and show an accessory - Fix import - Add documentation - Only show the save to readwise reader option if the token is set - Extract readwise logic to new file - Add action to save article to readwise reader - Automated add to contributors - Initial commit
|
Thank you for your contribution! 🎉 🔔 @thomaspaulmann @GastroGeek @sxn @itsnwa @andreaselia you might want to have a look. You can use this guide to learn how to check out the Pull Request locally in order to test it. Due to our current reduced availability, the initial review may take up to 10-15 business days |
pernielsentikaer
left a comment
There was a problem hiding this comment.
Looks like a nice update, could you check the suggestion I made 😊
|
|
||
| interface Preferences { | ||
| /** Readwise API token from https://readwise.io/access_token */ | ||
| readwiseToken: string; | ||
| } |
There was a problem hiding this comment.
You don't need to manually set preference types as this is autogenerated in raycast-env.d.tsx
There was a problem hiding this comment.
Ah cool! Thanks for the feedback
|
Could you look into the merge conflicts too? Also, we're testing @greptileai which also wants to do a review, could you look into that it finds if it makes sense? |
There was a problem hiding this comment.
PR Summary
This PR adds Readwise Reader integration to the Hacker News extension, allowing users to save articles and see visual indicators for previously saved content.
- Added new
readwise.tsmodule with API integration for saving articles to Readwise Reader and caching saved URLs - Added
preferences.tswith utility functions to securely handle the Readwise API token - Modified
utils.tsto show a visual indicator (SaveDocument icon) for previously saved articles - Added a new preference for the Readwise API token in
package.jsonas a password type for security - In
CHANGELOG.md, the new entry is correctly placed at the top with{PR_MERGE_DATE}which will be automatically replaced with the current date upon merging
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
6 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
| <Action | ||
| icon={Icon.SaveDocument} | ||
| title="Save to Readwise Reader" | ||
| onAction={() => saveToReadwise(props.item.link || "")} |
There was a problem hiding this comment.
style: Consider wrapping this in a try/catch block or using showFailureToast from @raycast/utils to handle errors more elegantly
There was a problem hiding this comment.
Super cool that the bot knows about the components in the Raycast libraries!
The saveToReadwise function does do error handling internally and shows a success/error toast message, but I guess it would be better software design to separate the API action and the UI. I'll do that now.
| export function getReadwiseToken(): string { | ||
| const preferences = getPreferenceValues(); | ||
| if (!preferences.readwiseToken) { | ||
| throw new Error("Readwise API token not configured"); | ||
| } | ||
| return preferences.readwiseToken; |
There was a problem hiding this comment.
style: Consider adding a try/catch block here similar to hasReadwiseToken() to handle potential exceptions from getPreferenceValues().
There was a problem hiding this comment.
You can add since we have raycast-env.d.ts available 😊
|
did you add the |
|
@greptileai can you check again 🙂 |
There was a problem hiding this comment.
PR Summary
(updates since last review)
This PR adds Readwise Reader integration to the Hacker News extension, allowing users to save articles and displaying visual indicators for previously saved content.
- The
launchCommandfunction infrontpage.tsxshould be wrapped in a try/catch block for better error handling - The
showToasterror handling inreadwise.tscould be simplified usingshowFailureToastfrom@raycast/utils - The
getReadwiseToken()function inpreferences.tslacks the same try/catch error handling thathasReadwiseToken()has - Consider adding a subtitle to the command in
package.jsonto indicate it's from Hacker News, since there are multiple commands
6 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
|
Can you show me a screencast of with and without the Readwise token? I don't have a token to test with 🫠 |
|
@pernielsentikaer Thanks for fixing the changelog and preferences! I reviewed the feedback from the bot and made a couple of improvements to the code:
I also made an improvement to ensure the saved icon appears immediately by loading the saved URLs into useState and refreshing it after successful saves. Overall the bot is pretty cool, but it seems to have made up some things (there's no Edit: The next batch of suggestions were great |
|
Here's a screencast of the changes in action 🙂 output.mp4 |
|
@greptileai can you review again please? 🙂 |
There was a problem hiding this comment.
PR Summary
(updates since last review)
The PR now includes improved error handling and state management for the Readwise Reader integration in the Hacker News extension.
- The
frontpage.tsxnow properly manages saved URLs state withuseStateanduseEffecthooks to load cached URLs when the component mounts - Added a dedicated
handleSaveToReadwisefunction that handles API responses and updates the UI accordingly - The
StoryListItemcomponent now acceptssavedUrlsandonSaveprops to properly display saved status and handle save actions - The
getAccessoriesfunction inutils.tshas been enhanced with an optionalisSavedparameter for more flexible saved status display
4 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
| onSave: (url: string) => Promise<void>; | ||
| }) { | ||
| // Check if this item is in the savedUrls array | ||
| const isSaved = props.item.link ? (props.savedUrls.includes(props.item.link) || isUrlSaved(props.item.link)) : false; |
There was a problem hiding this comment.
style: This line calls both savedUrls.includes(props.item.link) and isUrlSaved(props.item.link), which seems redundant since isUrlSaved already checks the cache. Consider simplifying this logic.
There was a problem hiding this comment.
Yeah fair point, probably good enough to check the local state only
| const urls = getSavedUrls(); | ||
| if (!urls.includes(url)) { | ||
| urls.push(url); | ||
| cache.set(CACHE_KEY, JSON.stringify(urls)); | ||
| } |
There was a problem hiding this comment.
style: Consider adding error handling for JSON.stringify or cache.set operations in case they fail.
pernielsentikaer
left a comment
There was a problem hiding this comment.
Hi 👋
Looks good to me, approved 🔥
In the next version, we can always configure it to delete the oldest one when it reaches the limit, I suppose
|
Thanks for the review @pernielsentikaer 🙏🏻 Is there anything I need to do to get the PR merged? |
|
No 🙂 |
|
Published to the Raycast Store: |
|
🎉 🎉 🎉 We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag. |
Description
Added optional support for saving hacker news articles to Readwise Reader.
Features
SavedDocumenticonScreenshots
Checklist
npm run buildand tested this distribution build in Raycastassetsfolder are used by the extension itselfREADMEare placed outside of themetadatafolder