From 88700da17595ef62e2363d66071967d2decf8091 Mon Sep 17 00:00:00 2001 From: sevichecc <91365763+Sevichecc@users.noreply.github.com> Date: Sat, 15 Apr 2023 04:33:56 +0800 Subject: [PATCH] refactor: detail-status command --- src/detail-status.tsx | 50 ++++++++----------------------------------- src/simple-status.tsx | 31 +++++++++++++++++++-------- src/types.ts | 11 +++++----- 3 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/detail-status.tsx b/src/detail-status.tsx index d2cdb9c..55fcd86 100644 --- a/src/detail-status.tsx +++ b/src/detail-status.tsx @@ -1,50 +1,18 @@ -import { useEffect,useState } from "react"; -import { Form, ActionPanel, Action, showToast } from "@raycast/api"; -import { postNewStatus } from "./api"; -import { Status } from "./types"; -import { authorize } from "./oauth"; +import { Form, LaunchProps } from "@raycast/api"; import VisibilityDropdown from "./components/VisibilityDropdown"; -import StatusContent from "./components/statusContent"; +import SimpleCommand from "./simple-status"; +import { Status } from "./types"; -export default function Command() { - const [isMarkdown, setIsMarkdown] = useState(true); - useEffect(() => { - authorize(); - }, []); - - const handleSubmit = async (values: Partial) => { - try { - await postNewStatus({ ...values }); - showToast({ title: "Submitted form", message: "Status has been posted!" }); - } catch (error) { - console.error(error); - showToast({ title: "Error", message: "Something went wrong!" }); - } - }; +interface CommandProps extends LaunchProps<{ draftValues: Status }> { + children?: React.ReactNode; +} +export default function DetailCommand(props: CommandProps) { return ( -
- - - } - > - - - + - - - + ); } diff --git a/src/simple-status.tsx b/src/simple-status.tsx index 66c3ef1..3616643 100644 --- a/src/simple-status.tsx +++ b/src/simple-status.tsx @@ -1,29 +1,34 @@ -import { useEffect, useState,useRef } from "react"; +import { useEffect, useState, useRef } from "react"; import { Form, ActionPanel, Action, showToast, popToRoot, - LaunchProps, Toast, Cache, Icon, LocalStorage, getPreferenceValues, + LaunchProps, } from "@raycast/api"; + import { postNewStatus } from "./api"; -import { Status, AkkomaError, StatusResponse, Preference } from "./types"; +import { AkkomaError, StatusResponse, Preference, Status } from "./types"; import { authorize } from "./oauth"; import VisibilityDropdown from "./components/VisibilityDropdown"; -import StatusContent from "./components/statusContent"; +import StatusContent from "./components/StatusContent"; const cache = new Cache(); type SimpleStatus = Pick; -export default function Command(props: LaunchProps<{ draftValues: SimpleStatus }>) { +interface CommandProps extends LaunchProps<{ draftValues: SimpleStatus }> { + children?: React.ReactNode; +} + +export default function SimpleCommand(props: CommandProps) { const { instance } = getPreferenceValues(); const { draftValues } = props; const [cw, setCw] = useState(draftValues?.spoiler_text || ""); @@ -47,7 +52,7 @@ export default function Command(props: LaunchProps<{ draftValues: SimpleStatus } init(); }, []); - const handleSubmit = async (values: SimpleStatus) => { + const handleSubmit = async (values: Status) => { try { if (!values.status) throw new Error("You might forget the content, right ? |・ω・)"); showToast(Toast.Style.Animated, "Publishing to the Fediverse ... ᕕ( ᐛ )ᕗ"); @@ -71,11 +76,11 @@ export default function Command(props: LaunchProps<{ draftValues: SimpleStatus } }; const handleCw = () => { - setShowCw(!showCw) + setShowCw(!showCw); if (cwRef.current) { cwRef.current.focus(); } - } + }; return (
{fqn && } {showCw && ( - + )} + {props.children} diff --git a/src/types.ts b/src/types.ts index 4dfdac3..4bebc89 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,20 +51,19 @@ export interface Status { status: string; content_type: string; expires_in: number; - in_reply_to_conversation_id: string; - in_reply_to_id: string; + in_reply_to_conversation_id?: string; + in_reply_to_id?: string; language: string; media_ids: string[]; - poll: Poll; - preview: boolean | string | number; + poll?: Poll; + preview?: boolean | string | number; scheduled_at: Date; sensitive: string | boolean | number; - to: string[]; + to?: string[]; visibility: VisibilityScope; } - export interface StatusResponse { id: string; create_at: Date;