|
1 | | -import { useState } from 'react'; |
2 | | -import reactLogo from '@/assets/react.svg'; |
3 | | -import wxtLogo from '/wxt.svg'; |
4 | | -import './App.css'; |
| 1 | +import { useState, useEffect } from 'react'; |
| 2 | +import { storage } from 'wxt/storage'; |
5 | 3 |
|
6 | 4 | function App() { |
7 | | - const [count, setCount] = useState(0); |
| 5 | + const [baseUrl, setBaseUrl] = useState<string>(''); |
| 6 | + const [isSaved, setIsSaved] = useState(false); |
| 7 | + |
| 8 | + useEffect(() => { |
| 9 | + storage.getItem<string>('sync:baseUrl').then((savedUrl) => { |
| 10 | + if (savedUrl) { |
| 11 | + setBaseUrl(savedUrl); |
| 12 | + } |
| 13 | + }); |
| 14 | + }, []); |
| 15 | + |
| 16 | + const handleSave = async (e: React.FormEvent) => { |
| 17 | + e.preventDefault(); |
| 18 | + await storage.setItem('sync:baseUrl', baseUrl); |
| 19 | + setIsSaved(true); |
| 20 | + setTimeout(() => setIsSaved(false), 2500); |
| 21 | + }; |
8 | 22 |
|
9 | 23 | return ( |
10 | | - <> |
11 | | - <div> |
12 | | - <a href="https://wxt.dev" target="_blank"> |
13 | | - <img src={wxtLogo} className="logo" alt="WXT logo" /> |
14 | | - </a> |
15 | | - <a href="https://react.dev" target="_blank"> |
16 | | - <img src={reactLogo} className="logo react" alt="React logo" /> |
17 | | - </a> |
| 24 | + <div className="min-w-32 p-4 bg-[#fff4da]"> |
| 25 | + <div className="mb-4"> |
| 26 | + <h1 className="text-2xl font-bold tracking-tight"> |
| 27 | + <span className="text-gray-900">Git</span><span className="text-[#fca847]">ingest</span> |
| 28 | + </h1> |
18 | 29 | </div> |
19 | | - <h1>WXT + React</h1> |
20 | | - <div className="card"> |
21 | | - <button onClick={() => setCount((count) => count + 1)}> |
22 | | - count is {count} |
23 | | - </button> |
24 | | - <p> |
25 | | - Edit <code>src/App.tsx</code> and save to test HMR |
26 | | - </p> |
| 30 | + |
| 31 | + <div className="rounded-xl relative z-20 pl-6 sm:pl-8 pr-6 sm:pr-12 py-6 border-[3px] border-gray-900 bg-[#fff4da]"> |
| 32 | + <form |
| 33 | + className="flex flex-col w-full h-full justify-center items-stretch space-y-4" |
| 34 | + onSubmit={handleSave} |
| 35 | + > |
| 36 | + <div className="space-y-2"> |
| 37 | + <label |
| 38 | + htmlFor="baseUrl" |
| 39 | + className="block font-bold text-gray-900 text-sm" |
| 40 | + > |
| 41 | + Service URL |
| 42 | + </label> |
| 43 | + <div className="relative"> |
| 44 | + <div className="w-full h-full rounded bg-gray-900 translate-y-1 translate-x-1 absolute inset-0 z-10"></div> |
| 45 | + <input |
| 46 | + id="baseUrl" |
| 47 | + type="text" |
| 48 | + value={baseUrl} |
| 49 | + onChange={(e) => setBaseUrl(e.target.value)} |
| 50 | + placeholder="https://gitingest.com" |
| 51 | + className="border-[3px] w-full relative z-20 border-gray-900 placeholder-gray-500 text-base font-medium focus:outline-none py-2 px-4 rounded" |
| 52 | + /> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + |
| 56 | + <div className="relative w-full group"> |
| 57 | + <div className="w-full h-full rounded bg-gray-800 translate-y-1 translate-x-1 absolute inset-0 z-10"></div> |
| 58 | + <button |
| 59 | + type="submit" |
| 60 | + className="py-2 rounded px-4 group-hover:-translate-y-px group-hover:-translate-x-px ease-out duration-300 z-20 relative w-full border-[3px] border-gray-900 font-medium bg-[#ffc480] tracking-wide text-base flex-shrink-0 text-gray-900" |
| 61 | + > |
| 62 | + Save |
| 63 | + </button> |
| 64 | + </div> |
| 65 | + </form> |
| 66 | + |
| 67 | + {isSaved && ( |
| 68 | + <div className="mt-6 text-sm text-green-600 font-medium text-center relative z-20"> |
| 69 | + Settings saved! |
| 70 | + <br /> |
| 71 | + <span className="ml-2 font-normal text-gray-600 text-xs"> |
| 72 | + You may need to refresh the page. |
| 73 | + </span> |
| 74 | + </div> |
| 75 | + )} |
27 | 76 | </div> |
28 | | - <p className="read-the-docs"> |
29 | | - Click on the WXT and React logos to learn more |
30 | | - </p> |
31 | | - </> |
| 77 | + </div> |
32 | 78 | ); |
33 | 79 | } |
34 | 80 |
|
|
0 commit comments