saving the export method to the browser storage. you can choose this
Some checks failed
Deploy / build-and-deploy (push) Failing after 1s
Some checks failed
Deploy / build-and-deploy (push) Failing after 1s
This commit is contained in:
@@ -79,6 +79,18 @@ export default function AdminPage() {
|
|||||||
const [previewHtml, setPreviewHtml] = useState('');
|
const [previewHtml, setPreviewHtml] = useState('');
|
||||||
const [editingPost, setEditingPost] = useState<{ slug: string, path: string } | null>(null);
|
const [editingPost, setEditingPost] = useState<{ slug: string, path: string } | null>(null);
|
||||||
const [isDocker, setIsDocker] = useState<boolean>(false);
|
const [isDocker, setIsDocker] = useState<boolean>(false);
|
||||||
|
const [rememberExportChoice, setRememberExportChoice] = useState<boolean>(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
return localStorage.getItem('rememberExportChoice') === 'true';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
const [lastExportChoice, setLastExportChoice] = useState<string | null>(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
return localStorage.getItem('lastExportChoice');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const usernameRef = useRef<HTMLInputElement>(null);
|
const usernameRef = useRef<HTMLInputElement>(null);
|
||||||
const passwordRef = useRef<HTMLInputElement>(null);
|
const passwordRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -98,6 +110,18 @@ export default function AdminPage() {
|
|||||||
localStorage.setItem('pinnedPosts', JSON.stringify(pinned));
|
localStorage.setItem('pinnedPosts', JSON.stringify(pinned));
|
||||||
}, [pinned]);
|
}, [pinned]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem('rememberExportChoice', rememberExportChoice.toString());
|
||||||
|
}, [rememberExportChoice]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (lastExportChoice) {
|
||||||
|
localStorage.setItem('lastExportChoice', lastExportChoice);
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem('lastExportChoice');
|
||||||
|
}
|
||||||
|
}, [lastExportChoice]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
gfm: true,
|
gfm: true,
|
||||||
@@ -491,6 +515,16 @@ export default function AdminPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleExportTarball() {
|
function handleExportTarball() {
|
||||||
|
// Check if we should use the remembered choice
|
||||||
|
if (rememberExportChoice && lastExportChoice) {
|
||||||
|
if (lastExportChoice === 'docker') {
|
||||||
|
exportFromEndpoint('/api/admin/export');
|
||||||
|
} else if (lastExportChoice === 'local') {
|
||||||
|
exportFromEndpoint('/api/admin/exportlocal');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create popup modal
|
// Create popup modal
|
||||||
const modal = document.createElement('div');
|
const modal = document.createElement('div');
|
||||||
modal.style.position = 'fixed';
|
modal.style.position = 'fixed';
|
||||||
@@ -522,11 +556,24 @@ export default function AdminPage() {
|
|||||||
<button id="docker-btn" style="padding: 10px 20px; background-color: #059669; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold;">Docker</button>
|
<button id="docker-btn" style="padding: 10px 20px; background-color: #059669; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold;">Docker</button>
|
||||||
<button id="local-btn" style="padding: 10px 20px; background-color: #2563eb; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold;">Local</button>
|
<button id="local-btn" style="padding: 10px 20px; background-color: #2563eb; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold;">Local</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="margin-top: 20px; display: flex; justify-content: center;">
|
||||||
|
<label style="display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9rem;">
|
||||||
|
<input type="checkbox" id="remember-choice" style="margin: 0;">
|
||||||
|
Remember my choice for next time
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
modal.appendChild(modalContent);
|
modal.appendChild(modalContent);
|
||||||
document.body.appendChild(modal);
|
document.body.appendChild(modal);
|
||||||
|
|
||||||
|
// Set the checkbox state
|
||||||
|
const rememberCheckbox = modal.querySelector('#remember-choice') as HTMLInputElement;
|
||||||
|
if (rememberCheckbox) {
|
||||||
|
rememberCheckbox.checked = rememberExportChoice;
|
||||||
|
}
|
||||||
|
|
||||||
// Add event listeners
|
// Add event listeners
|
||||||
const dockerBtn = modal.querySelector('#docker-btn');
|
const dockerBtn = modal.querySelector('#docker-btn');
|
||||||
const localBtn = modal.querySelector('#local-btn');
|
const localBtn = modal.querySelector('#local-btn');
|
||||||
@@ -536,14 +583,26 @@ export default function AdminPage() {
|
|||||||
document.body.removeChild(modal);
|
document.body.removeChild(modal);
|
||||||
};
|
};
|
||||||
|
|
||||||
dockerBtn?.addEventListener('click', () => {
|
const handleExport = (choice: string) => {
|
||||||
|
const shouldRemember = rememberCheckbox?.checked || false;
|
||||||
|
setRememberExportChoice(shouldRemember);
|
||||||
|
if (shouldRemember) {
|
||||||
|
setLastExportChoice(choice);
|
||||||
|
}
|
||||||
closeModal();
|
closeModal();
|
||||||
exportFromEndpoint('/api/admin/export');
|
if (choice === 'docker') {
|
||||||
|
exportFromEndpoint('/api/admin/export');
|
||||||
|
} else if (choice === 'local') {
|
||||||
|
exportFromEndpoint('/api/admin/exportlocal');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dockerBtn?.addEventListener('click', () => {
|
||||||
|
handleExport('docker');
|
||||||
});
|
});
|
||||||
|
|
||||||
localBtn?.addEventListener('click', () => {
|
localBtn?.addEventListener('click', () => {
|
||||||
closeModal();
|
handleExport('local');
|
||||||
exportFromEndpoint('/api/admin/exportlocal');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
closeBtn?.addEventListener('click', closeModal);
|
closeBtn?.addEventListener('click', closeModal);
|
||||||
@@ -575,6 +634,11 @@ export default function AdminPage() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearExportChoice = () => {
|
||||||
|
setRememberExportChoice(false);
|
||||||
|
setLastExportChoice(null);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-100 p-8">
|
<div className="min-h-screen bg-gray-100 p-8">
|
||||||
{pinFeedback && (
|
{pinFeedback && (
|
||||||
@@ -649,13 +713,27 @@ export default function AdminPage() {
|
|||||||
<span className="font-bold">Warning:</span> Docker is in use. Exporting will export the entire <span className="font-mono">/app</span> root directory (including all files and folders in the container's root).
|
<span className="font-bold">Warning:</span> Docker is in use. Exporting will export the entire <span className="font-mono">/app</span> root directory (including all files and folders in the container's root).
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<button
|
<div className="flex items-center gap-2">
|
||||||
onClick={handleExportTarball}
|
<button
|
||||||
className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700"
|
onClick={handleExportTarball}
|
||||||
title="Export Docker Posts"
|
className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700"
|
||||||
>
|
title="Export Docker Posts"
|
||||||
Export Posts
|
>
|
||||||
</button>
|
Export Posts
|
||||||
|
</button>
|
||||||
|
{rememberExportChoice && lastExportChoice && (
|
||||||
|
<div className="flex items-center gap-1 text-xs text-gray-600">
|
||||||
|
<span>💾 {lastExportChoice === 'docker' ? 'Docker' : 'Local'}</span>
|
||||||
|
<button
|
||||||
|
onClick={clearExportChoice}
|
||||||
|
className="text-red-500 hover:text-red-700"
|
||||||
|
title="Clear remembered choice"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user