From c66283b283e21e7709a9de77e62196da2bd0e4ea Mon Sep 17 00:00:00 2001 From: sevichecc <91365763+Sevichecc@users.noreply.github.com> Date: Sun, 16 Apr 2023 13:40:18 +0800 Subject: [PATCH] refactor: remove if else --- src/simple-status.tsx | 26 +++++++++----------------- src/status.tsx | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 src/status.tsx diff --git a/src/simple-status.tsx b/src/simple-status.tsx index c52f1dd..dfb2c6a 100644 --- a/src/simple-status.tsx +++ b/src/simple-status.tsx @@ -48,9 +48,8 @@ export default function SimpleCommand(props: CommandProps) { const init = async () => { authorize(); const newFqn = await LocalStorage.getItem("account-fqn"); - if (newFqn) setFqn(newFqn); + newFqn ? setFqn(newFqn) : setFqn(""); }; - init(); }, []); @@ -78,16 +77,18 @@ export default function SimpleCommand(props: CommandProps) { }; const response = await apiServer.postNewStatus(newStatus); + if (scheduled_at) { showToast(Toast.Style.Success, "Scheduled", labelText(scheduled_at)); } else { 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(""); - setTimeout(()=> popToRoot, 2000) + setTimeout(() => popToRoot, 2000); } catch (error) { const requestErr = error as AkkomaError; showToast(Toast.Style.Failure, "Error", requestErr.message); @@ -107,9 +108,7 @@ export default function SimpleCommand(props: CommandProps) { const handleCw = (value: boolean) => { setSensitive(value); - if (cwRef.current) { - cwRef.current.focus(); - } + cwRef.current?.focus(); }; return ( @@ -138,14 +137,7 @@ export default function SimpleCommand(props: CommandProps) { {!props.children && } {props.children} - + ); } diff --git a/src/status.tsx b/src/status.tsx new file mode 100644 index 0000000..489dcf3 --- /dev/null +++ b/src/status.tsx @@ -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 }>) { + const [files, setFiles] = useState([]); + + return ( + + + {files.length === 1 && } + + + + ); +}