Skip to content

Commit

Permalink
fix: Hoist state into page.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
rexmagnusdavid committed Apr 17, 2024
1 parent 65494a5 commit 52886ae
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
72 changes: 36 additions & 36 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ name: "CodeQL"

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]
schedule:
- cron: '00 15 * * 5'
- cron: "00 15 * * 5"

jobs:
analyze:
Expand All @@ -44,8 +44,8 @@ jobs:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
Expand All @@ -55,38 +55,38 @@ jobs:
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
11 changes: 5 additions & 6 deletions .github/workflows/rust-clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ name: rust-clippy analyze

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
branches: ["master"]
schedule:
- cron: '00 15 * * 5'
- cron: "00 15 * * 5"

jobs:
rust-clippy-analyze:
Expand All @@ -42,14 +42,13 @@ jobs:
run: sudo apt-get install protobuf-compiler

- name: Run rust-clippy
run:
cargo clippy
run: cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
20 changes: 3 additions & 17 deletions app/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Image from "next/image";
import React, { useEffect, useState } from "react";
import React from "react";
import Logo from "../../public/logo.png";
import { Bullet } from "./Bullet";
import { Title } from "./Title";
Expand All @@ -8,26 +8,12 @@ export function Alert(props: {
name: string;
headers: Array<string>;
routes: { [key: string]: { [key: string]: string } };
index: number;
}) {
const [index, setIndex] = useState(0);

let name = props.name;
let headers = props.headers;
let routes = props.routes;

useEffect(() => {
const loop = setInterval(() => {
if (headers.length === 0) {
setIndex(0);
return;
}
setIndex((i) => (((i + 1) % headers.length) + headers.length) % headers.length);
}, 5000);

return () => {
clearInterval(loop);
};
}, [headers, headers.length, index]);
let index = props.index;

return (
<React.Fragment>
Expand Down
17 changes: 16 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function Home() {
const [routes, setRoutes] = useState<{ [key: string]: { [key: string]: string } }>({});
const [paulTimes, setPaulTimes] = useState<{ [key: string]: { [key: string]: Array<Vehicle> } }>({});
const [w205Times, setW205Times] = useState<{ [key: string]: { [key: string]: Array<Vehicle> } }>({});
const [index, setIndex] = useState(0);

useEffect(() => {
const ws = new WebSocket("ws://127.0.0.1:9001");
Expand Down Expand Up @@ -92,14 +93,28 @@ export default function Home() {
};
}, []);

useEffect(() => {
const loop = setInterval(() => {
if (serviceAlerts.length === 0) {
setIndex(0);
return;
}
setIndex((i) => (((i + 1) % serviceAlerts.length) + serviceAlerts.length) % serviceAlerts.length);
}, 5000);

return () => {
clearInterval(loop);
};
}, [serviceAlerts.length]);

return (
<div className="grid min-h-screen grid-flow-dense grid-cols-3 grid-rows-3 gap-4 bg-emerald-700 p-2 text-black">
<div className="col-span-2 row-span-2 flex flex-col gap-2 rounded-xl bg-black p-2">
<Countdown name={"Bedford Park Blvd / Jerome Av"} vehicles={jeromeTimes} routes={routes}></Countdown>
<Countdown name={"Bedford Park Blvd / Grand Concourse"} vehicles={concourseTimes} routes={routes}></Countdown>
</div>
<div className="col-span-2 row-span-1 flex flex-col gap-2 rounded-xl bg-black p-2">
<Alert name={"Service Disruptions"} headers={serviceAlerts} routes={routes} />
<Alert name={"Service Disruptions"} headers={serviceAlerts} routes={routes} index={index} />
</div>
<div className="col-span-1 row-span-3 flex flex-col gap-2 rounded-xl bg-black p-2">
<List name={"Paul Av / W 205 St"} vehicles={paulTimes}></List>
Expand Down

0 comments on commit 52886ae

Please sign in to comment.