Skip to content
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

Fix result caching on refresh and add scroll to Icon in shared links #22

Merged
merged 3 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import ThankYou from './components/ThankYou'
import ScrollToTopBtn from './components/ScrollToTop'
import AppContext from './utils/AppContext'
import CookiesBanner from './components/CookiesBanner'
import StartOnTop from './components/StartOnTop'

const tagManagerArgs = {
gtmId: GTM
Expand All @@ -39,16 +38,14 @@ const App = () => {
<Navigation />
<div className='app-container'>
<Router primary={false}>
<StartOnTop path='/'>
<Home path='/' />
<Docs path='/docs' />
<CookiesPage path='/cookies-policy' />
<ThankYou path='/thankyou' />
<PageNotFound path='*' />
<AboutPage path='/about' />
<TeamPage path='/team' />
<Cheatsheet path='/cheatsheet' />
</StartOnTop>
<Home path='/' />
<Docs path='/docs' />
<CookiesPage path='/cookies-policy' />
<ThankYou path='/thankyou' />
<PageNotFound path='*' />
<AboutPage path='/about' />
<TeamPage path='/team' />
<Cheatsheet path='/cheatsheet' />
</Router>
<ScrollToTopBtn />
</div>
Expand Down
72 changes: 53 additions & 19 deletions src/modules/IconsSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const IconsSet = (props) => {
const [emptySearchResult, setEmptySearchResult] = useState(false)
const [suggestedString, setSuggestedString] = useState('')

const activeIconRef = useRef(null)
useEffect(() => {
if (iconSelected !== '') {
window.addEventListener('DOMContentLoaded', () => {
window.scrollTo(0, activeIconRef.current.offsetTop)
})
}
})

let setSearchWithUrlParam = urlIconName

if (setSearchWithUrlParam === '' || setSearchWithUrlParam === null) {
Expand Down Expand Up @@ -150,7 +159,7 @@ const IconsSet = (props) => {
const setIconInSearch = () => {
return dispatch({
type: 'TOGGLE_SEARCH_REGULAR_ICONS',
search: urlIconName
search: ''
})
}

Expand Down Expand Up @@ -431,24 +440,49 @@ const IconsSet = (props) => {
<div key={index}>
<h4 className='category'>{categoryObject.category}</h4>
<div className='icons-list'>
{categoryObject.icons.map((icon, i) => (
<Icon
size={36}
active={isActive(icon.name, state)}
key={icon.name}
name={icon.name}
iconsTheme={state.iconsTheme}
action={() =>
selectIcon(
icon,
dispatch({
type: state.customize ? 'ADD_MULTIPLE_ICONS' : '',
selection: icon.name
})
)
}
/>
))}
{categoryObject.icons.map((icon, i) =>
isActive(icon.name, state) ? (
<div ref={activeIconRef}>
<Icon
size={36}
active={isActive(icon.name, state)}
key={icon.name}
name={icon.name}
iconsTheme={state.iconsTheme}
action={() =>
selectIcon(
icon,
dispatch({
type: state.customize
? 'ADD_MULTIPLE_ICONS'
: '',
selection: icon.name
})
)
}
/>
</div>
) : (
<Icon
size={36}
active={isActive(icon.name, state)}
key={icon.name}
name={icon.name}
iconsTheme={state.iconsTheme}
action={() =>
selectIcon(
icon,
dispatch({
type: state.customize
? 'ADD_MULTIPLE_ICONS'
: '',
selection: icon.name
})
)
}
/>
)
)}
</div>
</div>
) : (
Expand Down