aboutsummaryrefslogtreecommitdiff
path: root/apps/raycast-extension/src/withSupermemory.tsx
blob: 9c78975133a91ce42c0b42a2a384e2044290c048 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { usePromise } from "@raycast/utils"
import { fetchSettings } from "./api"
import {
	Action,
	ActionPanel,
	Detail,
	Icon,
	List,
	openExtensionPreferences,
} from "@raycast/api"
import type { ComponentType } from "react"

export function withSupermemory<P extends object>(Component: ComponentType<P>) {
	return function SupermemoryWrappedComponent(props: P) {
		const { isLoading, data } = usePromise(fetchSettings, [], {
			failureToastOptions: {
				title: "Invalid API Key",
				message:
					"Invalid API key. Please check your API key in preferences. Get a new one from https://supermemory.link/raycast",
			},
		})

		if (!data) {
			return isLoading ? (
				<Detail isLoading />
			) : (
				<List>
					<List.EmptyView
						icon={Icon.ExclamationMark}
						title="API Key Required"
						description="Please configure your Supermemory API key to search memories"
						actions={
							<ActionPanel>
								<Action
									title="Open Extension Preferences"
									onAction={openExtensionPreferences}
									icon={Icon.Gear}
								/>
							</ActionPanel>
						}
					/>
				</List>
			)
		}

		return <Component {...props} />
	}
}