WIP memory editor

This commit is contained in:
2024-11-23 21:36:50 +01:00
parent dbc0068a82
commit 2c820f6ead
15 changed files with 467 additions and 37 deletions

View File

@@ -0,0 +1,96 @@
import React, { useState } from 'react';
import { SingleEntryEditor } from './SingleEntryEditor';
const EntryTypes = {
SINGLE: 'single'
};
export const MemoryEditor = ({
entries = [],
onCreateEntry,
onSaveEntry,
onDeleteEntry,
onResetEntry,
onUpdateEntry
}) => {
const [showCreateDialog, setShowCreateDialog] = useState(false);
const handleCreate = (_id, entry) => {
onCreateEntry(entry);
setShowCreateDialog(false);
};
const renderCreateDialog = () => {
const now = new Date();
const id = now.getFullYear() +
String(now.getMonth() + 1).padStart(2, '0') +
String(now.getDate()).padStart(2, '0') + '_' +
String(now.getHours()).padStart(2, '0') +
String(now.getMinutes()).padStart(2, '0') +
String(now.getSeconds()).padStart(2, '0') + '_' +
String(now.getMilliseconds()).padStart(3, '0');
const entry = {
type: EntryTypes.SINGLE,
id: id,
script: '',
timeout: null,
limit: null,
executed: false
};
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">
<div className="bg-white p-4 rounded-lg max-w-2xl w-full m-4">
<div className="flex justify-between items-center mb-4">
<h2 className="text-lg font-medium">Create New Entry</h2>
<button
onClick={() => setShowCreateDialog(false)}
className="text-gray-500 hover:text-gray-700"
>
</button>
</div>
<SingleEntryEditor
entry={entry}
isNew={true}
isEditing={true}
onSave={handleCreate}
onCancel={() => setShowCreateDialog(false)}
/>
</div>
</div>
);
};
return (
<div className="p-4">
<div className="flex justify-end mb-4">
<button
onClick={() => setShowCreateDialog(true)}
className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700"
>
Add Entry
</button>
</div>
<div className="space-y-4">
{entries.map(entry => (
<SingleEntryEditor
key={entry.id}
entry={entry}
isEditing={true}
onSave={onSaveEntry}
onDelete={onDeleteEntry}
onReset={onResetEntry}
onUpdate={onUpdateEntry}
/>
))}
</div>
{showCreateDialog && renderCreateDialog()}
</div>
);
};
export default MemoryEditor;