-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #253 from DanielEmmanuel1/Deon-OD
feat: Draft PR For [FRONTEND] Form page (desktop) task
- Loading branch information
Showing
13 changed files
with
645 additions
and
231 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,75 @@ | ||
import React, { useMemo, useCallback, useState } from 'react'; | ||
import React, { useState, useCallback, useMemo } from 'react'; | ||
import { useMaxMultiplier } from 'hooks/useMaxMultiplier'; | ||
import './multiplier.css'; | ||
|
||
const MultiplierSelector = ({ min = 0, max = 10, step = 1, defaultValue = 1, setSelectedMultiplier, selectedToken }) => { | ||
const { data, isLoading, error } = useMaxMultiplier(); | ||
const [value, setValue] = useState(defaultValue); | ||
|
||
const MultiplierSelector = ({ setSelectedMultiplier, selectedToken, sliderValue }) => { | ||
const { data, isLoading, error } = useMaxMultiplier(); | ||
const [actualValue, setActualValue] = useState(1.0); | ||
|
||
const maxMultiplier = useMemo(() => { | ||
return data?.[selectedToken] || 5.0; | ||
}, [data, selectedToken]); | ||
const maxMultiplier = useMemo(() => { | ||
return data?.[selectedToken] || 11.0; | ||
}, [data, selectedToken]); | ||
|
||
const mapSliderToValue = (sliderValue) => { | ||
return maxMultiplier - sliderValue + 1; | ||
}; | ||
const handleMultiplierChange = useCallback((e) => { | ||
setValue(Number(e.target.value)); | ||
setSelectedMultiplier(value); | ||
}, [setSelectedMultiplier, value]); | ||
|
||
const handleMultiplierChange = useCallback((e) => { | ||
const sliderValue = parseFloat(e.target.value); | ||
const value = mapSliderToValue(sliderValue).toFixed(1); | ||
setActualValue(value); | ||
setSelectedMultiplier(value); | ||
}, [setSelectedMultiplier, maxMultiplier]); | ||
const steps = Array.from( | ||
{ length: Math.floor((max - min) / step) + 1 }, | ||
(_, i) => min + (i * step) | ||
); | ||
|
||
const getSliderPercentage = useCallback(() => { | ||
return (((maxMultiplier - actualValue + 1) - 1) / (maxMultiplier - 1)) * 100; | ||
}, [actualValue, maxMultiplier]); | ||
console.log(maxMultiplier); | ||
const TOTAL_MARKS = 11; | ||
|
||
if (isLoading) return <div className='slider-skeleton'>Loading multiplier data...</div>; | ||
if (error) return <div className='error-message'>Error loading multiplier data: {error.message}</div>; | ||
const getTrackPercentage = useCallback(() => { | ||
return ((value - min + 0.15) / (max - min + 0.25)) * 100; | ||
}, [value, min, max]); | ||
|
||
return ( | ||
<div className='multiplier-card'> | ||
<div className='slider-container'> | ||
<div className='slider-labels'> | ||
<span>Max</span> | ||
<span>Low</span> | ||
</div> | ||
<div className='slider-with-tooltip'> | ||
<div | ||
className='slider-tooltip' | ||
style={{ left: `${getSliderPercentage()}%` }} | ||
> | ||
{sliderValue}x | ||
</div> | ||
<input | ||
type='range' | ||
min='1' | ||
max={maxMultiplier} | ||
step='0.1' | ||
value={maxMultiplier - actualValue + 1} | ||
onChange={handleMultiplierChange} | ||
className='multiplier-slider' | ||
/> | ||
if (isLoading) return <div className="slider-skeleton">Loading multiplier data...</div>; | ||
if (error) return <div className="error-message">Error loading multiplier data: {error.message}</div>; | ||
|
||
return ( | ||
<div className="step-slider-container"> | ||
<div className="slider-labels"> | ||
<span>Min</span> | ||
<span>Max</span> | ||
</div> | ||
<div className="slider-wrapper"> | ||
<div | ||
className="slider-track-fill" | ||
style={{ 'width': `${getTrackPercentage()}%` }} | ||
/> | ||
<input | ||
type="range" | ||
min={min} | ||
max={max} | ||
step={step} | ||
value={value} | ||
onChange={handleMultiplierChange} | ||
className="step-slider" | ||
/> | ||
<div className="step-markers"> | ||
{steps.map((stepValue) => ( | ||
<div | ||
key={stepValue} | ||
className={`step-mark ${stepValue === value ? 'active' : ''}`} | ||
/> | ||
))} | ||
</div> | ||
<div className="step-multipliers"> | ||
{Array.from({ length: TOTAL_MARKS }).map((_, index) => ( | ||
<div | ||
key={index} | ||
className={`step-multiplier ${index === value ? 'active' : ''}`} | ||
>x{index}</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export default MultiplierSelector; | ||
export default MultiplierSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useState, useCallback, useMemo } from 'react'; | ||
import { useMaxMultiplier } from 'hooks/useMaxMultiplier'; | ||
import './slider-three.css'; | ||
|
||
const StepSlider = ({ min = 0, max = 10, step = 1, defaultValue = 1, setSelectedMultiplier, selectedToken }) => { | ||
const { data, isLoading, error } = useMaxMultiplier(); | ||
const [value, setValue] = useState(defaultValue); | ||
|
||
|
||
const maxMultiplier = useMemo(() => { | ||
return data?.[selectedToken] || 11.0; | ||
}, [data, selectedToken]); | ||
|
||
const handleMultiplierChange = useCallback((e) => { | ||
setValue(Number(e.target.value)); | ||
setSelectedMultiplier(value); | ||
}, [setSelectedMultiplier, value]); | ||
|
||
const steps = Array.from( | ||
{ length: Math.floor((max - min) / step) + 1 }, | ||
(_, i) => min + (i * step) | ||
); | ||
|
||
const TOTAL_MARKS = 11; | ||
|
||
const getTrackPercentage = useCallback(() => { | ||
return ((value - min) / (max - min)) * 100; | ||
}, [value, min, max]); | ||
|
||
const getCurrentMark = useCallback(() => { | ||
const invertedValue = maxMultiplier - actualValue + 1; | ||
const markIndex = Math.round((invertedValue - 1) * (TOTAL_MARKS - 1) / (maxMultiplier - 1)); | ||
return Math.min(Math.max(0, markIndex), TOTAL_MARKS - 1); | ||
}, [value, maxMultiplier, TOTAL_MARKS]); | ||
|
||
if (isLoading) return <div className="slider-skeleton">Loading multiplier data...</div>; | ||
if (error) return <div className="error-message">Error loading multiplier data: {error.message}</div>; | ||
|
||
const currentMark = getCurrentMark(); | ||
|
||
return ( | ||
<div className="step-slider-container"> | ||
<div className="slider-labels"> | ||
<span>Min</span> | ||
<span>Max</span> | ||
</div> | ||
<div className="slider-wrapper"> | ||
<div | ||
className="slider-track-fill" | ||
style={{ 'width': `${getTrackPercentage()}%` }} | ||
/> | ||
<input | ||
type="range" | ||
min={min} | ||
max={max} | ||
step={step} | ||
value={value} | ||
onChange={handleMultiplierChange} | ||
className="step-slider" | ||
/> | ||
<div className="step-markers"> | ||
{steps.map((stepValue) => ( | ||
<div | ||
key={stepValue} | ||
className={`step-mark ${stepValue === currentMark ? 'active' : ''}`} | ||
/> | ||
))} | ||
</div> | ||
<div className="step-multipliers"> | ||
{Array.from({ length: TOTAL_MARKS }).map((_, index) => ( | ||
<div | ||
key={index} | ||
className={`step-multiplier ${index === currentMark ? 'active' : ''}`} | ||
>x{index}</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StepSlider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.