generated from CodeYourFuture/cyf-final-project-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
6 -select time period on map- Delnia #35
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e1d7f31
install react-slider
DelniaAlipour d4da8bf
Create a slider
DelniaAlipour 5cc9edf
add style for the tracker range to turn to a different color
DelniaAlipour e73fc0f
filter the date and update the rhythms accordingly
DelniaAlipour 5a38863
create a component to test slider and filtering
DelniaAlipour b02d8ed
add SliderTest to app.js
DelniaAlipour ff3b1be
Update Home.js
DelniaAlipour 44d2f76
Update SliderTest.js
DelniaAlipour 42a2466
Update package-lock.json
DelniaAlipour 116bd48
Update RhythmsWithSlider.js
DelniaAlipour 8440797
Update RhythmsWithSlider.js
DelniaAlipour 3bc3066
show time-period too
DelniaAlipour fee2806
Merge branch 'main' into US4-Select-time-period-on-map
DelniaAlipour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from "react"; | ||
import { Range } from "react-range"; | ||
|
||
const DualRangeSlider = ({ selectedRange, onChangeRange }) => { | ||
const min = 1400; | ||
const max = 2023; | ||
const step = 50; | ||
|
||
const handleChange = (newValues) => { | ||
onChangeRange(newValues); | ||
}; | ||
|
||
const railLabels = [1500, 1600, 1700, 1800, 1900]; | ||
|
||
return ( | ||
<div style={{ margin: "20px", maxWidth: "400px" }}> | ||
<h2> | ||
Range: {selectedRange[0]} - {selectedRange[1]} | ||
</h2> | ||
<div | ||
style={{ | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
position: "relative", | ||
}} | ||
> | ||
<Range | ||
step={step} | ||
min={min} | ||
max={max} | ||
values={selectedRange} | ||
onChange={handleChange} | ||
renderTrack={({ props, children }) => ( | ||
<div | ||
{...props} | ||
style={{ | ||
...props.style, | ||
height: "6px", | ||
width: "100%", | ||
backgroundColor: "#ddd", | ||
position: "relative", | ||
}} | ||
> | ||
{children} | ||
<div | ||
style={{ | ||
position: "absolute", | ||
height: "6px", | ||
width: `${ | ||
((selectedRange[1] - selectedRange[0]) / (max - min)) * 100 | ||
}%`, | ||
backgroundColor: "#007bbb", | ||
left: `${((selectedRange[0] - min) / (max - min)) * 100}%`, | ||
}} | ||
></div> | ||
{railLabels.map((label, index) => ( | ||
<div | ||
key={index} | ||
style={{ | ||
position: "absolute", | ||
bottom: "-25px", | ||
left: `${((label - min) / (max - min)) * 100}%`, | ||
transform: "translateX(-50%)", | ||
}} | ||
> | ||
{label} | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
renderThumb={({ props }) => ( | ||
<div | ||
{...props} | ||
style={{ | ||
...props.style, | ||
height: "20px", | ||
width: "20px", | ||
backgroundColor: "#007bbb", | ||
borderRadius: "50%", | ||
outline: "none", | ||
}} | ||
/> | ||
)} | ||
/> | ||
</div> | ||
<div style={{ display: "flex", justifyContent: "space-between" }}> | ||
<span>{min}</span> | ||
<span>{max}</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DualRangeSlider; | ||
// src: https://codesandbox.io/s/multi-range-slider-react-js-forked-4uq1uo?file=/src/component/multiRangeSlider/MultiRangeSlider.js:529-589 |
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,48 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import DualRangeSlider from "./DualRangeSlider"; | ||
|
||
const RhythmsWithSlider = ({ rhythms }) => { | ||
const [selectedRange, setSelectedRange] = useState([1400, 2023]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For long-term projects, it's better to use something like Date.now() and get the year rather than hard-coding, but good illustration of the max/min |
||
const [filteredRhythms, setFilteredRhythms] = useState([]); | ||
|
||
// Update rhythms when user change the slider | ||
// This strictly just shows the rhythms in selected range(for now!) | ||
useEffect(() => { | ||
const updatedRhythms = rhythms.filter((rhythm) => { | ||
const rhythmStartYear = parseInt(rhythm.timePeriod.split("-")[0]); | ||
const rhythmEndYear = parseInt(rhythm.timePeriod.split("-")[1]); | ||
return ( | ||
rhythmStartYear >= selectedRange[0] && rhythmEndYear <= selectedRange[1] | ||
); | ||
}); | ||
setFilteredRhythms(updatedRhythms); | ||
}, [selectedRange, rhythms]); | ||
|
||
return ( | ||
<div> | ||
<DualRangeSlider | ||
selectedRange={selectedRange} | ||
onChangeRange={setSelectedRange} | ||
/> | ||
<div style={{ display: "flex", flexDirection: "column" }}> | ||
{filteredRhythms.map((rhythm, index) => ( | ||
<div key={index} style={{ display: "flex", alignItems: "center" }}> | ||
<div | ||
// all inline styles are just for testing | ||
style={{ | ||
width: "20px", | ||
height: "20px", | ||
backgroundColor: "blue", | ||
borderRadius: "50%", | ||
marginRight: "10px", | ||
}} | ||
></div> | ||
<span>{rhythm.title} {rhythm.timePeriod }</span> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RhythmsWithSlider; |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from "react"; | ||
import RhythmsWithSlider from "../components/RhythmsWithSlider"; | ||
const rhythms = [ | ||
{ | ||
title: "DC Hand dancing", | ||
url: "https://www.youtube.com/watch?v=M6uM0qrjetQ", | ||
location: "Washington DC", | ||
description: "I have both Video and Description", | ||
timePeriod: "1500-2010", | ||
}, | ||
{ | ||
title: "Rumba Guaguanco", | ||
location: "Havana, Cuba", | ||
description: "I have no video to play, for more information google me!", | ||
timePeriod: "1600-1800", | ||
}, | ||
{ | ||
title: "DC Hand dancing 2", | ||
url: "https://www.youtube.com/watch?v=M6uM0qrjetQ", | ||
location: "Washington DC", | ||
timePeriod: "1700-2000", | ||
}, | ||
{ | ||
title: "Adaha and Konkoma", | ||
audioUrl: | ||
"https://soundcloud.com/shugo_srd/shugz-king-of-my-castle?utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing", | ||
location: "Washington DC", | ||
timePeriod: "2015-2020", | ||
}, | ||
{ | ||
title: "Dance Band Highlife", | ||
audioUrl: | ||
"https://soundcloud.com/eduleon42/are-we-going-out-tonight-vol-3?si=0cd23cdd892b41c6ad451505b21c0d3f&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing", | ||
location: "Washington DC", | ||
description: | ||
"Dance band likely had its immediate roots in the orchestras founded and popularized by West African coastal elites who lived in the region’s expanding colonial and cosmopolitan cities", | ||
timePeriod: "1900-2008", | ||
}, | ||
]; | ||
// timePeriod is different from what Man has put in Rhythms Table.(year_start/year_end) | ||
const SliderTest = () => { | ||
return ( | ||
<div> | ||
<h1>Testing the Date Filtering </h1> | ||
<RhythmsWithSlider rhythms={rhythms} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SliderTest; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good illustration of how the component will operate using state. When it's integrated, we should look to move this state into the main page.