feat: show scheduled time in toast

This commit is contained in:
sevichecc 2023-04-16 12:08:12 +08:00
parent 1b2d51f601
commit 6491f68324
Signed by untrusted user who does not match committer: SevicheCC
GPG key ID: C577000000000000
4 changed files with 20 additions and 24 deletions

View file

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

View file

@ -1,7 +0,0 @@
import { Detail } from "@raycast/api";
const StatusPreview = () => {
return <div></div>;
};
export default StatusPreview;

View file

@ -10,7 +10,7 @@ export default function DetailCommand(props: LaunchProps<{ draftValues: Partial<
return ( return (
<SimpleCommand {...props}> <SimpleCommand {...props}>
<Form.FilePicker id="files" value={files} onChange={setFiles} /> <Form.FilePicker id="files" value={files} onChange={setFiles} />
{files.length !== 0 && <Form.TextArea id="description" title="Alt text" />} {files.length === 1 &&<Form.TextArea id="description" title="Alt text" />}
<Form.DatePicker id="scheduled_at" title="Scheduled Time"/> <Form.DatePicker id="scheduled_at" title="Scheduled Time"/>
<VisibilityDropdown /> <VisibilityDropdown />
</SimpleCommand> </SimpleCommand>

View file

@ -67,7 +67,6 @@ export default function SimpleCommand(props: CommandProps) {
}) })
); );
console.log(scheduled_at);
const newStatus: Partial<Status> = { const newStatus: Partial<Status> = {
spoiler_text, spoiler_text,
status, status,
@ -79,24 +78,33 @@ export default function SimpleCommand(props: CommandProps) {
}; };
const response = await apiServer.postNewStatus(newStatus); const response = await apiServer.postNewStatus(newStatus);
if (scheduled_at) {
setStatusInfo(response); showToast(Toast.Style.Success, "Scheduled", labelText(scheduled_at));
} else {
if (!scheduled_at) {
cache.set("latest_published_status", JSON.stringify(response)); cache.set("latest_published_status", JSON.stringify(response));
} setOpenActionText("View the status in Browser");
showToast(Toast.Style.Success, "Status has been published (≧∇≦)/ ! "); showToast(Toast.Style.Success, "Status has been published (≧∇≦)/ ! ");
setOpenActionText("Open the status in Browser"); }
setTimeout(() => { setStatusInfo(response)
popToRoot(); setCw("");
}, 1000); setTimeout(()=> popToRoot, 2000)
} catch (error) { } catch (error) {
const requestErr = error as AkkomaError; const requestErr = error as AkkomaError;
showToast(Toast.Style.Failure, "Error", requestErr.message); showToast(Toast.Style.Failure, "Error", requestErr.message);
} }
}; };
const labelText = (time: Date) => {
return new Intl.DateTimeFormat("default", {
hour: "numeric",
minute: "numeric",
day: "numeric",
month: "long",
weekday: "long",
dayPeriod: "narrow",
}).format(time);
};
const handleCw = (value: boolean) => { const handleCw = (value: boolean) => {
setSensitive(value); setSensitive(value);
if (cwRef.current) { if (cwRef.current) {