- 
                Notifications
    You must be signed in to change notification settings 
- Fork 16
Feature/faster cars from behind #15
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      bddf63b
              
                added calculations and distance bar
              
              
                TMBraunDE ffa20f1
              
                animation and hiding
              
              
                DerMega 4fa4e09
              
                moved cautionahead out of this branch to its own branch.
              
              
                TMBraunDE 6190686
              
                added color change. logical fixes
              
              
                DerMega 032e173
              
                Merge branch 'main' into feature/fasterCarsFromBehind
              
              
                DerMega 07e2377
              
                Update src/frontend/components/FasterCarsFromBehind/FasterCarsFromBeh…
              
              
                tariknz 70e4148
              
                Merge branch 'main' into feature/fasterCarsFromBehind
              
              
                tariknz 6ec20fc
              
                Update src/app/storage/defaultDashboard.ts
              
              
                tariknz 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
    
  
  
    
              
              
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  src/frontend/components/FasterCarsFromBehind/FasterCarsFromBehind.stories.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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 { Meta, StoryObj } from '@storybook/react'; | ||
| import { FasterCarsFromBehind } from './FasterCarsFromBehind'; | ||
| import { TelemetryDecorator } from '../../../../.storybook/telemetryDecorator'; | ||
| import { DynamicTelemetrySelector } from '../Standings/DynamicTelemetrySelector'; | ||
| import { useState } from 'react'; | ||
|  | ||
| export default { | ||
| component: FasterCarsFromBehind, | ||
| parameters: { | ||
| controls: { | ||
| exclude: ['telemetryPath'], | ||
| } | ||
| } | ||
| } as Meta<typeof FasterCarsFromBehind>; | ||
|  | ||
| type Story = StoryObj<typeof FasterCarsFromBehind>; | ||
|  | ||
| export const Primary: Story = { | ||
| decorators: [TelemetryDecorator()], | ||
| }; | ||
|  | ||
| export const DynamicTelemetry: Story = { | ||
| decorators: [(Story, context) => { | ||
| const [selectedPath, setSelectedPath] = useState('/test-data/1745291694179'); | ||
|  | ||
| return ( | ||
| <> | ||
| <DynamicTelemetrySelector | ||
| onPathChange={setSelectedPath} | ||
| initialPath={selectedPath} | ||
| /> | ||
| {TelemetryDecorator(selectedPath)(Story, context)} | ||
| </> | ||
| ); | ||
| }], | ||
| }; | 
        
          
          
            30 changes: 30 additions & 0 deletions
          
          30 
        
  src/frontend/components/FasterCarsFromBehind/FasterCarsFromBehind.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,30 @@ | ||
| import { useMemo } from 'react'; | ||
| import { useAutoAnimate } from '@formkit/auto-animate/react'; | ||
| import { useCarBehind } from './hooks/useCarBehind'; | ||
|  | ||
| export const FasterCarsFromBehind = () => { | ||
| const carBehind = useCarBehind(); | ||
| const [parent] = useAutoAnimate(); | ||
|  | ||
| const layout = useMemo(() => { | ||
| const hidden = carBehind.name === null || carBehind.name == undefined ? 'hidden' : ''; | ||
| const animate = carBehind.distance > -0.3 ? 'animate-pulse' : ''; | ||
| const red = carBehind.percent; | ||
| const green = 100 - carBehind.percent; | ||
|  | ||
| return { hidden, animate, red, green }; | ||
| }, [ | ||
| carBehind.name, | ||
| carBehind.distance, | ||
| carBehind.percent | ||
| ]); | ||
|  | ||
| return ( | ||
| <div className={`w-full flex justify-between rounded-sm p-1 pb-2 font-bold relative ${layout.hidden} ${layout.animate} ${carBehind.background}`} | ||
| ref={parent}> | ||
| <div className="rounded-sm bg-gray-700 p-1">{carBehind.name}</div> | ||
| <div className="rounded-sm bg-gray-700 p-1">{carBehind.distance}</div> | ||
| <div className={`absolute bottom-0 left-0 rounded-b-sm bg-white h-1 flex-none`} style={{width: carBehind.percent+'%', backgroundColor: `rgb(${layout.red}%, ${layout.green}%, 0%)`}}></div> | ||
| </div> | ||
| ); | ||
| }; | 
        
          
          
            20 changes: 20 additions & 0 deletions
          
          20 
        
  src/frontend/components/FasterCarsFromBehind/hooks/useCarBehind.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,20 @@ | ||
| import { useMemo } from 'react'; | ||
| import { useDriverRelatives } from '../../Standings/hooks/useDriverRelatives'; | ||
| import { getTailwindStyle } from '../../../utils/colors'; | ||
|  | ||
| export const useCarBehind = () => { | ||
| const drivers = useDriverRelatives({ buffer: 1 }); | ||
| const carBehind = drivers[2]; | ||
| const myCar = drivers[1]; | ||
|  | ||
| const background = getTailwindStyle(carBehind?.carClass?.color).classHeader; | ||
|  | ||
| const FasterCarFromBehind = useMemo(() => { | ||
| const percent = parseInt((100 - (Math.abs(carBehind?.delta) / 3 * 100)).toFixed(0)); | ||
|  | ||
| return { name: carBehind?.driver?.name, distance: parseFloat(carBehind?.delta.toFixed(1)), background: background, percent : percent }; | ||
| }, [carBehind?.delta, carBehind?.driver?.name, background]); | ||
|  | ||
| if(carBehind?.carClass?.relativeSpeed <= myCar?.carClass?.relativeSpeed || carBehind?.delta < -3) return {name: null, distance: 0, background: null, percent: 0}; | ||
| return FasterCarFromBehind; | ||
| }; | 
  
    
      This file contains hidden or 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
    
  
  
    
              
              
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.