Implemented. Sign in, then open Experience or Skills to:
- Add, edit, and delete experience entries and project links. - Manage skill categories and individual skill labels. - Edit the skills introduction and “How I work” text. Changes save directly to Supabase—no code edits or Git push needed. Existing content is preserved.
This commit is contained in:
@@ -108,12 +108,14 @@ export default function AdminProvider({ children }) {
|
||||
{open && <Modal title={isAdmin ? "Admin account" : "Admin sign in"} onClose={close} busy={busy}>
|
||||
{isAdmin ? <div className="admin-account">
|
||||
<span className="publisher-badge"><span /> Admin</span>
|
||||
<p>You can create, edit, and delete journal articles.</p>
|
||||
<p>Manage your articles, experience, and skills.</p>
|
||||
<Link className="button button--primary" to="/blog/manage" onClick={close}><Icon name="plus" size={18} /> New article</Link>
|
||||
<Link className="button" to="/blog" onClick={close}>Manage articles</Link>
|
||||
<Link className="button" to="/experience" onClick={close}>Manage experience</Link>
|
||||
<Link className="button" to="/skills" onClick={close}>Manage skills</Link>
|
||||
<button className="text-button" type="button" onClick={signOut}><Icon name="logout" size={18} /> Sign out</button>
|
||||
</div> : <form className="admin-signin" onSubmit={signIn}>
|
||||
<p>Enter the admin password to manage journal articles.</p>
|
||||
<p>Enter the admin password to manage your website content.</p>
|
||||
<label className="publisher-field">
|
||||
<span>Admin password</span>
|
||||
<input autoFocus autoComplete="current-password" type="password" required maxLength={200}
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function ArticleAdminActions({ post, onDeleted }) {
|
||||
<Icon name="trash" size={16} /> Delete
|
||||
</button>
|
||||
{confirming && <Modal title="Delete article?" onClose={() => setConfirming(false)} busy={busy}>
|
||||
<p>“{post.title}” will be removed from the journal. This cannot be undone.</p>
|
||||
<p>“{post.title}” and its uploaded files will be deleted. Files used by another article will be kept. This cannot be undone.</p>
|
||||
{error && <p className="form-status form-status--error" role="alert">{error}</p>}
|
||||
<div className="dialog-actions">
|
||||
<button autoFocus className="button" type="button" disabled={busy} onClick={() => setConfirming(false)}>Cancel</button>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import { mediaUrl } from "../api";
|
||||
import Icon from "./Icon";
|
||||
import AttachmentList from "./AttachmentList";
|
||||
|
||||
const imageTypes = ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
||||
const isImage = (file) => imageTypes.includes(file.type) || (!file.type && /\.(jpe?g|png|webp|gif)$/i.test(file.name));
|
||||
@@ -147,17 +148,7 @@ export default function ArticleUploads({ banner, attachments, busy, title, subti
|
||||
<div className="upload-section">
|
||||
<div className="upload-section__heading"><div><h3>Additional photos & files</h3><p>Shown below your article, in this order.</p></div><span className="upload-label">{attachmentCount}/10</span></div>
|
||||
<Dropzone purpose="attachment" disabled={busy || attachmentCount >= 10} onFiles={addFiles} />
|
||||
{attachments.length > 0 && <ul className="upload-list">
|
||||
{attachments.map((file, index) => <li key={file.url}>
|
||||
<span className="upload-file-icon">{file.media_type.startsWith("image/") ? <img src={mediaUrl(file)} alt="" /> : <Icon name="file" size={24} />}</span>
|
||||
<div className="upload-file-info"><strong>{file.name}</strong><small>{fileSize(file.size)} · <span className="upload-ready">Ready</span></small></div>
|
||||
<div className="upload-file-actions">
|
||||
<button type="button" className="upload-icon-button" disabled={index === 0} aria-label={`Move ${file.name} up`} title="Move up" onClick={() => onMoveAttachment(file.url, -1)}><Icon name="up" size={17} /></button>
|
||||
<button type="button" className="upload-icon-button" disabled={index === attachments.length - 1} aria-label={`Move ${file.name} down`} title="Move down" onClick={() => onMoveAttachment(file.url, 1)}><Icon name="down" size={17} /></button>
|
||||
<button type="button" className="upload-icon-button" aria-label={`Remove ${file.name}`} title="Remove file" onClick={() => onRemoveAttachment(file.url)}><Icon name="close" size={17} /></button>
|
||||
</div>
|
||||
</li>)}
|
||||
</ul>}
|
||||
{attachments.length > 0 && <AttachmentList attachments={attachments} busy={busy} onMove={onMoveAttachment} onRemove={onRemoveAttachment} formatSize={fileSize} />}
|
||||
</div>
|
||||
|
||||
{messages.length > 0 && <div className="upload-feedback" role="alert"><strong>Some files could not be added</strong><ul>{messages.map((message, index) => <li key={index}>{message}</li>)}</ul><button type="button" className="text-button" onClick={() => setMessages([])}>Dismiss</button></div>}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { useState } from "react";
|
||||
import { DndContext, KeyboardSensor, MouseSensor, TouchSensor, closestCenter, useSensor, useSensors } from "@dnd-kit/core";
|
||||
import { SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import { mediaUrl } from "../api";
|
||||
import Icon from "./Icon";
|
||||
|
||||
const verticalDrag = ({ transform }) => ({ ...transform, x: 0 });
|
||||
|
||||
function SortableAttachment({ file, busy, canSort, sorting, onRemove, formatSize }) {
|
||||
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
|
||||
id: file.url, disabled: !canSort, transition: { duration: 180, easing: "ease" },
|
||||
});
|
||||
return <li ref={setNodeRef} className={`upload-sortable ${isDragging ? "is-sorting" : ""} ${!canSort ? "is-disabled" : ""}`}
|
||||
style={{ transform: CSS.Transform.toString(transform), transition }}
|
||||
onDragStart={(event) => event.preventDefault()}
|
||||
onMouseDown={(event) => {
|
||||
// Keep touch scrolling available on the row, with dragging on the handle.
|
||||
if (!event.target.closest("button")) listeners?.onMouseDown?.(event);
|
||||
}}>
|
||||
<button ref={setActivatorNodeRef} type="button" className="upload-drag-handle"
|
||||
{...attributes} {...listeners} disabled={!canSort} aria-label={`Reorder ${file.name}`}
|
||||
title="Drag to reorder. Or press Space, use arrow keys, then Space to drop.">
|
||||
<Icon name="grip" size={18} />
|
||||
</button>
|
||||
<span className="upload-file-icon">{file.media_type.startsWith("image/") ? <img src={mediaUrl(file)} alt="" draggable={false} /> : <Icon name="file" size={24} />}</span>
|
||||
<div className="upload-file-info"><strong>{file.name}</strong><small>{formatSize(file.size)} · <span className="upload-ready">Ready</span></small></div>
|
||||
<button type="button" className="upload-icon-button" disabled={busy || sorting}
|
||||
aria-label={`Remove ${file.name}`} title="Remove file" onClick={() => onRemove(file.url)}><Icon name="close" size={17} /></button>
|
||||
</li>;
|
||||
}
|
||||
|
||||
export default function AttachmentList({ attachments, busy, onMove, onRemove, formatSize }) {
|
||||
const [activeId, setActiveId] = useState(null);
|
||||
const sensors = useSensors(
|
||||
useSensor(MouseSensor, { activationConstraint: { distance: 6 } }),
|
||||
useSensor(TouchSensor, { activationConstraint: { delay: 150, tolerance: 5 } }),
|
||||
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates, scrollBehavior: "auto" }),
|
||||
);
|
||||
const describe = (id) => attachments.find((file) => file.url === id)?.name ?? "File";
|
||||
const position = (id) => attachments.findIndex((file) => file.url === id) + 1;
|
||||
return <>
|
||||
{attachments.length > 1 && <p className="upload-tip upload-sort-hint">Drag to reorder. Keyboard: <kbd>Space</kbd> to pick up, <kbd>↑</kbd>/<kbd>↓</kbd> to move, <kbd>Space</kbd> to drop.</p>}
|
||||
<DndContext sensors={sensors} collisionDetection={closestCenter} modifiers={[verticalDrag]}
|
||||
accessibility={{
|
||||
screenReaderInstructions: { draggable: "Press Space to pick up a file, arrow keys to move it, and Space to drop. Press Escape to cancel." },
|
||||
announcements: {
|
||||
onDragStart: ({ active }) => `Picked up ${describe(active.id)}, position ${position(active.id)} of ${attachments.length}.`,
|
||||
onDragOver: ({ active, over }) => over ? `${describe(active.id)}, position ${position(over.id)} of ${attachments.length}.` : undefined,
|
||||
onDragEnd: ({ active, over }) => over ? `Dropped ${describe(active.id)} at position ${position(over.id)} of ${attachments.length}.` : "Reordering canceled.",
|
||||
onDragCancel: () => "Reordering canceled. File order unchanged.",
|
||||
},
|
||||
}}
|
||||
onDragStart={({ active }) => setActiveId(active.id)}
|
||||
onDragCancel={() => setActiveId(null)}
|
||||
onDragEnd={({ active, over }) => {
|
||||
setActiveId(null);
|
||||
if (!busy && over && active.id !== over.id) onMove(active.id, over.id);
|
||||
}}>
|
||||
<SortableContext items={attachments.map((file) => file.url)} strategy={verticalListSortingStrategy}>
|
||||
<ul className="upload-list upload-sortable-list" aria-label="Attachment order">
|
||||
{attachments.map((file) => <SortableAttachment key={file.url} file={file} formatSize={formatSize}
|
||||
busy={busy} canSort={!busy && attachments.length > 1} sorting={activeId !== null} onRemove={onRemove} />)}
|
||||
</ul>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</>;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
const paths = {
|
||||
grip: <path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" strokeWidth="3" />,
|
||||
upload: <path d="M12 16V3m-5 5 5-5 5 5M4 16v5h16v-5" />,
|
||||
photo: <><rect x="3" y="3" width="18" height="18" rx="3" /><circle cx="8" cy="8" r="1.5" /><path d="m3 17 6-6 4 4 3-3 5 5" /></>,
|
||||
file: <><path d="M14 2H5v20h14V7l-5-5Zm0 0v6h5M8 13h8M8 17h5" /></>,
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useState } from "react";
|
||||
import { createExperience, updateExperience, createSkillCategory, updateSkillCategory, updateSkillsOverview } from "../api";
|
||||
import { useAdmin } from "./AdminSession";
|
||||
import Icon from "./Icon";
|
||||
import Modal from "./Modal";
|
||||
|
||||
const lines = (text) => text.split("\n").map((line) => line.trim()).filter(Boolean);
|
||||
|
||||
function EditorDialog({ title, children, onClose, onSave, onSaved, submitLabel = "Save changes", destructive = false }) {
|
||||
const { token, isAdmin, openSignIn } = useAdmin();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
if (busy || !isAdmin) return;
|
||||
setBusy(true); setError("");
|
||||
try { const result = await onSave(token); onSaved(result); }
|
||||
catch (problem) { setError(problem.message); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <Modal title={title} busy={busy} onClose={onClose}>
|
||||
<form className="portfolio-editor" onSubmit={submit}>
|
||||
<fieldset disabled={busy || !isAdmin}>{children}</fieldset>
|
||||
{error && <p className="form-status form-status--error" role="alert">{error}</p>}
|
||||
{!isAdmin && <p className="form-status" role="status">Sign in again to save. Your edits are still here.</p>}
|
||||
<div className="dialog-actions">
|
||||
<button type="button" className="button" disabled={busy} onClick={onClose}>Cancel</button>
|
||||
{isAdmin ? <button type="submit" className={`button ${destructive ? "button--danger" : "button--primary"}`} disabled={busy}>{busy ? "Saving…" : submitLabel}</button>
|
||||
: <button type="button" className="button button--primary" onClick={openSignIn}>Sign in</button>}
|
||||
</div>
|
||||
</form>
|
||||
</Modal>;
|
||||
}
|
||||
|
||||
export function ContentActions({ label, onEdit, onDelete }) {
|
||||
return <div className="portfolio-item-actions">
|
||||
<button type="button" className="text-button" aria-label={`Edit ${label}`} onClick={onEdit}><Icon name="edit" size={15} /> Edit</button>
|
||||
<button type="button" className="text-button text-button--danger" aria-label={`Delete ${label}`} onClick={onDelete}><Icon name="trash" size={15} /> Delete</button>
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function DeleteContentDialog({ label, onDelete, onClose, onDeleted }) {
|
||||
return <EditorDialog title="Delete this entry?" destructive submitLabel="Delete entry" onClose={onClose} onSave={onDelete} onSaved={onDeleted}>
|
||||
<p>“{label}” will be removed from the website. This cannot be undone.</p>
|
||||
</EditorDialog>;
|
||||
}
|
||||
|
||||
function TagEditor({ label, items, onChange, limit }) {
|
||||
const [text, setText] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
function add() {
|
||||
const value = text.trim();
|
||||
if (!value) return;
|
||||
if (items.some((item) => item.toLowerCase() === value.toLowerCase())) { setMessage("Already added."); return; }
|
||||
if (items.length >= limit) { setMessage(`You can add up to ${limit} labels.`); return; }
|
||||
onChange([...items, value]); setText(""); setMessage("");
|
||||
}
|
||||
return <div className="portfolio-tags-editor">
|
||||
<label className="publisher-field"><span>{label}</span>
|
||||
<input value={text} maxLength={100} placeholder="Type a label and press Enter" onChange={(event) => { setText(event.target.value); setMessage(""); }}
|
||||
onKeyDown={(event) => { if (event.key === "Enter" && !event.nativeEvent.isComposing) { event.preventDefault(); add(); } }} />
|
||||
</label>
|
||||
<div className="portfolio-tag-list">{items.map((item) => <span key={item}>{item}<button type="button" aria-label={`Remove ${item}`} onClick={() => onChange(items.filter((value) => value !== item))}><Icon name="close" size={13} /></button></span>)}</div>
|
||||
<div className="portfolio-tag-help"><small>Press Enter to add. Use × to remove.</small><button type="button" className="text-button" onClick={add}>Add label</button></div>
|
||||
{message && <small role="status">{message}</small>}
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function ExperienceEditor({ item, onClose, onSaved }) {
|
||||
const [value, setValue] = useState(() => ({ company: item?.company ?? "", role: item?.role ?? "", location: item?.location ?? "", start: item?.start ?? "", end: item?.end ?? "", summary: item?.summary ?? "", technologies: item?.technologies ?? [], projects: item?.projects ?? [] }));
|
||||
const [current, setCurrent] = useState(!item?.end);
|
||||
const [highlights, setHighlights] = useState((item?.highlights ?? []).join("\n"));
|
||||
const field = (name) => ({ value: value[name], onChange: (event) => setValue((before) => ({ ...before, [name]: event.target.value })) });
|
||||
const projectField = (index, name, text) => setValue((before) => ({ ...before, projects: before.projects.map((project, i) => i === index ? { ...project, [name]: text } : project) }));
|
||||
function save(token) {
|
||||
if (!current && value.end < value.start) throw new Error("End date must be on or after the start date.");
|
||||
const payload = { ...value, end: current ? null : value.end, highlights: lines(highlights) };
|
||||
return item ? updateExperience(item.id, payload, token) : createExperience(payload, token);
|
||||
}
|
||||
return <EditorDialog title={item ? "Edit experience" : "Add experience"} onClose={onClose} onSave={save} onSaved={onSaved} submitLabel={item ? "Save changes" : "Add experience"}>
|
||||
<label className="publisher-field"><span>Role</span><input autoFocus required maxLength={200} {...field("role")} /></label>
|
||||
<div className="portfolio-form-grid">
|
||||
<label className="publisher-field"><span>Company</span><input required maxLength={100} {...field("company")} /></label>
|
||||
<label className="publisher-field"><span>Location</span><input required maxLength={200} {...field("location")} /></label>
|
||||
<label className="publisher-field"><span>Start date</span><input type="month" required {...field("start")} /></label>
|
||||
<label className="publisher-field"><span>End date</span><input type="month" min={value.start || undefined} required={!current} disabled={current} {...field("end")} /></label>
|
||||
</div>
|
||||
<label className="portfolio-checkbox"><input type="checkbox" checked={current} onChange={(event) => setCurrent(event.target.checked)} /> I currently work here</label>
|
||||
<label className="publisher-field"><span>Summary</span><textarea aria-label="Summary" required rows={4} maxLength={4000} {...field("summary")} /></label>
|
||||
<label className="publisher-field"><span>Highlights — one per line</span><textarea aria-label="Highlights" rows={5} value={highlights} onChange={(event) => setHighlights(event.target.value)} /></label>
|
||||
<TagEditor label="Technologies" items={value.technologies} limit={60} onChange={(technologies) => setValue((before) => ({ ...before, technologies }))} />
|
||||
<div className="portfolio-projects">
|
||||
<div className="portfolio-section-heading"><strong>Project links</strong><button type="button" className="text-button" disabled={value.projects.length >= 20} onClick={() => setValue((before) => ({ ...before, projects: [...before.projects, { name: "", href: "", period: "" }] }))}><Icon name="plus" size={15} /> Add project</button></div>
|
||||
{value.projects.map((project, index) => <div className="portfolio-project" key={index}>
|
||||
<label className="publisher-field"><span>Project name</span><input required maxLength={100} value={project.name} onChange={(event) => projectField(index, "name", event.target.value)} /></label>
|
||||
<label className="publisher-field"><span>Project URL</span><input required type="url" placeholder="https://" value={project.href} onChange={(event) => projectField(index, "href", event.target.value)} /></label>
|
||||
<label className="publisher-field"><span>Project period (optional)</span><input maxLength={100} value={project.period} onChange={(event) => projectField(index, "period", event.target.value)} /></label>
|
||||
<button type="button" className="text-button text-button--danger" onClick={() => setValue((before) => ({ ...before, projects: before.projects.filter((_, i) => i !== index) }))}>Remove project</button>
|
||||
</div>)}
|
||||
</div>
|
||||
</EditorDialog>;
|
||||
}
|
||||
|
||||
export function SkillCategoryEditor({ item, onClose, onSaved }) {
|
||||
const [value, setValue] = useState({ name: item?.name ?? "", description: item?.description ?? "", accent: item?.accent ?? "mint", items: item?.items ?? [] });
|
||||
const field = (name) => ({ value: value[name], onChange: (event) => setValue((before) => ({ ...before, [name]: event.target.value })) });
|
||||
return <EditorDialog title={item ? "Edit skill category" : "Add skill category"} onClose={onClose} onSave={(token) => item ? updateSkillCategory(item.id, value, token) : createSkillCategory(value, token)} onSaved={onSaved} submitLabel={item ? "Save changes" : "Add category"}>
|
||||
<label className="publisher-field"><span>Category name</span><input autoFocus required maxLength={100} {...field("name")} /></label>
|
||||
<label className="publisher-field"><span>Description</span><textarea aria-label="Description" required rows={3} maxLength={1000} {...field("description")} /></label>
|
||||
<label className="publisher-field"><span>Card color</span><select {...field("accent")}>{["mint", "blue", "lavender", "peach", "yellow"].map((color) => <option key={color} value={color}>{color[0].toUpperCase() + color.slice(1)}</option>)}</select></label>
|
||||
<TagEditor label="Skills" items={value.items} limit={100} onChange={(items) => setValue((before) => ({ ...before, items }))} />
|
||||
</EditorDialog>;
|
||||
}
|
||||
|
||||
export function SkillsOverviewEditor({ skills, onClose, onSaved }) {
|
||||
const [intro, setIntro] = useState(skills.intro);
|
||||
const [principles, setPrinciples] = useState(skills.principles.join("\n"));
|
||||
return <EditorDialog title="Edit skills overview" onClose={onClose} onSave={(token) => updateSkillsOverview({ intro, principles: lines(principles) }, token)} onSaved={onSaved}>
|
||||
<label className="publisher-field"><span>Introduction</span><textarea aria-label="Introduction" autoFocus required rows={4} maxLength={2000} value={intro} onChange={(event) => setIntro(event.target.value)} /></label>
|
||||
<label className="publisher-field"><span>How I work — one principle per line</span><textarea aria-label="How I work" rows={6} value={principles} onChange={(event) => setPrinciples(event.target.value)} /></label>
|
||||
</EditorDialog>;
|
||||
}
|
||||
Reference in New Issue
Block a user