-
Notifications
You must be signed in to change notification settings - Fork 60
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
freeze admin bounty overview section #1243
Merged
kevkevinpal
merged 7 commits into
stakwork:master
from
Ekep-Obasi:freeze-admin-bounty-overview-section
Jan 8, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fed699c
feat: created useInViewPort custom hook
Ekep-Obasi 334b4ca
feat: freeze bounties overview section
Ekep-Obasi 58d5d17
fix: fixed merge conflicts
Ekep-Obasi b5b2680
fix: merge conflicts
Ekep-Obasi 6a7df5c
refactor: refactored proptypes
Ekep-Obasi d39eb0d
test: wrote tests for useInViewport hook
Ekep-Obasi 81e1d54
feat: freeze bounties overview section
Ekep-Obasi 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,57 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useInViewPort } from 'hooks/useInViewport'; | ||
import { IntersectionOptions } from 'react-intersection-observer'; | ||
|
||
const defaultOptions: IntersectionOptions = {}; | ||
|
||
describe('useInViewport hook', () => { | ||
interface Window { | ||
IntersectionObserver: unknown; | ||
} | ||
|
||
const prepareForTesting = (isIntersecting: boolean): void => { | ||
const mockedIntersectionObserver = jest.fn((callback: any) => { | ||
callback([{ isIntersecting }]); | ||
|
||
return { | ||
observe: jest.fn(), | ||
unobserve: jest.fn() | ||
}; | ||
}); | ||
|
||
(window as Window).IntersectionObserver = mockedIntersectionObserver; | ||
}; | ||
|
||
it('should initialize the inView state to false', () => { | ||
prepareForTesting(false); | ||
|
||
const { result } = renderHook(() => useInViewPort(defaultOptions)); | ||
expect(result.current[0]).toBe(false); | ||
}); | ||
|
||
it('should not detect element when reference is not connected', () => { | ||
prepareForTesting(false); | ||
|
||
const { result } = renderHook(() => useInViewPort(defaultOptions)); | ||
const [isVisible, ref] = result.current; | ||
|
||
expect(ref.current).toBe(null); | ||
expect(isVisible).toBe(false); | ||
}); | ||
|
||
it('should detect element after scroll', () => { | ||
prepareForTesting(true); | ||
|
||
const element = document.createElement('div'); | ||
|
||
const { result } = renderHook(() => useInViewPort(defaultOptions)); | ||
|
||
const [isVisible, ref] = result.current; | ||
|
||
ref.current = element; | ||
|
||
renderHook(() => useInViewPort(defaultOptions)); | ||
|
||
expect(isVisible).toBe(true); | ||
}); | ||
}); |
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,24 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { IntersectionOptions } from 'react-intersection-observer'; | ||
|
||
export const useInViewPort = (options: IntersectionOptions) => { | ||
const [inView, setInView] = useState<boolean>(false); | ||
const elementRef = useRef<HTMLElement | null>(null); | ||
|
||
const callback = (entries: IntersectionObserverEntry[]) => { | ||
const [entry] = entries; | ||
setInView(entry.isIntersecting); | ||
}; | ||
|
||
useEffect(() => { | ||
// checking support and blocking execution on server-side | ||
if (!(typeof window !== 'undefined') && !('IntersectionObserver' in window)) return; | ||
|
||
const observer = new IntersectionObserver(callback, options); | ||
if (elementRef.current) observer.observe(elementRef.current); | ||
|
||
return () => observer.disconnect(); | ||
}, [options]); | ||
|
||
return [inView, elementRef] as const; | ||
}; |
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
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
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
Oops, something went wrong.
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
z-index
doesnt feel like best practice is there a style to keep it always ontop? if you can look into alternatives to doing this that would be goodThere 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.
I'm just going to make this another issue so we can merge this PR for now