diff --git a/CHANGELOG.md b/CHANGELOG.md index 65dcf688..215428f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - [#659](https://github.com/estruyf/vscode-front-matter/issues/659): Implement a filter for the taxonomy dashboard - [#662](https://github.com/estruyf/vscode-front-matter/issues/662): Always show the `all articles` tab with the page counter - [#663](https://github.com/estruyf/vscode-front-matter/issues/663): Make card tags clickable to filter the view +- [#669](https://github.com/estruyf/vscode-front-matter/issues/669): Add the video preview to the details panel + caption field ### ⚡️ Optimizations diff --git a/src/dashboardWebView/components/Media/DetailsSlideOver.tsx b/src/dashboardWebView/components/Media/DetailsSlideOver.tsx index 37a3796e..686c5aa3 100644 --- a/src/dashboardWebView/components/Media/DetailsSlideOver.tsx +++ b/src/dashboardWebView/components/Media/DetailsSlideOver.tsx @@ -23,6 +23,7 @@ export interface IDetailsSlideOverProps { media: MediaInfo; showForm: boolean; isImageFile: boolean; + isVideoFile: boolean; onEdit: () => void; onEditClose: () => void; onDismiss: () => void; @@ -38,7 +39,8 @@ export const DetailsSlideOver: React.FunctionComponent = onEdit, onEditClose, onDismiss, - isImageFile + isImageFile, + isVideoFile }: React.PropsWithChildren) => { const [filename, setFilename] = React.useState(media.filename); const [caption, setCaption] = React.useState(media.caption); @@ -136,9 +138,19 @@ export const DetailsSlideOver: React.FunctionComponent =
- {isImageFile && ( + {(isImageFile || isVideoFile) && (
- {media.filename} + { + isImageFile && ( + {media.filename} + ) + } + + { + isVideoFile && ( +
)}
@@ -211,25 +223,25 @@ export const DetailsSlideOver: React.FunctionComponent =
+ {(isImageFile || isVideoFile) && ( +
+ +
+ setCaption(e.target.value)} isTextArea /> +
+
+ )} {isImageFile && ( - <> -
- -
- setCaption(e.target.value)} isTextArea /> -
+
+ +
+ setAlt(e.target.value)} isTextArea />
-
- -
- setAlt(e.target.value)} isTextArea /> -
-
- +
)}
diff --git a/src/dashboardWebView/components/Media/Item.tsx b/src/dashboardWebView/components/Media/Item.tsx index c484c2e7..55d12c9a 100644 --- a/src/dashboardWebView/components/Media/Item.tsx +++ b/src/dashboardWebView/components/Media/Item.tsx @@ -701,6 +701,7 @@ export const Item: React.FunctionComponent = ({ media={media} showForm={showForm} isImageFile={isImageFile} + isVideoFile={isVideoFile} onEdit={() => setShowForm(true)} onEditClose={() => setShowForm(false)} onDismiss={() => { diff --git a/src/helpers/MediaHelpers.ts b/src/helpers/MediaHelpers.ts index 9698a031..427f3752 100644 --- a/src/helpers/MediaHelpers.ts +++ b/src/helpers/MediaHelpers.ts @@ -350,6 +350,8 @@ export class MediaHelpers { try { await unlinkAsync(file); + MediaLibrary.getInstance().remove(file); + MediaHelpers.media = []; return true; } catch (err: any) { diff --git a/src/helpers/MediaLibrary.ts b/src/helpers/MediaLibrary.ts index 5ba1dc88..60b70bcf 100644 --- a/src/helpers/MediaLibrary.ts +++ b/src/helpers/MediaLibrary.ts @@ -18,6 +18,7 @@ interface MediaRecord { export class MediaLibrary { private db: JsonDB | undefined; private renameFilesListener: Disposable | undefined; + private removeFilesListener: Disposable | undefined; private static instance: MediaLibrary; private constructor() { @@ -74,20 +75,26 @@ export class MediaLibrary { this.renameFilesListener = workspace.onDidRenameFiles((e) => { e.files.forEach(async (f) => { const path = f.oldUri.path.toLowerCase(); - const mimeType = lookup(path); - // Check if file is an image - if ( - mimeType && - (mimeType.startsWith('image/') || - mimeType.startsWith('video/') || - mimeType.startsWith('audio/') || - mimeType.startsWith('application/pdf')) - ) { + if (MediaLibrary.isMediaFile(path)) { await this.rename(f.oldUri.fsPath, f.newUri.fsPath); MediaHelpers.resetMedia(); } }); }); + + if (this.removeFilesListener) { + this.removeFilesListener.dispose(); + } + + this.removeFilesListener = workspace.onDidDeleteFiles((e) => { + e.files.forEach(async (f) => { + const path = f.path.toLowerCase(); + if (MediaLibrary.isMediaFile(path)) { + this.remove(f.fsPath); + MediaHelpers.resetMedia(); + } + }); + }); } public static getInstance(): MediaLibrary { @@ -138,6 +145,11 @@ export class MediaLibrary { } } + public async remove(path: string): Promise { + const fileId = this.parsePath(path); + await this.db?.delete(fileId); + } + public async updateFilename(filePath: string, filename: string) { const name = basename(filePath); @@ -167,4 +179,19 @@ export class MediaLibrary { absPath = isWindows ? absPath.split('\\').join('/') : absPath; return absPath.toLowerCase(); } + + private static isMediaFile(path: string) { + const mimeType = lookup(path); + // Check if file is an image + if ( + mimeType && + (mimeType.startsWith('image/') || + mimeType.startsWith('video/') || + mimeType.startsWith('audio/') || + mimeType.startsWith('application/pdf')) + ) { + return true; + } + return false; + } }