summaryrefslogtreecommitdiff
path: root/src/components/LoadScreen.tsx
blob: e51ff6ab876f07fbe12551f6002f62ce7e41bbf9 (plain)
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
159
160
161
162
163
164
import React, { useState } from 'react';
import type { Grid } from '@/types/grid';
import { getSavedArt, deleteSavedArt, type SavedArt } from '@/utils/storage';
import { GridComponent } from './grid/GridComponent';
import { gridFromAscii } from '@/utils/grid';

const demoArt = [
    { name: '🎨 Butterfly', art: `|                      |
|  ⠀⠀⠀⠀⊹               |
|  ⢶⢻⣑⣒⢤⡀⠀⢄⠀⠀⡠⠀⢀⡤⣆⣊⡿⡷  |
|  ⠀⠹⠹⣚⣣⠻⣦⡀⠀⠀⢀⣴⠟⣸⢓⢎⠏⠀  |
|  ⠀⠀⢡⣱⣖⣢⡾⢿⣾⣷⡿⢷⣖⣒⣎⡎⠀⠀  |
|  ⠀⠀⠀⣠⠓⢬⠅⡺⢻⡟⢗⠨⡥⠚⣄⠀⠀⠀  |
|  ⠀⠀⠀⣿⡆⠘⠆⢇⢸⡇⠸⠰⠃⢰⣿⠀⠀⠀  |
|  ⠀⠀⠀⠐⡻⣮⣬⠞⠈⠁⠳⣤⣴⢿⠂⠀⠀⠀  |
|  ⠀⠀⠀⡜⠀⠁⠉⠀⠀⠀⠀⠈⠈⠀⢣⠀⠀⠀  |
|  ⊹                   |
|                      |` },
    { name: '😊 Smiley', art: `    ████████
  ██        ██
 ██  ██  ██  ██
██              ██
██   ██    ██   ██
██              ██
 ██  ██████████ ██
  ██          ██
    ████████    ` },
    { name: '🌟 Star', art: `    ★
   ███
  █████
 ███████
█████████
 ███████
  █████
   ███
    █    ` },
];

interface LoadScreenProps {
    onLoad: (grid: Grid) => void;
    onNew: () => void;
    onPaste: (ansiText: string) => void;
}

export const LoadScreen: React.FC<LoadScreenProps> = ({ onLoad, onNew, onPaste }) => {
    const [saves] = useState<SavedArt[]>(getSavedArt());
    const [pasteText, setPasteText] = useState('');

    const handleDemoLoad = (art: string) => {
        const grid = gridFromAscii(art);
        onLoad(grid);
    };

    const formatDate = (timestamp: number) => {
        const date = new Date(timestamp);
        return date.toLocaleString();
    };

    const handleDelete = (id: string, e: React.MouseEvent) => {
        e.stopPropagation();
        deleteSavedArt(id);
        window.location.reload();
    };

    const handlePaste = () => {
        if (pasteText.trim()) {
            onPaste(pasteText.trim());
        }
    };

    return (
        <div style={{
            display: 'flex',
            flexDirection: 'column',
            gap: '1.5rem',
            padding: '2rem',
            width: '100%',
            maxWidth: '900px',
            margin: '0 auto',
        }}>
            <h2>ANSI Color Paint</h2>

            <div>
                <h3>Demo Templates</h3>
                <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
                    {demoArt.map((demo, idx) => (
                        <button
                            key={idx}
                            onClick={() => handleDemoLoad(demo.art)}
                            style={{ flex: '1 1 calc(33% - 0.5rem)', minWidth: '150px' }}
                        >
                            {demo.name}
                        </button>
                    ))}
                </div>
            </div>

            <div>
                <h3>Recent Saves</h3>
                {saves.length > 0 ? (
                    <div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                        {saves.map((save) => (
                            <div
                                key={save.id}
                                onClick={() => onLoad(save.grid)}
                                style={{
                                    border: '2px solid var(--regular3)',
                                    borderRadius: '4px',
                                    padding: '1rem',
                                    cursor: 'pointer',
                                    display: 'flex',
                                    justifyContent: 'space-between',
                                    alignItems: 'center',
                                    transition: 'border-color 0.2s',
                                }}
                                onMouseEnter={(e) => {
                                    e.currentTarget.style.borderColor = 'var(--regular6)';
                                }}
                                onMouseLeave={(e) => {
                                    e.currentTarget.style.borderColor = 'var(--regular3)';
                                }}
                            >
                                <div>
                                    <div style={{ fontWeight: 'bold', marginBottom: '0.25rem' }}>
                                        {save.name}
                                    </div>
                                    <div style={{ fontSize: '0.9rem', opacity: 0.7 }}>
                                        {formatDate(save.timestamp)}
                                    </div>
                                </div>
                                <button
                                    onClick={(e) => handleDelete(save.id, e)}
                                    style={{
                                        padding: '0.25rem 0.5rem',
                                        fontSize: '0.9rem',
                                        width: 'auto',
                                        minWidth: 'fit-content',
                                    }}
                                >
                                    Delete
                                </button>
                            </div>
                        ))}
                    </div>
                ) : (
                    <p style={{ opacity: 0.7 }}>No saves yet</p>
                )}
            </div>

            <div>
                <h3>Import from ANSI Text</h3>
                <textarea
                    value={pasteText}
                    onChange={(e) => setPasteText(e.target.value)}
                    placeholder="Paste ANSI art here..."
                    style={{ width: '100%', minHeight: '100px', marginBottom: '0.5rem' }}
                />
                <button onClick={handlePaste} disabled={!pasteText.trim()}>
                    Import
                </button>
            </div>
        </div>
    );
};