# All files / src/components/features/snippet-display EmptyState.tsx

0% Statements 0/157
0% Branches 0/1
0% Functions 0/1
0% Lines 0/157

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158

     import { Code, Plus, CaretDown } from '@phosphor-icons/react'
    import { Button } from '@/components/ui/button'
    import {
      DropdownMenu,
      DropdownMenuContent,
      DropdownMenuItem,
      DropdownMenuSeparator,
      DropdownMenuTrigger,
      DropdownMenuLabel,
    } from '@/components/ui/dropdown-menu'
    import { strings } from '@/lib/config'
    import { SnippetTemplate } from '@/lib/types'
    import templatesData from '@/data/templates.json'

    const templates = templatesData as SnippetTemplate[]

    interface EmptyStateProps {
      onCreateClick: () => void
      onCreateFromTemplate?: (templateId: string) => void
    }

    export function EmptyState({ onCreateClick, onCreateFromTemplate }: EmptyStateProps) {
      return (
        <div
          className="flex flex-col items-center justify-center py-20 px-4 text-center"
          data-testid="empty-state"
          role="status"
          aria-label="No snippets available"
        >
          <div className="rounded-full bg-accent/10 p-6 mb-6" aria-hidden="true">
            <Code className="h-16 w-16 text-accent" weight="duotone" />
          </div>
          <h2 className="text-2xl font-semibold mb-2">{strings.emptyState.title}</h2>
          <p className="text-muted-foreground mb-8 max-w-sm">
            {strings.emptyState.description}
          </p>
          <DropdownMenu>
            <DropdownMenuTrigger asChild>
              <Button
                size="lg"
                className="gap-2"
                data-testid="empty-state-create-menu"
                aria-label="Create new snippet from templates"
              >
                <Code className="h-5 w-5" weight="bold" aria-hidden="true" />
                {strings.emptyState.buttonText}
                <CaretDown weight="bold" aria-hidden="true" />
              </Button>
            </DropdownMenuTrigger>
            <DropdownMenuContent
              align="center"
              className="w-72 max-h-[500px] overflow-y-auto"
              data-testid="empty-state-menu-content"
            >
              <DropdownMenuItem
                onClick={onCreateClick}
                data-testid="create-blank-snippet-item"
              >
                <Plus className="mr-2 h-4 w-4" weight="bold" aria-hidden="true" />
                Blank Snippet
              </DropdownMenuItem>
              <DropdownMenuSeparator />
              <DropdownMenuLabel>React Components</DropdownMenuLabel>
              {templates.filter((t) => t.category === 'react').map((template) => (
                <DropdownMenuItem
                  key={template.id}
                  onClick={() => onCreateFromTemplate?.(template.id)}
                  data-testid={`template-react-${template.id}`}
                >
                  <div className="flex flex-col gap-1 py-1">
                    <span className="font-medium">{template.title}</span>
                    <span className="text-xs text-muted-foreground line-clamp-1">
                      {template.description}
                    </span>
                  </div>
                </DropdownMenuItem>
              ))}
              <DropdownMenuSeparator />
              <DropdownMenuLabel>JavaScript / TypeScript</DropdownMenuLabel>
              {templates.filter((t) => ['api', 'basics', 'async', 'types'].includes(t.category)).map((template) => (
                <DropdownMenuItem
                  key={template.id}
                  onClick={() => onCreateFromTemplate?.(template.id)}
                >
                  <div className="flex flex-col gap-1 py-1">
                    <span className="font-medium">{template.title}</span>
                    <span className="text-xs text-muted-foreground line-clamp-1">
                      {template.description}
                    </span>
                  </div>
                </DropdownMenuItem>
              ))}
              <DropdownMenuSeparator />
              <DropdownMenuLabel>CSS Layouts</DropdownMenuLabel>
              {templates.filter((t) => t.category === 'layout').map((template) => (
                <DropdownMenuItem
                  key={template.id}
                  onClick={() => onCreateFromTemplate?.(template.id)}
                >
                  <div className="flex flex-col gap-1 py-1">
                    <span className="font-medium">{template.title}</span>
                    <span className="text-xs text-muted-foreground line-clamp-1">
                      {template.description}
                    </span>
                  </div>
                </DropdownMenuItem>
              ))}
              <DropdownMenuSeparator />
              <DropdownMenuLabel>Python - Project Euler</DropdownMenuLabel>
              {templates.filter((t) => t.category === 'euler').map((template) => (
                <DropdownMenuItem
                  key={template.id}
                  onClick={() => onCreateFromTemplate?.(template.id)}
                >
                  <div className="flex flex-col gap-1 py-1">
                    <span className="font-medium">{template.title}</span>
                    <span className="text-xs text-muted-foreground line-clamp-1">
                      {template.description}
                    </span>
                  </div>
                </DropdownMenuItem>
              ))}
              <DropdownMenuSeparator />
              <DropdownMenuLabel>Python - Algorithms</DropdownMenuLabel>
              {templates.filter((t) => t.category === 'algorithms' && t.language === 'Python').map((template) => (
                <DropdownMenuItem
                  key={template.id}
                  onClick={() => onCreateFromTemplate?.(template.id)}
                >
                  <div className="flex flex-col gap-1 py-1">
                    <span className="font-medium">{template.title}</span>
                    <span className="text-xs text-muted-foreground line-clamp-1">
                      {template.description}
                    </span>
                  </div>
                </DropdownMenuItem>
              ))}
              <DropdownMenuSeparator />
              <DropdownMenuLabel>Python - Interactive Programs</DropdownMenuLabel>
              {templates.filter((t) => t.category === 'interactive').map((template) => (
                <DropdownMenuItem
                  key={template.id}
                  onClick={() => onCreateFromTemplate?.(template.id)}
                >
                  <div className="flex flex-col gap-1 py-1">
                    <span className="font-medium">{template.title}</span>
                    <span className="text-xs text-muted-foreground line-clamp-1">
                      {template.description}
                    </span>
                  </div>
                </DropdownMenuItem>
              ))}
            </DropdownMenuContent>
          </DropdownMenu>
        </div>
      )
    }