mirror of
https://github.com/Sevichecc/raycast-akkoma-extension.git
synced 2025-04-30 06:39:30 +08:00
refactor: remove if else
This commit is contained in:
parent
b55c15c123
commit
c66283b283
2 changed files with 28 additions and 17 deletions
|
@ -48,9 +48,8 @@ export default function SimpleCommand(props: CommandProps) {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
authorize();
|
authorize();
|
||||||
const newFqn = await LocalStorage.getItem<string>("account-fqn");
|
const newFqn = await LocalStorage.getItem<string>("account-fqn");
|
||||||
if (newFqn) setFqn(newFqn);
|
newFqn ? setFqn(newFqn) : setFqn("");
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -78,16 +77,18 @@ export default function SimpleCommand(props: CommandProps) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await apiServer.postNewStatus(newStatus);
|
const response = await apiServer.postNewStatus(newStatus);
|
||||||
|
|
||||||
if (scheduled_at) {
|
if (scheduled_at) {
|
||||||
showToast(Toast.Style.Success, "Scheduled", labelText(scheduled_at));
|
showToast(Toast.Style.Success, "Scheduled", labelText(scheduled_at));
|
||||||
} else {
|
} else {
|
||||||
showToast(Toast.Style.Success, "Status has been published (≧∇≦)/ ! ");
|
showToast(Toast.Style.Success, "Status has been published (≧∇≦)/ ! ");
|
||||||
cache.set("latest_published_status", JSON.stringify(response));
|
|
||||||
setOpenActionText("View the status in Browser");
|
|
||||||
}
|
}
|
||||||
setStatusInfo(response)
|
|
||||||
|
setStatusInfo(response);
|
||||||
|
setOpenActionText("View the status in Browser");
|
||||||
|
cache.set("latest_published_status", JSON.stringify(response));
|
||||||
setCw("");
|
setCw("");
|
||||||
setTimeout(()=> popToRoot, 2000)
|
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);
|
||||||
|
@ -107,9 +108,7 @@ export default function SimpleCommand(props: CommandProps) {
|
||||||
|
|
||||||
const handleCw = (value: boolean) => {
|
const handleCw = (value: boolean) => {
|
||||||
setSensitive(value);
|
setSensitive(value);
|
||||||
if (cwRef.current) {
|
cwRef.current?.focus();
|
||||||
cwRef.current.focus();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -138,14 +137,7 @@ export default function SimpleCommand(props: CommandProps) {
|
||||||
{!props.children && <VisibilityDropdown />}
|
{!props.children && <VisibilityDropdown />}
|
||||||
{props.children}
|
{props.children}
|
||||||
<Form.Checkbox id="markdown" title="Markdown" label="" value={isMarkdown} onChange={setIsMarkdown} storeValue />
|
<Form.Checkbox id="markdown" title="Markdown" label="" value={isMarkdown} onChange={setIsMarkdown} storeValue />
|
||||||
<Form.Checkbox
|
<Form.Checkbox id="sensitive" title="Sensitive" label="" value={sensitive} onChange={handleCw} storeValue />
|
||||||
id="sensitive"
|
|
||||||
title="Mark as Sensitive"
|
|
||||||
label=""
|
|
||||||
value={sensitive}
|
|
||||||
onChange={handleCw}
|
|
||||||
storeValue
|
|
||||||
/>
|
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
19
src/status.tsx
Normal file
19
src/status.tsx
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Form, LaunchProps } from "@raycast/api";
|
||||||
|
import { Status } from "./types";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import VisibilityDropdown from "./components/VisibilityDropdown";
|
||||||
|
import SimpleCommand from "./simple-status";
|
||||||
|
|
||||||
|
export default function DetailCommand(props: LaunchProps<{ draftValues: Partial<Status> }>) {
|
||||||
|
const [files, setFiles] = useState<string[]>([]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SimpleCommand {...props}>
|
||||||
|
<Form.FilePicker id="files" value={files} onChange={setFiles} />
|
||||||
|
{files.length === 1 && <Form.TextArea id="description" title="Alt text" />}
|
||||||
|
<Form.DatePicker id="scheduled_at" title="Scheduled Time" />
|
||||||
|
<VisibilityDropdown />
|
||||||
|
</SimpleCommand>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue