fix: fqn do not show

This commit is contained in:
sevichecc 2023-04-16 19:17:52 +08:00
parent ef3368abb1
commit 51a30401ef
Signed by untrusted user who does not match committer: SevicheCC
GPG key ID: C577000000000000
2 changed files with 19 additions and 15 deletions

View file

@ -44,7 +44,7 @@ const refreshToken = async (
return tokenResponse; return tokenResponse;
}; };
export const authorize = async (cache: Cache): Promise<void> => { export const authorize = async (): Promise<void> => {
const { instance } = getPreferenceValues<Preference>(); const { instance } = getPreferenceValues<Preference>();
const tokenSet = await client.getTokens(); const tokenSet = await client.getTokens();
@ -67,5 +67,5 @@ export const authorize = async (cache: Cache): Promise<void> => {
await client.setTokens(await requestAccessToken(client_id, client_secret, authRequest, authorizationCode)); await client.setTokens(await requestAccessToken(client_id, client_secret, authRequest, authorizationCode));
const { fqn } = await apiServer.fetchAccountInfo(); const { fqn } = await apiServer.fetchAccountInfo();
cache.set("account-fqn", fqn); await LocalStorage.setItem("account-fqn", fqn);
}; };

View file

@ -10,6 +10,7 @@ import {
Icon, Icon,
getPreferenceValues, getPreferenceValues,
LaunchProps, LaunchProps,
LocalStorage,
} from "@raycast/api"; } from "@raycast/api";
import apiServer from "./api"; import apiServer from "./api";
import { AkkomaError, StatusResponse, Preference, Status } from "./types"; import { AkkomaError, StatusResponse, Preference, Status } from "./types";
@ -29,15 +30,6 @@ interface StatusForm extends Status {
description?: string; description?: string;
} }
const init = async (cache: Cache, setFqn: (fqn: string) => void) => {
try {
await authorize(cache);
setFqn(cache.get("account-fqn") ?? "");
} catch (error) {
console.error("Error during authorization or fetching account-fqn:", error);
}
};
const labelText = (time: Date) => { const labelText = (time: Date) => {
return new Intl.DateTimeFormat("default", { return new Intl.DateTimeFormat("default", {
hour: "numeric", hour: "numeric",
@ -61,13 +53,25 @@ export default function SimpleCommand(props: CommandProps) {
fqn: "", fqn: "",
}); });
const cachedInfo = cache.get("latest_published_status"); const cached = cache.get("latest_published_status");
const [statusInfo, setStatusInfo] = useState<StatusResponse>(cachedInfo ? JSON.parse(cachedInfo) : null); const [statusInfo, setStatusInfo] = useState<StatusResponse>(cached ? JSON.parse(cached) : null);
const cwRef = useRef<Form.TextField>(null); const cwRef = useRef<Form.TextField>(null);
useEffect(() => { useEffect(() => {
init(cache, (fqn) => setState((prevState) => ({ ...prevState, fqn }))); const init = async () => {
try {
await authorize();
const newFqn = (await LocalStorage.getItem<string>("account-fqn")) ?? "";
setState((prevState) => ({
...prevState,
fqn: newFqn,
}));
} catch (error) {
console.error("Error during authorization or fetching account-fqn:", error);
}
};
init();
}, []); }, []);
const handleSubmit = async ({ spoiler_text, status, scheduled_at, visibility, files, description }: StatusForm) => { const handleSubmit = async ({ spoiler_text, status, scheduled_at, visibility, files, description }: StatusForm) => {