feat(right_pane): hide PDF attachments/layers when not needed

This commit is contained in:
Elian Doran 2025-12-30 00:10:23 +02:00
parent 3c1beab725
commit f5a89aa81a
No known key found for this signature in database
2 changed files with 30 additions and 48 deletions

View File

@ -14,35 +14,28 @@ export default function PdfAttachments() {
const { note } = useActiveNoteContext();
const noteType = useNoteProperty(note, "type");
const noteMime = useNoteProperty(note, "mime");
const attachmentsData = useGetContextData("pdfAttachments");
if (noteType !== "file" || noteMime !== "application/pdf") {
return null;
}
return (
<RightPanelWidget id="pdf-attachments" title="Attachments">
<PdfAttachmentsList key={note?.noteId} />
</RightPanelWidget>
);
}
function PdfAttachmentsList() {
const attachmentsData = useGetContextData("pdfAttachments");
if (!attachmentsData || attachmentsData.attachments.length === 0) {
return <div className="no-attachments">No attachments</div>;
return null;
}
return (
<div className="pdf-attachments-list">
{attachmentsData.attachments.map((attachment) => (
<PdfAttachmentItem
key={attachment.filename}
attachment={attachment}
onDownload={attachmentsData.downloadAttachment}
/>
))}
</div>
<RightPanelWidget id="pdf-attachments" title="Attachments">
<div className="pdf-attachments-list">
{attachmentsData.attachments.map((attachment) => (
<PdfAttachmentItem
key={attachment.filename}
attachment={attachment}
onDownload={attachmentsData.downloadAttachment}
/>
))}
</div>
</RightPanelWidget>
);
}

View File

@ -14,47 +14,36 @@ export default function PdfLayers() {
const { note } = useActiveNoteContext();
const noteType = useNoteProperty(note, "type");
const noteMime = useNoteProperty(note, "mime");
const layersData = useGetContextData("pdfLayers");
if (noteType !== "file" || noteMime !== "application/pdf") {
return null;
}
return (
return (layersData?.layers && layersData.layers.length > 0 &&
<RightPanelWidget id="pdf-layers" title="Layers">
<PdfLayersList key={note?.noteId} />
<div className="pdf-layers-list">
{layersData.layers.map((layer) => (
<PdfLayerItem
key={layer.id}
layer={layer}
onToggle={layersData.toggleLayer}
/>
))}
</div>
</RightPanelWidget>
);
}
function PdfLayersList() {
const layersData = useGetContextData("pdfLayers");
if (!layersData || layersData.layers.length === 0) {
return <div className="no-layers">No layers</div>;
}
return (
<div className="pdf-layers-list">
{layersData.layers.map((layer) => (
<PdfLayerItem
key={layer.id}
layer={layer}
onToggle={layersData.toggleLayer}
/>
))}
</div>
);
}
function PdfLayerItem({
layer,
onToggle
}: {
layer: LayerInfo;
function PdfLayerItem({
layer,
onToggle
}: {
layer: LayerInfo;
onToggle: (layerId: string, visible: boolean) => void;
}) {
return (
<div
<div
className={`pdf-layer-item ${layer.visible ? 'visible' : 'hidden'}`}
onClick={() => onToggle(layer.id, !layer.visible)}
>