Skip to content

Commit

Permalink
feat: update error display
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Dec 15, 2023
1 parent 90b9d15 commit a5db037
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions components/episode-ai-thingy/episode-ai-thingy-generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@ import {
validateAccountAICredits,
} from '@/lib/services/account';
import { transcribeEpisode } from '@/lib/services/ai/transcribe-episode';
import { Box, Button, Flex, Text } from '@radix-ui/themes';
import { Box, Button, Callout, Flex, Text } from '@radix-ui/themes';
import { useCallback, useState } from 'react';
import { FaExclamationTriangle } from 'react-icons/fa';
import { PiRobotBold } from 'react-icons/pi';

import { CollapsiblePanel } from '../ui/collapsible-panel';
import { EpisodeAIThingyPlaceholder } from './episode-ai-thingy-placeholder';

type State =
| {
reason: string;
message: string;
status: 'error';
}
| {
status: 'idle';
}
| {
status: 'success';
summary: string;
transcription: string;
}
| {
status: 'summarizing';
transcription: string;
Expand All @@ -49,28 +45,20 @@ export function EpisodeAIThingyGenerator({
const initialAiCredits = await validateAccountAICredits();
updatedAiCredits = await updateAccountAICredits(initialAiCredits - 1);
} catch (error) {
setState({ reason: 'Not enough credits.', status: 'error' });
setState({ message: 'Not enough credits.', status: 'error' });
}

try {
setState({ status: 'transcribing' });

const transcription = await transcribeEpisode(id);
setState({ status: 'summarizing', transcription });
} catch (error) {
await updateAccountAICredits(updatedAiCredits + 1);
setState({ reason: 'idk', status: 'error' });
setState({ message: 'Failed to transcribe episode', status: 'error' });
}
}, [id]);

switch (state.status) {
case 'success':
return (
<CollapsiblePanel open title="Episode summary">
<Box style={{ whiteSpace: 'pre-wrap' }}>{state.summary}</Box>
</CollapsiblePanel>
);

case 'summarizing':
return (
<CollapsiblePanel open title="Episode transcription">
Expand All @@ -81,7 +69,13 @@ export function EpisodeAIThingyGenerator({
case 'error':
return (
<EpisodeAIThingyPlaceholder>
<Text>Failed {state.reason}</Text>
<Callout.Root color="red" role="alert" size="1">
<Callout.Icon>
<FaExclamationTriangle />
</Callout.Icon>

<Callout.Text>{state.message}</Callout.Text>
</Callout.Root>
</EpisodeAIThingyPlaceholder>
);

Expand Down

0 comments on commit a5db037

Please sign in to comment.