Skip to content

Commit

Permalink
feat: save to instapaper
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Aug 29, 2024
1 parent 3be6f2b commit 9d9b2c5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/renderer/src/atoms/settings/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const createDefaultSettings = (): IntegrationSettings => ({
enableEagle: true,
enableReadwise: true,
readwiseToken: "",
enableInstapaper: true,
instapaperUsername: "",
instapaperPassword: "",
})

export const {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { SVGProps } from "react"

export function SimpleIconsInstapaper(props: SVGProps<SVGSVGElement>) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
viewBox="0 0 90 90"
{...props}
>
<path d="M60.942 77.897c-4.244-.308-6.996-.946-8.251-1.923-1.255-.971-1.883-3.496-1.883-7.562V21.446c0-3.884.628-6.384 1.883-7.501 1.255-1.118 4.007-1.78 8.251-1.987V10H30.077v1.958c4.244.207 6.994.87 8.252 1.987 1.257 1.117 1.884 3.617 1.884 7.5v46.968c0 4.066-.627 6.59-1.884 7.562-1.258.976-4.008 1.614-8.252 1.922v1.96h30.865v-1.96Z" fill="currentColor" />
</svg>
)
}
1 change: 1 addition & 0 deletions src/renderer/src/components/ui/platform-icon/icons.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./collections/eagle"
export * from "./collections/instapaper"
export * from "./collections/readwise"
export * from "./collections/rss3"
33 changes: 32 additions & 1 deletion src/renderer/src/hooks/biz/useEntryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@renderer/atoms/readability"
import { useIntegrationSettingKey } from "@renderer/atoms/settings/integration"
import { whoami } from "@renderer/atoms/user"
import { SimpleIconsEagle, SimpleIconsReadwise } from "@renderer/components/ui/platform-icon/icons"
import { SimpleIconsEagle, SimpleIconsInstapaper, SimpleIconsReadwise } from "@renderer/components/ui/platform-icon/icons"
import { COPY_MAP } from "@renderer/constants"
import { shortcuts } from "@renderer/constants/shortcuts"
import { tipcClient } from "@renderer/lib/client"
Expand Down Expand Up @@ -140,6 +140,9 @@ export const useEntryActions = ({
const enableEagle = useIntegrationSettingKey("enableEagle")
const enableReadwise = useIntegrationSettingKey("enableReadwise")
const readwiseToken = useIntegrationSettingKey("readwiseToken")
const enableInstapaper = useIntegrationSettingKey("enableInstapaper")
const instapaperUsername = useIntegrationSettingKey("instapaperUsername")
const instapaperPassword = useIntegrationSettingKey("instapaperPassword")

const items = useMemo(() => {
if (!populatedEntry || view === undefined) return []
Expand Down Expand Up @@ -216,6 +219,34 @@ export const useEntryActions = ({
}
},
},
{
name: "Save to Instapaper",
icon: <SimpleIconsInstapaper />,
key: "saveToInstapaper",
hide: !enableInstapaper || !instapaperPassword || !instapaperUsername || !populatedEntry.entries.url,
onClick: async () => {
try {
const data = await ofetch("https://www.instapaper.com/api/add", {
query: {
url: populatedEntry.entries.url,
title: populatedEntry.entries.title,
},
method: "POST",
headers: {
Authorization: `Basic ${btoa(`${instapaperUsername}:${instapaperPassword}`)}`,
},
parseResponse: JSON.parse,
})
toast.success(<>Saved to Instapaper, <a target="_blank" className="underline" href={`https://www.instapaper.com/read/${data.bookmark_id}`}>view</a></>, {
duration: 3000,
})
} catch {
toast.error("Failed to save to Instapaper.", {
duration: 3000,
})
}
},
},
{
key: "tip",
shortcut: shortcuts.entry.tip.key,
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/initialize/hydrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { initializeDefaultGeneralSettings } from "@renderer/atoms/settings/general"
import { initializeDefaultIntegrationSettings } from "@renderer/atoms/settings/integration"
import { initializeDefaultUISettings } from "@renderer/atoms/settings/ui"
import { appLog } from "@renderer/lib/log"
import { sleep } from "@renderer/lib/utils"
Expand Down Expand Up @@ -108,4 +109,5 @@ const logHydrateError = (message: string) => {
export const hydrateSettings = () => {
initializeDefaultUISettings()
initializeDefaultGeneralSettings()
initializeDefaultIntegrationSettings()
}
16 changes: 15 additions & 1 deletion src/renderer/src/modules/settings/tabs/integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
setUISetting,
useUISettingSelector,
} from "@renderer/atoms/settings/ui"
import { SimpleIconsEagle, SimpleIconsReadwise } from "@renderer/components/ui/platform-icon/icons"
import { SimpleIconsEagle, SimpleIconsInstapaper, SimpleIconsReadwise } from "@renderer/components/ui/platform-icon/icons"
import {
Select,
SelectContent,
Expand Down Expand Up @@ -51,6 +51,20 @@ export const SettingIntegration = () => (
label: "Readwise Access Token",
description: <>You can get it here: <a target="_blank" className="underline" rel="noreferrer noopener" href="https://readwise.io/access_token">readwise.io/access_token</a>.</>,
}),
{
type: "title",
value: <span className="flex items-center gap-2"><SimpleIconsInstapaper />Instapaper</span>,
},
defineSettingItem("enableInstapaper", {
label: "Enable",
description: <>Display <i>Save to Instapaper</i> button when available.</>,
}),
defineSettingItem("instapaperUsername", {
label: "Instapaper Username",
}),
defineSettingItem("instapaperPassword", {
label: "Instapaper Password",
}),
]}
/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/shared/src/interface/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ export interface IntegrationSettings {
enableEagle: boolean
enableReadwise: boolean
readwiseToken: string
enableInstapaper: boolean
instapaperUsername: string
instapaperPassword: string
}

0 comments on commit 9d9b2c5

Please sign in to comment.