mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00
refactor(react/dialogs): solve some type errors
This commit is contained in:
parent
2ad4b26c9e
commit
edd18b53d0
@ -1,4 +1,4 @@
|
|||||||
import type { FullRevision, RevisionItem } from "@triliumnext/commons";
|
import type { RevisionPojo, RevisionItem } from "@triliumnext/commons";
|
||||||
import appContext, { EventData } from "../../components/app_context";
|
import appContext, { EventData } from "../../components/app_context";
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import dialog, { closeActiveDialog, openDialog } from "../../services/dialog";
|
import dialog, { closeActiveDialog, openDialog } from "../../services/dialog";
|
||||||
@ -91,20 +91,20 @@ function RevisionsList({ revisions, onSelect }: { revisions: RevisionItem[], onS
|
|||||||
title={t("revisions.revision_last_edited", { date: item.dateLastEdited })}
|
title={t("revisions.revision_last_edited", { date: item.dateLastEdited })}
|
||||||
value={item.revisionId}
|
value={item.revisionId}
|
||||||
>
|
>
|
||||||
{item.dateLastEdited.substr(0, 16)} ({utils.formatSize(item.contentLength)})
|
{item.dateLastEdited && item.dateLastEdited.substr(0, 16)} ({item.contentLength && utils.formatSize(item.contentLength)})
|
||||||
</FormListItem>
|
</FormListItem>
|
||||||
)}
|
)}
|
||||||
</FormList>);
|
</FormList>);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RevisionPreview({ revisionItem }: { revisionItem?: RevisionItem}) {
|
function RevisionPreview({ revisionItem }: { revisionItem?: RevisionItem}) {
|
||||||
const [ fullRevision, setFullRevision ] = useState<FullRevision>();
|
const [ fullRevision, setFullRevision ] = useState<RevisionPojo>();
|
||||||
const [ needsRefresh, setNeedsRefresh ] = useState<boolean>();
|
const [ needsRefresh, setNeedsRefresh ] = useState<boolean>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNeedsRefresh(false);
|
setNeedsRefresh(false);
|
||||||
if (revisionItem) {
|
if (revisionItem) {
|
||||||
server.get<FullRevision>(`revisions/${revisionItem.revisionId}`).then(setFullRevision);
|
server.get<RevisionPojo>(`revisions/${revisionItem.revisionId}`).then(setFullRevision);
|
||||||
} else {
|
} else {
|
||||||
setFullRevision(undefined);
|
setFullRevision(undefined);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,11 @@ function RevisionPreview({ revisionItem }: { revisionItem?: RevisionItem}) {
|
|||||||
primary
|
primary
|
||||||
icon="bx bx-download"
|
icon="bx bx-download"
|
||||||
text={t("revisions.download_button")}
|
text={t("revisions.download_button")}
|
||||||
onClick={() => open.downloadRevision(revisionItem.noteId, revisionItem.revisionId)} />
|
onClick={() => {
|
||||||
|
if (revisionItem.revisionId) {
|
||||||
|
open.downloadRevision(revisionItem.noteId, revisionItem.revisionId)}
|
||||||
|
}
|
||||||
|
}/>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</div>)}
|
</div>)}
|
||||||
@ -167,12 +171,12 @@ const CODE_STYLE: CSSProperties = {
|
|||||||
whiteSpace: "pre-wrap"
|
whiteSpace: "pre-wrap"
|
||||||
};
|
};
|
||||||
|
|
||||||
function RevisionContent({ revisionItem, fullRevision }: { revisionItem?: RevisionItem, fullRevision?: FullRevision }) {
|
function RevisionContent({ revisionItem, fullRevision }: { revisionItem?: RevisionItem, fullRevision?: RevisionPojo }) {
|
||||||
if (!revisionItem || !fullRevision) {
|
const content = fullRevision?.content;
|
||||||
|
if (!revisionItem || !content) {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = fullRevision.content;
|
|
||||||
|
|
||||||
switch (revisionItem.type) {
|
switch (revisionItem.type) {
|
||||||
case "text": {
|
case "text": {
|
||||||
@ -182,7 +186,7 @@ function RevisionContent({ revisionItem, fullRevision }: { revisionItem?: Revisi
|
|||||||
renderMathInElement(contentRef.current, { trust: true });
|
renderMathInElement(contentRef.current, { trust: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return <div ref={contentRef} className="ck-content" dangerouslySetInnerHTML={{ __html: content }}></div>
|
return <div ref={contentRef} className="ck-content" dangerouslySetInnerHTML={{ __html: content as string }}></div>
|
||||||
}
|
}
|
||||||
case "code":
|
case "code":
|
||||||
return <pre style={CODE_STYLE}>{content}</pre>;
|
return <pre style={CODE_STYLE}>{content}</pre>;
|
||||||
@ -190,7 +194,7 @@ function RevisionContent({ revisionItem, fullRevision }: { revisionItem?: Revisi
|
|||||||
switch (revisionItem.mime) {
|
switch (revisionItem.mime) {
|
||||||
case "image/svg+xml": {
|
case "image/svg+xml": {
|
||||||
//Base64 of other format images may be embedded in svg
|
//Base64 of other format images may be embedded in svg
|
||||||
const encodedSVG = encodeURIComponent(content);
|
const encodedSVG = encodeURIComponent(content as string);
|
||||||
return <img
|
return <img
|
||||||
src={`data:${fullRevision.mime};utf8,${encodedSVG}`}
|
src={`data:${fullRevision.mime};utf8,${encodedSVG}`}
|
||||||
style={IMAGE_STYLE} />;
|
style={IMAGE_STYLE} />;
|
||||||
@ -211,7 +215,7 @@ function RevisionContent({ revisionItem, fullRevision }: { revisionItem?: Revisi
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{t("revisions.file_size")}</th>
|
<th>{t("revisions.file_size")}</th>
|
||||||
<td>{utils.formatSize(revisionItem.contentLength)}</td>
|
<td>{revisionItem.contentLength && utils.formatSize(revisionItem.contentLength)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{fullRevision.content &&
|
{fullRevision.content &&
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -7,7 +7,7 @@ import becca from "../becca.js";
|
|||||||
import AbstractBeccaEntity from "./abstract_becca_entity.js";
|
import AbstractBeccaEntity from "./abstract_becca_entity.js";
|
||||||
import sql from "../../services/sql.js";
|
import sql from "../../services/sql.js";
|
||||||
import BAttachment from "./battachment.js";
|
import BAttachment from "./battachment.js";
|
||||||
import type { AttachmentRow, NoteType, RevisionRow } from "@triliumnext/commons";
|
import type { AttachmentRow, NoteType, RevisionPojo, RevisionRow } from "@triliumnext/commons";
|
||||||
import eraseService from "../../services/erase.js";
|
import eraseService from "../../services/erase.js";
|
||||||
|
|
||||||
interface ContentOpts {
|
interface ContentOpts {
|
||||||
@ -201,7 +201,7 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
|
|||||||
utcDateModified: this.utcDateModified,
|
utcDateModified: this.utcDateModified,
|
||||||
content: this.content, // used when retrieving full note revision to frontend
|
content: this.content, // used when retrieving full note revision to frontend
|
||||||
contentLength: this.contentLength
|
contentLength: this.contentLength
|
||||||
};
|
} satisfies RevisionPojo;
|
||||||
}
|
}
|
||||||
|
|
||||||
override getPojoToSave() {
|
override getPojoToSave() {
|
||||||
|
@ -12,7 +12,7 @@ import type { Request, Response } from "express";
|
|||||||
import type BRevision from "../../becca/entities/brevision.js";
|
import type BRevision from "../../becca/entities/brevision.js";
|
||||||
import type BNote from "../../becca/entities/bnote.js";
|
import type BNote from "../../becca/entities/bnote.js";
|
||||||
import type { NotePojo } from "../../becca/becca-interface.js";
|
import type { NotePojo } from "../../becca/becca-interface.js";
|
||||||
import { RevisionItem, RevisionRow } from "@triliumnext/commons";
|
import { RevisionItem, RevisionPojo, RevisionRow } from "@triliumnext/commons";
|
||||||
|
|
||||||
interface NotePath {
|
interface NotePath {
|
||||||
noteId: string;
|
noteId: string;
|
||||||
@ -60,7 +60,7 @@ function getRevision(req: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return revision satisfies RevisionRow;
|
return revision satisfies RevisionPojo;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRevisionFilename(revision: BRevision) {
|
function getRevisionFilename(revision: BRevision) {
|
||||||
|
@ -28,3 +28,20 @@ export interface RevisionItem {
|
|||||||
isProtected?: boolean;
|
isProtected?: boolean;
|
||||||
mime: string;
|
mime: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RevisionPojo {
|
||||||
|
revisionId?: string;
|
||||||
|
noteId: string;
|
||||||
|
type: NoteType;
|
||||||
|
mime: string;
|
||||||
|
isProtected?: boolean;
|
||||||
|
title: string;
|
||||||
|
blobId?: string;
|
||||||
|
dateLastEdited?: string;
|
||||||
|
dateCreated?: string;
|
||||||
|
utcDateLastEdited?: string;
|
||||||
|
utcDateCreated?: string;
|
||||||
|
utcDateModified?: string;
|
||||||
|
content?: string | Buffer<ArrayBufferLike>;
|
||||||
|
contentLength?: number;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user