+31
-11
@@ -61,24 +61,44 @@ export default Plugin.define({
|
||||
});
|
||||
|
||||
const Slot = (props: { instance: string; centered?: boolean; visible?: () => boolean }) => {
|
||||
const [status] = createResource(
|
||||
const [statuses] = createResource(
|
||||
() => (props.visible?.() === false ? false : `${props.instance}:${revision()}`),
|
||||
() => loadQuotaStatus(() => quota.status({})),
|
||||
async () => {
|
||||
const [chatgpt, claude] = await Promise.all([
|
||||
loadQuotaStatus(() => quota.status({})),
|
||||
loadQuotaStatus(() => quota.claude({})),
|
||||
]);
|
||||
return chatgpt || claude ? { chatgpt, claude } : null;
|
||||
},
|
||||
);
|
||||
const Section = (section: { title: string; status: QuotaStatus | null }) => (
|
||||
<Show when={section.status}>
|
||||
{(status: () => QuotaStatus) => (
|
||||
<>
|
||||
<text fg={context.theme.text.default}>
|
||||
<b>
|
||||
{section.title} quota ({status().plan})
|
||||
</b>
|
||||
</text>
|
||||
<For each={status().windows}>
|
||||
{(window) => (
|
||||
<text fg={context.theme.text.muted}>
|
||||
{formatQuotaWindow(window)}
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
</>
|
||||
)}
|
||||
</Show>
|
||||
);
|
||||
const Content = () => (
|
||||
<box flexDirection="column">
|
||||
<text fg={context.theme.text.default}>
|
||||
<b>ChatGPT quota ({status()!.plan})</b>
|
||||
</text>
|
||||
<For each={status()!.windows}>
|
||||
{(window) => (
|
||||
<text fg={context.theme.text.muted}>{formatQuotaWindow(window)}</text>
|
||||
)}
|
||||
</For>
|
||||
<Section title="ChatGPT" status={statuses()!.chatgpt} />
|
||||
<Section title="Claude" status={statuses()!.claude} />
|
||||
</box>
|
||||
);
|
||||
return (
|
||||
<Show when={status()}>
|
||||
<Show when={statuses()}>
|
||||
<Show when={props.centered} fallback={<Content />}>
|
||||
<box position="absolute" top={2} left={0} width="100%" alignItems="center">
|
||||
<Content />
|
||||
|
||||
Reference in New Issue
Block a user