Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ interface HeaderProps {
handlePasteFromClipboard: () => void;
fileInputRef: React.RefObject<HTMLInputElement | null>;
handleFileUpload: (e: React.ChangeEvent<HTMLInputElement>) => void;
handleImportFileClick: () => void;
handleExport: () => void;
}

export const Header = ({
handlePasteFromClipboard,
fileInputRef,
handleFileUpload,
handleImportFileClick,
handleExport,
}: HeaderProps) => {
return (
Expand Down Expand Up @@ -43,7 +45,7 @@ export const Header = ({
onChange={handleFileUpload}
/>
<button
onClick={() => fileInputRef.current?.click()}
onClick={handleImportFileClick}
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 bg-slate-100 dark:bg-slate-800 hover:bg-slate-200 dark:hover:bg-slate-700 rounded-lg transition-colors"
>
<Upload size={16} /> <span className="hidden sm:inline">Import</span>
Expand Down
2 changes: 2 additions & 0 deletions components/ProtocolEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function ProtocolEditor({
sessionItems,
fileInputRef,
handleFileUpload,
handleImportFileClick,
handlePasteFromClipboard,
handleExport,
addTopic,
Expand Down Expand Up @@ -70,6 +71,7 @@ export function ProtocolEditor({
handlePasteFromClipboard={handlePasteFromClipboard}
fileInputRef={fileInputRef}
handleFileUpload={handleFileUpload}
handleImportFileClick={handleImportFileClick}
handleExport={handleExport}
/>

Expand Down
23 changes: 23 additions & 0 deletions hooks/useProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,29 @@ export const useProtocol = () => {
e.target.value = "";
};

const handleImportFileClick = () => {
if (sessionItems.length > 0) {
if (
!window.confirm(
"Das Importieren eines Protokolls überschreibt alle aktuellen Daten. Fortfahren?"
)
) {
return;
}
}
fileInputRef.current?.click();
};

const handlePasteFromClipboard = async () => {
if (sessionItems.length > 0) {
if (
!window.confirm(
"Das Einfügen aus der Zwischenablage überschreibt alle aktuellen Daten. Fortfahren?"
)
) {
return;
}
}
try {
const text = await navigator.clipboard.readText();
if (!text) return alert("Zwischenablage ist leer!");
Expand Down Expand Up @@ -183,6 +205,7 @@ export const useProtocol = () => {
setSessionItems,
fileInputRef,
handleFileUpload,
handleImportFileClick,
handlePasteFromClipboard,
handleExport,
addTopic,
Expand Down