forked from all-in-aigc/gpts-works
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
305 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging" | ||
|
||
import { searchGpts } from "~services/gpts" | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => { | ||
const { question } = req.body | ||
const data = await searchGpts(question) | ||
console.log("search gpts in back", data) | ||
|
||
res.send({ | ||
data | ||
}) | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Gpts } from "~types/gpts" | ||
|
||
interface Props { | ||
gpts: Gpts[] | ||
} | ||
|
||
export default ({ gpts }: Props) => { | ||
return ( | ||
<ul className="menu overflow-auto text-base-content"> | ||
{gpts.length > 0 && | ||
gpts.map((item: Gpts, idx: number) => { | ||
return ( | ||
<> | ||
{item.avatar_url && item.author_name && ( | ||
<li key={idx} className="max-w-[480px] overflow-hidden"> | ||
<a | ||
href={item.visit_url} | ||
className="flex items-center rounded-none border-t border-gray-100 px-2 py-4 hover:bg-gray-100 dark:border-gray-700 dark:hover:bg-transparent"> | ||
<img | ||
src={item.avatar_url} | ||
className="h-10 w-10 rounded-full" | ||
alt="GPT" | ||
/> | ||
<div className="max-w-[200px] flex-1 ml-2 mr-24"> | ||
<h3 className="text-md font-semibold truncate"> | ||
{item.name} | ||
</h3> | ||
<p className="text-sm line-clamp-2 truncate"> | ||
{item.description} | ||
</p> | ||
</div> | ||
<div className="text-sm text-token-text-tertiary text-left truncate"> | ||
By {item.author_name || "-"} | ||
</div> | ||
</a> | ||
</li> | ||
)} | ||
</> | ||
) | ||
})} | ||
</ul> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use client" | ||
|
||
import type { | ||
ChangeEvent, | ||
Dispatch, | ||
KeyboardEvent, | ||
SetStateAction | ||
} from "react" | ||
import { useRef, useState } from "react" | ||
|
||
import { sendToBackground } from "@plasmohq/messaging" | ||
|
||
import type { Gpts } from "~/types/gpts" | ||
|
||
interface Props { | ||
setGpts: Dispatch<SetStateAction<Gpts[]>> | ||
setLoading: Dispatch<SetStateAction<boolean>> | ||
} | ||
|
||
export default ({ setGpts, setLoading }: Props) => { | ||
const [inputDisabled, setInputDisabled] = useState(false) | ||
const inputRef = useRef<HTMLInputElement | null>(null) | ||
const [content, setContent] = useState("") | ||
|
||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setContent(e.target.value) | ||
} | ||
|
||
const handleInputKeydown = (e: KeyboardEvent<HTMLInputElement>) => { | ||
if (e.code === "Enter" && !e.shiftKey) { | ||
if (e.keyCode !== 229) { | ||
e.preventDefault() | ||
handleSubmit() | ||
} | ||
} | ||
} | ||
|
||
const searchGpts = async (question: string) => { | ||
const resp = await sendToBackground({ | ||
name: "searchGpts", | ||
body: { | ||
question: question | ||
} | ||
}) | ||
console.log("searchGpts resp", resp) | ||
if (resp && resp.data) { | ||
setGpts(resp.data) | ||
} else { | ||
setGpts([]) | ||
} | ||
} | ||
|
||
const handleSubmit = async () => { | ||
if (!content) { | ||
return | ||
} | ||
|
||
searchGpts(content) | ||
} | ||
|
||
return ( | ||
<section className="relatve"> | ||
<div className="mx-auto w-full max-w-3xl px-5 py-2 md:px-10 pt-2 pb-8 md:pt-4 lg:pt-4 text-center"> | ||
<div className="flex items-center"> | ||
<input | ||
type="text" | ||
className="flex-1 px-4 py-3 border-2 border-[#2752f4] bg-white rounded-lg" | ||
placeholder="chat for searching GPTs" | ||
ref={inputRef} | ||
value={content} | ||
disabled={inputDisabled} | ||
onChange={handleInputChange} | ||
onKeyDown={handleInputKeydown} | ||
/> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="16" | ||
height="16" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className="-ml-8 cursor-pointer" | ||
onClick={handleSubmit}> | ||
<polyline points="9 10 4 15 9 20"></polyline> | ||
<path d="M20 4v7a4 4 0 0 1-4 4H4"></path> | ||
</svg> | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
.text-primary { | ||
color: #2752f4; | ||
} | ||
|
||
.border-primary { | ||
border-color: #2752f4; | ||
} | ||
|
||
.bg-panel { | ||
background-color: #fff; | ||
} | ||
|
||
.dark .bg-panel { | ||
background-color: #000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.