Skip to content

Commit

Permalink
Fix: The video aspect ratio (maybe)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantasy-programming committed May 19, 2024
1 parent e8c33d0 commit d17730c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "only-refs",
"version": "0.0.5",
"version": "0.0.6",
"description": "",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -84,3 +84,4 @@
"vitest": "^1.6.0"
}
}

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "only-refs"
version = "0.0.5"
version = "0.0.6"
description = "All your references in a single place"
authors = ["Ngobo Ridy"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "only-refs",
"version": "0.0.5"
"version": "0.0.6"
},
"tauri": {
"allowlist": {
Expand Down
22 changes: 22 additions & 0 deletions src/components/ViewBox/ViewBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ import { ViewBoxZoom } from './ViewBoxZoom';
import { isMediaRef } from '~/lib/helper';

export const ViewBox: Component<ParentProps & { source: Ref }> = (props) => {
let videoRef: HTMLVideoElement | undefined;

const [videoDimensions, setVideoDimensions] = createSignal({
width: 0,
height: 0,
});

const handleVideoLoadedMetadata = () => {
if (videoRef) {
setVideoDimensions({
width: videoRef.videoWidth,
height: videoRef.videoHeight,
});
}
};

return (
<DialogContent
class={
Expand All @@ -33,12 +49,18 @@ export const ViewBox: Component<ParentProps & { source: Ref }> = (props) => {
<Switch>
<Match when={props.source.metadata.ref_type === 'video'}>
<video
ref={(el) => (videoRef = el)}
class="aspect-video h-auto w-auto rounded-xl"
src={(props.source as VideoRef).video_path}
preload="auto"
autoplay
controls
loop
onLoadedMetadata={handleVideoLoadedMetadata}
style={{
'max-width': `min(100%, ${videoDimensions().width}px)`,
'max-height': `min(100%, ${videoDimensions().height}px)`,
}}
></video>
</Match>
<Match when={props.source.metadata.ref_type === 'image'}>
Expand Down

0 comments on commit d17730c

Please sign in to comment.