From d84ca17754fbb54a61eb53a14b5b369a3fef3d40 Mon Sep 17 00:00:00 2001 From: edgarasben <725324+edgarasben@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:30:45 +0700 Subject: [PATCH] . --- extensions/multi-prompt/CHANGELOG.md | 6 + extensions/multi-prompt/package.json | 8 +- extensions/multi-prompt/src/manage-urls.tsx | 155 ++++++++++++++++++++ 3 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 extensions/multi-prompt/CHANGELOG.md create mode 100644 extensions/multi-prompt/src/manage-urls.tsx diff --git a/extensions/multi-prompt/CHANGELOG.md b/extensions/multi-prompt/CHANGELOG.md new file mode 100644 index 00000000000..a25c38c3b57 --- /dev/null +++ b/extensions/multi-prompt/CHANGELOG.md @@ -0,0 +1,6 @@ +# Multi Link Changelog + +## [Initial Release] - 2024-12-26 + +- Added `New Prompt` command +- Added `Mange Urls` command diff --git a/extensions/multi-prompt/package.json b/extensions/multi-prompt/package.json index 5703ec5b99f..05f28384324 100644 --- a/extensions/multi-prompt/package.json +++ b/extensions/multi-prompt/package.json @@ -6,7 +6,7 @@ "icon": "multi-icon.png", "author": "edg", "license": "MIT", -"commands": [ + "commands": [ { "name": "prompt", "title": "New Prompt", @@ -21,8 +21,8 @@ "mode": "view" }, { - "name": "add-urls", - "title": "Add Urls", + "name": "manage-urls", + "title": "Manage Urls", "subtitle": "Add or remove links for Multi command", "keywords": [ "add", @@ -54,4 +54,4 @@ "prepublishOnly": "echo \"\\n\\nIt seems like you are trying to publish the Raycast extension to npm.\\n\\nIf you did intend to publish it to npm, remove the \\`prepublishOnly\\` script and rerun \\`npm publish\\` again.\\nIf you wanted to publish it to the Raycast Store instead, use \\`npm run publish\\` instead.\\n\\n\" && exit 1", "publish": "npx @raycast/api@latest publish" } -} \ No newline at end of file +} diff --git a/extensions/multi-prompt/src/manage-urls.tsx b/extensions/multi-prompt/src/manage-urls.tsx new file mode 100644 index 00000000000..7d4a0f89b77 --- /dev/null +++ b/extensions/multi-prompt/src/manage-urls.tsx @@ -0,0 +1,155 @@ +import { + List, + ActionPanel, + Action, + Icon, + showToast, + Toast, + confirmAlert, + LocalStorage, +} from "@raycast/api"; +import { useEffect, useState } from "react"; + +interface URL { + id: string; + url: string; +} + +const DEFAULT_URLS = [ + "https://huggingface.co/chat/?q=", + "https://chatgpt.com/?q=", + "https://perplexity.ai/?q=", + "https://copilot.microsoft.com/?q=", + "https://claude.ai/new?q=", +]; + +export default function Command() { + const [urls, setUrls] = useState([]); + const [isLoading, setIsLoading] = useState(true); + const [searchText, setSearchText] = useState(""); + + useEffect(() => { + loadUrls(); + }, []); + + async function loadUrls() { + try { + const storedUrls = await LocalStorage.getItem("urls"); + if (storedUrls) { + setUrls(JSON.parse(storedUrls)); + } else { + // If no URLs are stored, add the default ones + const defaultUrlObjects = DEFAULT_URLS.map((url) => ({ + id: Date.now().toString() + Math.random(), + url, + })); + await saveUrls(defaultUrlObjects); + } + } catch (error) { + console.error("Error loading URLs:", error); + } + setIsLoading(false); + } + + async function saveUrls(newUrls: URL[]) { + await LocalStorage.setItem("urls", JSON.stringify(newUrls)); + setUrls(newUrls); + } + + async function addUrl(url: string) { + if (!url.trim()) return; + + const newUrl: URL = { + id: Date.now().toString(), + url: url.trim(), + }; + const newUrls = [...urls, newUrl]; + await saveUrls(newUrls); + showToast({ title: "URL Added", style: Toast.Style.Success }); + setSearchText(""); + } + + async function removeUrl(id: string) { + if ( + await confirmAlert({ + title: "Remove URL", + message: "Are you sure you want to remove this URL?", + }) + ) { + const newUrls = urls.filter((url) => url.id !== id); + await saveUrls(newUrls); + showToast({ title: "URL Removed", style: Toast.Style.Success }); + } + } + + async function resetToDefaults() { + if ( + await confirmAlert({ + title: "Reset to Defaults", + message: + "This will remove all custom URLs and restore the default LLM URLs. Are you sure?", + }) + ) { + const defaultUrlObjects = DEFAULT_URLS.map((url) => ({ + id: Date.now().toString() + Math.random(), + url, + })); + await saveUrls(defaultUrlObjects); + showToast({ title: "Reset to Default URLs", style: Toast.Style.Success }); + } + } + + function ActionButtons({ url }: { url?: URL }) { + return ( + + + addUrl(searchText)} + /> + + {url && ( + + removeUrl(url.id)} + /> + + )} + + + + + ); + } + + return ( + } + > + + {urls.map((url) => ( + } + /> + ))} + + + ); +}