-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deviation): deviations for stop place (#1365)
- Loading branch information
1 parent
13496c2
commit 5f21833
Showing
10 changed files
with
122 additions
and
27 deletions.
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
13 changes: 2 additions & 11 deletions
13
next-tavla/src/Board/scenarios/Table/components/Situations.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
23 changes: 23 additions & 0 deletions
23
next-tavla/src/Board/scenarios/Table/components/StopPlaceDeviation/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { TSituationFragment } from 'graphql/index' | ||
import { useCycler } from '../../useCycler' | ||
import { Situation } from '../Situation' | ||
import classes from './styles.module.css' | ||
|
||
function StopPlaceDeviation({ | ||
situations, | ||
}: { | ||
situations?: TSituationFragment[] | ||
}) { | ||
const index = useCycler(situations) | ||
const numberOfSituations = situations?.length ?? 0 | ||
|
||
if (!situations || numberOfSituations === 0) return null | ||
|
||
return ( | ||
<div className={classes.deviation}> | ||
<Situation situation={situations[index % numberOfSituations]} /> | ||
</div> | ||
) | ||
} | ||
|
||
export { StopPlaceDeviation } |
11 changes: 11 additions & 0 deletions
11
next-tavla/src/Board/scenarios/Table/components/StopPlaceDeviation/styles.module.css
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,11 @@ | ||
.deviation { | ||
padding-bottom: 0.5em; | ||
} | ||
|
||
.header { | ||
color: var(--table-header-color); | ||
font-size: 0.7em; | ||
margin-left: 0.25em; | ||
margin-right: 0.25em; | ||
padding-bottom: 0.5em; | ||
} |
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,18 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
function useCycler<T>(array: T[] | undefined, step = 5000) { | ||
const [index, setIndex] = useState(0) | ||
|
||
const length = array?.length ?? 0 | ||
|
||
useEffect(() => { | ||
if (length <= 1) { | ||
return | ||
} | ||
const interval = setInterval(() => setIndex((i) => i + 1), step) | ||
return () => clearInterval(interval) | ||
}, [length, step]) | ||
return index | ||
} | ||
|
||
export { useCycler } |
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 |
---|---|---|
|
@@ -16,5 +16,8 @@ query getQuay( | |
) { | ||
...departure | ||
} | ||
situations { | ||
...situation | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,5 +14,8 @@ query StopPlace( | |
) { | ||
...departure | ||
} | ||
situations { | ||
...situation | ||
} | ||
} | ||
} |