refactor: set statusInfo init to null

This commit is contained in:
sevichecc 2023-04-15 02:20:07 +08:00
parent 955fbd400e
commit 73b104a968
Signed by untrusted user who does not match committer: SevicheCC
GPG key ID: C577000000000000
2 changed files with 13 additions and 4 deletions

View file

@ -0,0 +1,9 @@
const Actions = () => {
return (
<>
</>
)
}
export default Actions

View file

@ -14,9 +14,9 @@ export default function Command(props: LaunchProps<{ draftValues: Partial<Status
const [cw, setCw] = useState<string>(draftValues?.spoiler_text || "");
const [isMarkdown, setIsMarkdown] = useState<boolean>(true);
const cached = cache.get("latest-pubished-status");
const cached = cache.get("latest_published_status");
const [statusInfo, setStatusInfo] = useState<StatusResponse>(cached ? JSON.parse(cached) : "");
const [statusInfo, setStatusInfo] = useState<StatusResponse>(cached ? JSON.parse(cached) : null);
const [openActionText, setOpenActionText] = useState<string>("Open the last published status");
useEffect(() => {
@ -34,7 +34,7 @@ export default function Command(props: LaunchProps<{ draftValues: Partial<Status
});
setStatusInfo(response);
cache.set("latest-pubished-status", JSON.stringify({ ...response }));
cache.set("latest_published_status", JSON.stringify(response));
showToast(Toast.Style.Success, "Status has been published (≧∇≦)/ ! ");
setOpenActionText("Open the status in Browser");
setTimeout(() => {
@ -52,7 +52,7 @@ export default function Command(props: LaunchProps<{ draftValues: Partial<Status
actions={
<ActionPanel>
<Action.SubmitForm onSubmit={handleSubmit} title="Publish" icon={Icon.Upload} />
<Action.OpenInBrowser url={statusInfo.url} title={openActionText} />
{ statusInfo && <Action.OpenInBrowser url={statusInfo.url} title={openActionText} />}
</ActionPanel>
}
>