Skip to content

Commit

Permalink
refactor: simplify show-status command and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrwalters committed Feb 4, 2025
1 parent fbb91a4 commit 72eac0b
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions extensions/mutedeck/src/commands/show-status.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,39 @@
import { showToast, Toast } from "@raycast/api";
import { useEffect, useState } from "react";
import { showToast, Toast, updateCommandMetadata } from '@raycast/api';
import { useEffect } from 'react';
import {
getStatus,
isInMeeting,
isMuted,
isMuteDeckRunning,
isVideoOn,
type MuteDeckStatus,
} from "../utils/api";

interface State {
status: MuteDeckStatus | null;
isLoading: boolean;
error: Error | null;
}
} from '../utils/api';

export default function Command(): void {
const [state, setState] = useState<State>({
status: null,
isLoading: true,
error: null,
});

async function fetchStatus(): Promise<void> {
try {
const status = await getStatus();
setState((prev) => ({ ...prev, status, isLoading: false }));

// Update command metadata
Command.subtitle = getStatusText(status);
await updateCommandMetadata({ subtitle: getStatusText(status) });
} catch (error) {
setState((prev) => ({
...prev,
error:
error instanceof Error ? error : new Error("Failed to fetch status"),
isLoading: false,
}));

showToast({
style: Toast.Style.Failure,
title: "Failed to Get Status",
message: error instanceof Error ? error.message : "Unknown error",
title: 'Failed to Get Status',
message: error instanceof Error ? error.message : 'Unknown error',
});
}
}

function getStatusText(status: MuteDeckStatus): string {
if (!isMuteDeckRunning(status)) {
return "Not Running";
return 'Not Running';
}

if (!isInMeeting(status)) {
return "Not in Meeting";
return 'Not in Meeting';
}

const muted = isMuted(status) ? "Muted" : "Unmuted";
const video = isVideoOn(status) ? "Video On" : "Video Off";
const muted = isMuted(status) ? 'Muted' : 'Unmuted';
const video = isVideoOn(status) ? 'Video On' : 'Video Off';
return `${muted}, ${video}`;
}

Expand Down

0 comments on commit 72eac0b

Please sign in to comment.