mirror of
https://github.com/Sevichecc/raycast-akkoma-extension.git
synced 2025-04-30 22:49:30 +08:00
refactor: detail-status command
This commit is contained in:
parent
9d8c23cec0
commit
88700da175
3 changed files with 36 additions and 56 deletions
|
@ -1,50 +1,18 @@
|
||||||
import { useEffect,useState } from "react";
|
import { Form, LaunchProps } from "@raycast/api";
|
||||||
import { Form, ActionPanel, Action, showToast } from "@raycast/api";
|
|
||||||
import { postNewStatus } from "./api";
|
|
||||||
import { Status } from "./types";
|
|
||||||
import { authorize } from "./oauth";
|
|
||||||
import VisibilityDropdown from "./components/VisibilityDropdown";
|
import VisibilityDropdown from "./components/VisibilityDropdown";
|
||||||
import StatusContent from "./components/statusContent";
|
import SimpleCommand from "./simple-status";
|
||||||
|
import { Status } from "./types";
|
||||||
|
|
||||||
export default function Command() {
|
interface CommandProps extends LaunchProps<{ draftValues: Status }> {
|
||||||
const [isMarkdown, setIsMarkdown] = useState<boolean>(true);
|
children?: React.ReactNode;
|
||||||
useEffect(() => {
|
}
|
||||||
authorize();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleSubmit = async (values: Partial<Status>) => {
|
|
||||||
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!" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
export default function DetailCommand(props: CommandProps) {
|
||||||
return (
|
return (
|
||||||
<Form
|
<SimpleCommand {...props}>
|
||||||
actions={
|
|
||||||
<ActionPanel>
|
|
||||||
<Action.SubmitForm onSubmit={handleSubmit} />
|
|
||||||
</ActionPanel>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Form.TextField id="textfield" title="Content Warning" placeholder="" />
|
|
||||||
<StatusContent isMarkdown={isMarkdown} />
|
|
||||||
<Form.Separator />
|
|
||||||
<Form.DatePicker id="datepicker" title="Scheduled Time" />
|
<Form.DatePicker id="datepicker" title="Scheduled Time" />
|
||||||
<VisibilityDropdown />
|
<VisibilityDropdown />
|
||||||
<Form.FilePicker id="files" />
|
<Form.FilePicker id="files" />
|
||||||
<Form.Checkbox
|
</SimpleCommand>
|
||||||
id="content-type"
|
|
||||||
title="Markdown"
|
|
||||||
label="Yes"
|
|
||||||
value={isMarkdown}
|
|
||||||
onChange={setIsMarkdown}
|
|
||||||
storeValue={true}
|
|
||||||
/>
|
|
||||||
<Form.Checkbox id="sensitive" title="Sensitive" label="Sensitive" />
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,34 @@
|
||||||
import { useEffect, useState,useRef } from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
ActionPanel,
|
ActionPanel,
|
||||||
Action,
|
Action,
|
||||||
showToast,
|
showToast,
|
||||||
popToRoot,
|
popToRoot,
|
||||||
LaunchProps,
|
|
||||||
Toast,
|
Toast,
|
||||||
Cache,
|
Cache,
|
||||||
Icon,
|
Icon,
|
||||||
LocalStorage,
|
LocalStorage,
|
||||||
getPreferenceValues,
|
getPreferenceValues,
|
||||||
|
LaunchProps,
|
||||||
} from "@raycast/api";
|
} from "@raycast/api";
|
||||||
|
|
||||||
import { postNewStatus } from "./api";
|
import { postNewStatus } from "./api";
|
||||||
import { Status, AkkomaError, StatusResponse, Preference } from "./types";
|
import { AkkomaError, StatusResponse, Preference, Status } from "./types";
|
||||||
import { authorize } from "./oauth";
|
import { authorize } from "./oauth";
|
||||||
|
|
||||||
import VisibilityDropdown from "./components/VisibilityDropdown";
|
import VisibilityDropdown from "./components/VisibilityDropdown";
|
||||||
import StatusContent from "./components/statusContent";
|
import StatusContent from "./components/StatusContent";
|
||||||
|
|
||||||
const cache = new Cache();
|
const cache = new Cache();
|
||||||
|
|
||||||
type SimpleStatus = Pick<Status, "content_type" | "status" | "spoiler_text" | "visibility">;
|
type SimpleStatus = Pick<Status, "content_type" | "status" | "spoiler_text" | "visibility">;
|
||||||
|
|
||||||
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<Preference>();
|
const { instance } = getPreferenceValues<Preference>();
|
||||||
const { draftValues } = props;
|
const { draftValues } = props;
|
||||||
const [cw, setCw] = useState<string>(draftValues?.spoiler_text || "");
|
const [cw, setCw] = useState<string>(draftValues?.spoiler_text || "");
|
||||||
|
@ -47,7 +52,7 @@ export default function Command(props: LaunchProps<{ draftValues: SimpleStatus }
|
||||||
init();
|
init();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSubmit = async (values: SimpleStatus) => {
|
const handleSubmit = async (values: Status) => {
|
||||||
try {
|
try {
|
||||||
if (!values.status) throw new Error("You might forget the content, right ? |・ω・)");
|
if (!values.status) throw new Error("You might forget the content, right ? |・ω・)");
|
||||||
showToast(Toast.Style.Animated, "Publishing to the Fediverse ... ᕕ( ᐛ )ᕗ");
|
showToast(Toast.Style.Animated, "Publishing to the Fediverse ... ᕕ( ᐛ )ᕗ");
|
||||||
|
@ -71,11 +76,11 @@ export default function Command(props: LaunchProps<{ draftValues: SimpleStatus }
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCw = () => {
|
const handleCw = () => {
|
||||||
setShowCw(!showCw)
|
setShowCw(!showCw);
|
||||||
if (cwRef.current) {
|
if (cwRef.current) {
|
||||||
cwRef.current.focus();
|
cwRef.current.focus();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
|
@ -90,10 +95,18 @@ export default function Command(props: LaunchProps<{ draftValues: SimpleStatus }
|
||||||
>
|
>
|
||||||
{fqn && <Form.Description title="Account" text={fqn} />}
|
{fqn && <Form.Description title="Account" text={fqn} />}
|
||||||
{showCw && (
|
{showCw && (
|
||||||
<Form.TextField id="spoiler_text" title="CW" placeholder={"content warning"} value={cw} onChange={setCw} ref={cwRef} />
|
<Form.TextField
|
||||||
|
id="spoiler_text"
|
||||||
|
title="CW"
|
||||||
|
placeholder={"content warning"}
|
||||||
|
value={cw}
|
||||||
|
onChange={setCw}
|
||||||
|
ref={cwRef}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
<StatusContent isMarkdown={isMarkdown} draftStatus={draftValues?.status} />
|
<StatusContent isMarkdown={isMarkdown} draftStatus={draftValues?.status} />
|
||||||
<VisibilityDropdown />
|
<VisibilityDropdown />
|
||||||
|
{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 id="showCw" title="Sensitive" label="" value={showCw} onChange={handleCw} storeValue />
|
<Form.Checkbox id="showCw" title="Sensitive" label="" value={showCw} onChange={handleCw} storeValue />
|
||||||
</Form>
|
</Form>
|
||||||
|
|
11
src/types.ts
11
src/types.ts
|
@ -51,20 +51,19 @@ export interface Status {
|
||||||
status: string;
|
status: string;
|
||||||
content_type: string;
|
content_type: string;
|
||||||
expires_in: number;
|
expires_in: number;
|
||||||
in_reply_to_conversation_id: string;
|
in_reply_to_conversation_id?: string;
|
||||||
in_reply_to_id: string;
|
in_reply_to_id?: string;
|
||||||
language: string;
|
language: string;
|
||||||
media_ids: string[];
|
media_ids: string[];
|
||||||
poll: Poll;
|
poll?: Poll;
|
||||||
preview: boolean | string | number;
|
preview?: boolean | string | number;
|
||||||
scheduled_at: Date;
|
scheduled_at: Date;
|
||||||
sensitive: string | boolean | number;
|
sensitive: string | boolean | number;
|
||||||
to: string[];
|
to?: string[];
|
||||||
visibility: VisibilityScope;
|
visibility: VisibilityScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface StatusResponse {
|
export interface StatusResponse {
|
||||||
id: string;
|
id: string;
|
||||||
create_at: Date;
|
create_at: Date;
|
||||||
|
|
Loading…
Reference in a new issue