mirror of
https://github.com/Sevichecc/raycast-akkoma-extension.git
synced 2025-04-30 22:49:30 +08:00
fix: fqn do not show
This commit is contained in:
parent
ef3368abb1
commit
51a30401ef
2 changed files with 19 additions and 15 deletions
|
@ -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();
|
||||||
|
|
||||||
|
@ -66,6 +66,6 @@ export const authorize = async (cache: Cache): Promise<void> => {
|
||||||
const { authorizationCode } = await client.authorize(authRequest);
|
const { authorizationCode } = await client.authorize(authRequest);
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) => {
|
||||||
|
|
Loading…
Reference in a new issue