Skip to content

Commit

Permalink
Fix: resolve browser console errors and desktop functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Casm101 committed Dec 27, 2024
1 parent f47d410 commit 0d4ac69
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Stories - React Story Component</title>
</head>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@casm101/react-stories",
"description": "Simple and dynamic Metainspired story component in React!",
"private": false,
"version": "1.1.1",
"version": "1.1.2",
"type": "module",
"scripts": {
"dev": "vite --host",
Expand Down
10 changes: 6 additions & 4 deletions src/components/ProgressBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useState } from 'react';

// Style imports
Expand Down Expand Up @@ -43,9 +44,6 @@ export const ProgressBar = ({
interval = setInterval(() => {
setProgress(oldProgress => {
const newProgress = oldProgress + (50 / finalDuration) * 100;
if (newProgress >= 100) {
skipCallback();
}
return newProgress;
});
}, 50);
Expand All @@ -55,7 +53,11 @@ export const ProgressBar = ({
if (!isActive) setProgress(0);

return () => clearInterval(interval);
}, [isActive, duration, isPaused, progress, skipCallback, finalDuration]);
}, [isActive, duration, isPaused, finalDuration]);

useEffect(() => {
if (progress > 100) skipCallback();
}, [progress]);

return (
<div className="progressbar-styled">
Expand Down
17 changes: 10 additions & 7 deletions src/components/ReactStory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const ReactStory = ({
const [imagesPreload, setImagesPreload] = useState<string[]>([]);
const [videosPreload, setVideosPreload] = useState<string[]>([]);
const [videoDuration, setVideoDuration] = useState<number>(0);
const currentStoryType: TStoryMedia['type'] | TStoryCustom['type'] =
stories[currentStory].type;
const numStories = stories?.length;

// Declaration of local refrences
Expand Down Expand Up @@ -92,14 +94,11 @@ export const ReactStory = ({

// Function to toggle pause or video speed (on mouse down event)
const mouseDownAction = (e: React.MouseEvent | React.TouchEvent) => {
e.preventDefault();
e.cancelable && e.preventDefault();
const speedUpStory = (e.target as HTMLElement).closest('.speed-up-story');

console.log('speedUpStory: ', speedUpStory);

startYRef.current = (e as React.TouchEvent).touches[0].clientY;
if (e instanceof TouchEvent) startYRef.current = e.touches[0].clientY;
mousedownId.current = setTimeout(() => {
if (speedUpStory) setSpedUp(true);
if (speedUpStory && currentStoryType) setSpedUp(true);
if (!speedUpStory) setPause(true);
setHudHidden(true);
}, 200);
Expand All @@ -108,7 +107,7 @@ export const ReactStory = ({
// Function to toggle overlay visibility (on mouse up event)
const mouseUpAction =
(action: 'prev' | 'next') => (e: React.MouseEvent | React.TouchEvent) => {
e.preventDefault();
e.cancelable && e.preventDefault();
mousedownId.current && clearTimeout(mousedownId.current);

if ((e as React.TouchEvent).changedTouches) {
Expand Down Expand Up @@ -329,27 +328,31 @@ export const ReactStory = ({
onTouchEnd={mouseUpAction('prev')}
onMouseDown={mouseDownAction}
onMouseUp={mouseUpAction('prev')}
onContextMenu={e => e.preventDefault()}
/>
<div
className="next-story"
onTouchStart={mouseDownAction}
onTouchEnd={mouseUpAction('next')}
onMouseDown={mouseDownAction}
onMouseUp={mouseUpAction('next')}
onContextMenu={e => e.preventDefault()}
/>
<div
className="speed-up-story left"
onTouchStart={mouseDownAction}
onTouchEnd={mouseUpAction('prev')}
onMouseDown={mouseDownAction}
onMouseUp={mouseUpAction('prev')}
onContextMenu={e => e.preventDefault()}
/>
<div
className="speed-up-story right"
onTouchStart={mouseDownAction}
onTouchEnd={mouseUpAction('next')}
onMouseDown={mouseDownAction}
onMouseUp={mouseUpAction('next')}
onContextMenu={e => e.preventDefault()}
/>
</div>
</div>
Expand Down

0 comments on commit 0d4ac69

Please sign in to comment.