-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from PepperDash/websocket-updates
Websocket updates
- Loading branch information
Showing
10 changed files
with
243 additions
and
48 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/lib/shared/disconnectedMessage/DisconnectedMessage.module.scss
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,3 @@ | ||
.mwfit { | ||
max-width: fit-content; | ||
} |
18 changes: 12 additions & 6 deletions
18
src/lib/shared/disconnectedMessage/DisconnectedMessage.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { RefObject, useLayoutEffect, useState } from "react"; | ||
|
||
export function useOverflow<T extends HTMLElement | undefined>(ref:RefObject<T | undefined>, callback?:(hasOverflowVertical: boolean, hasOverflowHorizontal: boolean) => void):UseIsOverflowProps { | ||
const [overflowHorizontal, setOverflowHorizontal] = useState(false); | ||
const [overflowVertical, setOverflowVertical] = useState(false); | ||
|
||
|
||
useLayoutEffect(() => { | ||
const { current } = ref; | ||
|
||
const trigger = () => { | ||
const hasOverflowVertical = current && current.scrollHeight > current.clientHeight; | ||
const hasOverflowHorizontal = current && current.scrollWidth > current.clientWidth; | ||
|
||
setOverflowVertical(hasOverflowVertical ?? false); | ||
setOverflowHorizontal(hasOverflowHorizontal ?? false); | ||
|
||
if (!callback) return; | ||
|
||
callback(hasOverflowVertical ?? false, hasOverflowHorizontal ?? false); | ||
} | ||
|
||
if (!current) return; | ||
|
||
trigger(); | ||
}, [ref, callback]) | ||
|
||
return { overflowHorizontal, overflowVertical }; | ||
} | ||
|
||
export interface UseIsOverflowProps { | ||
overflowHorizontal: boolean; | ||
overflowVertical: boolean; | ||
} | ||
|
||
export default useOverflow; |
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,55 @@ | ||
import { RefObject, useLayoutEffect, useState } from "react"; | ||
|
||
export function useScroll<T extends HTMLElement | undefined>(ref: RefObject<T | undefined>): UseScrollProps { | ||
|
||
const [horizontalScrollPosition, setHorizontalScrollPosition] = useState(ref?.current?.scrollLeft ?? 0); | ||
const [verticalScrollPosition, setVerticalScrollPosition] = useState(ref?.current?.scrollTop ?? 0); | ||
|
||
const scrollHorizontal = (increment: number) => { | ||
const { current } = ref; | ||
|
||
if (!current) return; | ||
|
||
console.log(current.scrollLeft); | ||
|
||
current.scrollLeft += increment; | ||
|
||
console.log(current.scrollLeft); | ||
} | ||
|
||
const scrollVertical = (increment: number) => { | ||
const { current } = ref; | ||
|
||
if (!current) return; | ||
|
||
console.log(current.scrollTop); | ||
|
||
current.scrollTop += increment; | ||
|
||
console.log(current.scrollTop); | ||
} | ||
|
||
useLayoutEffect(() => { | ||
const { current } = ref; | ||
|
||
const trigger = () => { | ||
setHorizontalScrollPosition(current?.scrollLeft ?? 0); | ||
setVerticalScrollPosition(current?.scrollTop ?? 0); | ||
} | ||
|
||
if (!current) return; | ||
|
||
trigger(); | ||
}, [ref]) | ||
|
||
return {horizontalScrollPosition, verticalScrollPosition, scrollHorizontal, scrollVertical}; | ||
} | ||
|
||
export default useScroll; | ||
|
||
export interface UseScrollProps { | ||
scrollHorizontal: (increment: number) => void; | ||
scrollVertical: (increment: number) => void; | ||
horizontalScrollPosition: number; | ||
verticalScrollPosition: number; | ||
} |
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.