mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-14 01:48:50 +01:00
Swipe to toggle poll results
This commit is contained in:
parent
535715cfe8
commit
963312aacb
3 changed files with 16 additions and 2 deletions
|
@ -15,6 +15,7 @@ import {
|
||||||
useNavigate,
|
useNavigate,
|
||||||
useParams,
|
useParams,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
import 'swiped-events';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
import AccountSheet from './components/account-sheet';
|
import AccountSheet from './components/account-sheet';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
|
|
||||||
import emojifyText from '../utils/emojify-text';
|
import emojifyText from '../utils/emojify-text';
|
||||||
import shortenNumber from '../utils/shorten-number';
|
import shortenNumber from '../utils/shorten-number';
|
||||||
|
@ -61,8 +61,22 @@ export default function Poll({
|
||||||
|
|
||||||
const [showResults, setShowResults] = useState(false);
|
const [showResults, setShowResults] = useState(false);
|
||||||
const optionsHaveVoteCounts = options.every((o) => o.votesCount !== null);
|
const optionsHaveVoteCounts = options.every((o) => o.votesCount !== null);
|
||||||
|
|
||||||
|
const pollRef = useRef();
|
||||||
|
useEffect(() => {
|
||||||
|
const handleSwipe = () => {
|
||||||
|
console.log('swiped left');
|
||||||
|
setShowResults(!showResults);
|
||||||
|
};
|
||||||
|
pollRef.current?.addEventListener?.('swiped-left', handleSwipe);
|
||||||
|
return () => {
|
||||||
|
pollRef.current?.removeEventListener?.('swiped-left', handleSwipe);
|
||||||
|
};
|
||||||
|
}, [showResults]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={pollRef}
|
||||||
lang={lang}
|
lang={lang}
|
||||||
dir="auto"
|
dir="auto"
|
||||||
class={`poll ${readOnly ? 'read-only' : ''} ${
|
class={`poll ${readOnly ? 'read-only' : ''} ${
|
||||||
|
|
|
@ -15,7 +15,6 @@ import pThrottle from 'p-throttle';
|
||||||
import { memo } from 'preact/compat';
|
import { memo } from 'preact/compat';
|
||||||
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
||||||
import { InView } from 'react-intersection-observer';
|
import { InView } from 'react-intersection-observer';
|
||||||
import 'swiped-events';
|
|
||||||
import { useLongPress } from 'use-long-press';
|
import { useLongPress } from 'use-long-press';
|
||||||
import useResizeObserver from 'use-resize-observer';
|
import useResizeObserver from 'use-resize-observer';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
Loading…
Reference in a new issue