mirror of
https://github.com/open-webui/extension
synced 2025-06-26 18:25:58 +00:00
fix: storage
This commit is contained in:
parent
4dce964f8e
commit
fe024a6e9b
24
extension/dist/main.js
vendored
24
extension/dist/main.js
vendored
File diff suppressed because one or more lines are too long
@ -6,18 +6,44 @@ export const SpotlightSearch = () => {
|
|||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [searchValue, setSearchValue] = useState("");
|
const [searchValue, setSearchValue] = useState("");
|
||||||
|
|
||||||
const [url, setUrl] = useState(localStorage.getItem("url") ?? "");
|
const [storageCache, setStorageCache] = useState(null);
|
||||||
const [key, setKey] = useState(localStorage.getItem("key") ?? "");
|
|
||||||
const [model, setModel] = useState(localStorage.getItem("model") ?? "");
|
useEffect(() => {
|
||||||
|
async function getStorageCache() {
|
||||||
|
let _storageCache = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
_storageCache = await chrome.storage.local.get();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
setStorageCache(_storageCache);
|
||||||
|
}
|
||||||
|
getStorageCache();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const [url, setUrl] = useState(storageCache?.url ?? "");
|
||||||
|
const [key, setKey] = useState(storageCache?.key ?? "");
|
||||||
|
const [model, setModel] = useState(storageCache?.model ?? "");
|
||||||
|
|
||||||
const [showConfig, setShowConfig] = useState(url === "" || key === "");
|
const [showConfig, setShowConfig] = useState(url === "" || key === "");
|
||||||
const [models, setModels] = useState(null);
|
const [models, setModels] = useState(null);
|
||||||
|
|
||||||
const resetConfig = () => {
|
const resetConfig = () => {
|
||||||
console.log("resetConfig");
|
console.log("resetConfig");
|
||||||
|
|
||||||
|
try {
|
||||||
|
chrome.storage.local.clear().then(() => {
|
||||||
|
console.log("Value is cleared");
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
localStorage.setItem("url", "");
|
localStorage.setItem("url", "");
|
||||||
localStorage.setItem("key", "");
|
localStorage.setItem("key", "");
|
||||||
localStorage.setItem("model", "");
|
localStorage.setItem("model", "");
|
||||||
|
}
|
||||||
|
|
||||||
setUrl("");
|
setUrl("");
|
||||||
setKey("");
|
setKey("");
|
||||||
@ -171,11 +197,19 @@ export const SpotlightSearch = () => {
|
|||||||
const initHandler = (e) => {
|
const initHandler = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
try {
|
||||||
|
chrome.storage.local
|
||||||
|
.set({ url: url, key: key, model: model })
|
||||||
|
.then(() => {
|
||||||
|
console.log("Value is set");
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
localStorage.setItem("url", url);
|
localStorage.setItem("url", url);
|
||||||
localStorage.setItem("key", key);
|
localStorage.setItem("key", key);
|
||||||
localStorage.setItem("model", model);
|
localStorage.setItem("model", model);
|
||||||
|
}
|
||||||
console.log(localStorage);
|
|
||||||
|
|
||||||
setShowConfig(false);
|
setShowConfig(false);
|
||||||
};
|
};
|
||||||
@ -224,7 +258,7 @@ export const SpotlightSearch = () => {
|
|||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setUrl(e.target.value);
|
setUrl(e.target.value);
|
||||||
}}
|
}}
|
||||||
autoComplete="off"
|
autoComplete="one-time-code"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -246,13 +280,11 @@ export const SpotlightSearch = () => {
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
id="open-webui-key-input"
|
|
||||||
placeholder="Open WebUI API Key"
|
placeholder="Open WebUI API Key"
|
||||||
type="password"
|
|
||||||
className="tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"
|
className="tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"
|
||||||
value={key}
|
value={key}
|
||||||
onChange={(e) => setKey(e.target.value)}
|
onChange={(e) => setKey(e.target.value)}
|
||||||
autoComplete="off"
|
autoComplete="one-time-code"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
@ -378,7 +410,7 @@ export const SpotlightSearch = () => {
|
|||||||
className="tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"
|
className="tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"
|
||||||
value={searchValue}
|
value={searchValue}
|
||||||
onChange={(e) => setSearchValue(e.target.value)}
|
onChange={(e) => setSearchValue(e.target.value)}
|
||||||
autoComplete="off"
|
autoComplete="one-time-code"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user