🐛 fixed a bug that prevented typing

This commit is contained in:
kawamataryo 2023-10-13 20:05:17 +09:00
parent f1acbaa17c
commit 62b0136e16

View File

@ -1,10 +1,9 @@
import { type FormEvent, useState } from "react" import { type FormEvent, useState, useEffect } from "react"
import { P, match } from "ts-pattern" import { P, match } from "ts-pattern"
import "./style.css" import "./style.css"
import { sendToContentScript } from "@plasmohq/messaging" import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"
import { import {
MAX_RELOAD_COUNT, MAX_RELOAD_COUNT,
@ -14,13 +13,10 @@ import {
TARGET_URLS_REGEX TARGET_URLS_REGEX
} from "~lib/constants" } from "~lib/constants"
import { debugLog } from "./lib/utils"
import { ReloadButton } from "~lib/components/ReloadBtn"
function IndexPopup() { function IndexPopup() {
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [password, setPassword] = useStorage(STORAGE_KEYS.BSKY_PASSWORD, "") const [password, setPassword] = useState("")
const [userId, setUserId] = useStorage(STORAGE_KEYS.BSKY_USER_ID, "") const [userId, setUserId] = useState("")
const [reloadCount, setReloadCount] = useState(0) const [reloadCount, setReloadCount] = useState(0)
const [message, setMessage] = useState<null | { const [message, setMessage] = useState<null | {
type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE] type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]
@ -42,6 +38,23 @@ function IndexPopup() {
await chrome.tabs.reload(tabId) await chrome.tabs.reload(tabId)
} }
const saveCredentialsToStorage = () => {
chrome.storage.local.set({
[STORAGE_KEYS.BSKY_PASSWORD]: password,
[STORAGE_KEYS.BSKY_USER_ID]: userId
})
}
const loadCredentialsFromStorage = async () => {
chrome.storage.local.get(
[STORAGE_KEYS.BSKY_PASSWORD, STORAGE_KEYS.BSKY_USER_ID],
(result) => {
setPassword(result[STORAGE_KEYS.BSKY_PASSWORD] || "")
setUserId(result[STORAGE_KEYS.BSKY_USER_ID] || "")
}
)
}
const searchBskyUser = async (e?: FormEvent) => { const searchBskyUser = async (e?: FormEvent) => {
if(e) { if(e) {
e.preventDefault() e.preventDefault()
@ -108,9 +121,14 @@ function IndexPopup() {
} }
} finally { } finally {
setIsLoading(false) setIsLoading(false)
saveCredentialsToStorage()
} }
} }
useEffect(() => {
loadCredentialsFromStorage()
}, [])
return ( return (
<div className="px-5 pt-3 pb-4 w-[380px]"> <div className="px-5 pt-3 pb-4 w-[380px]">
<h1 className="text-primary text-2xl font-thin flex gap-2 items-center"> <h1 className="text-primary text-2xl font-thin flex gap-2 items-center">