# All files / src/components/settings DatabaseActionsCard.tsx

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

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

     'use client'

    import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card'
    import { Button } from '@/components/ui/button'
    import { Database, Download, Upload, Trash } from '@phosphor-icons/react'

    interface DatabaseActionsCardProps {
      onExport: () => Promise<void>
      onImport: (event: React.ChangeEvent<HTMLInputElement>) => Promise<void>
      onSeed: () => Promise<void>
      onClear: () => Promise<void>
    }

    export function DatabaseActionsCard({
      onExport,
      onImport,
      onSeed,
      onClear
    }: DatabaseActionsCardProps) {
      return (
        <Card>
          <CardHeader>
            <CardTitle>Database Actions</CardTitle>
            <CardDescription>
              Backup, restore, or reset your database
            </CardDescription>
          </CardHeader>
          <CardContent className="space-y-4">
            <div>
              <h3 className="text-sm font-semibold mb-2">Export Database</h3>
              <p className="text-sm text-muted-foreground mb-3">
                Download your database as a file for backup or transfer to another device
              </p>
              <Button onClick={onExport} variant="outline" className="gap-2">
                <Download weight="bold" size={16} />
                Export Database
              </Button>
            </div>

            <div className="pt-4 border-t border-border">
              <h3 className="text-sm font-semibold mb-2">Import Database</h3>
              <p className="text-sm text-muted-foreground mb-3">
                Restore a previously exported database file
              </p>
              <label>
                <input
                  type="file"
                  accept=".db"
                  onChange={onImport}
                  className="hidden"
                  id="import-db"
                />
                <Button variant="outline" className="gap-2" asChild>
                  <span>
                    <Upload weight="bold" size={16} />
                    Import Database
                  </span>
                </Button>
              </label>
            </div>

            <div className="pt-4 border-t border-border">
              <h3 className="text-sm font-semibold mb-2">Sample Data</h3>
              <p className="text-sm text-muted-foreground mb-3">
                Add sample code snippets to get started (only if database is empty)
              </p>
              <Button onClick={onSeed} variant="outline" className="gap-2">
                <Database weight="bold" size={16} />
                Add Sample Data
              </Button>
            </div>

            <div className="pt-4 border-t border-border">
              <h3 className="text-sm font-semibold mb-2 text-destructive">Clear All Data</h3>
              <p className="text-sm text-muted-foreground mb-3">
                Permanently delete all snippets and templates. This cannot be undone.
              </p>
              <Button onClick={onClear} variant="destructive" className="gap-2">
                <Trash weight="bold" size={16} />
                Clear Database
              </Button>
            </div>
          </CardContent>
        </Card>
      )
    }