-
Notifications
You must be signed in to change notification settings - Fork 0
Playoff Schedule #3
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
base: master
Are you sure you want to change the base?
Conversation
| // בס"ד | ||
| // const eventsInYear = t.type({// if you need this | ||
| // address: t.string, | ||
| // city: t.string, | ||
| // country: t.string, | ||
| // district: t.unknown, | ||
| // division_keys: t.array(t.string), | ||
| // end_date: t.string, | ||
| // event_code: t.string, | ||
| // event_type: t.number, | ||
| // event_type_string: t.string, | ||
| // first_event_code: t.string, | ||
| // first_event_id: t.unknown, | ||
| // gmaps_place_id: t.string, | ||
| // gmaps_url: t.string, | ||
| // key: t.string, | ||
| // lat: t.number, | ||
| // lng: t.number, | ||
| // location_name: t.string, | ||
| // name: t.string, | ||
| // parent_event_key: t.unknown, | ||
| // playoff_type: t.number, | ||
| // playoff_type_string: t.string, | ||
| // postal_code: t.string, | ||
| // remap_teams: t.unknown, | ||
| // short_name: t.string, | ||
| // start_date: t.string, | ||
| // state_prov: t.string, | ||
| // timezone: t.string, | ||
| // webcasts: t.array( | ||
| // t.type({ | ||
| // channel: t.string, | ||
| // type: t.string, | ||
| // }) | ||
| // ), |
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.
if this is unused, why is this here?
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.
ask oded
|
|
||
| app.use(express.static(distDirectory)); | ||
|
|
||
| app.get(/^(.*)$/, (req, res) => { |
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 is magic, I don't like magic
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.
agreed, consider copying what is in the updated master branch. either look at it through github or git pull and merge
YoniKiriaty
left a comment
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.
Thought this was good then I saw the App.tsx
.vscode/tasks.json
Outdated
| "type": "shell", | ||
| "command": "./node_modules/.bin/dotenv -e .dev.env -e .public.env -e .secret.env -- 'turbo run dev --filter=${input:project}-frontend --filter=${input:project}-backend'" | ||
| "command": "./node_modules/.bin/dotenv -e .dev.env -e .public.env -e .secret.env -- 'turbo run dev --filter=${input:project}-frontend --filter=${input:project}-backend'", | ||
| "problemMatcher": [] |
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.
consider removing this.
| const statusBadServer = 500; | ||
| const statusGood = 200; | ||
| const statusBadUser = 400; |
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.
consider using the status codes library http-status-codes:
use StatusCodes.OK instead of statusGood
| const statusBadUser = 400; | ||
|
|
||
| // enter a valid api key | ||
| const apiKey = "YOUR_API_KEY"; |
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.
consider using enviromental variables to pass in sensitive information. create a .secret.env file near the .public.env file (the .secret.env file is already gitignored and used in the files). consider looking at the .public.env at how to make enviromental variables.
| const apiKey = "YOUR_API_KEY"; | |
| const apiKey = process.env.TBA_API_KEY ?? "YOUR_API_KEY"; |
| export const fetchData = async (url: string): Promise<unknown> => { | ||
| const response = await fetch(url, { | ||
| method: "GET", | ||
| headers: { | ||
| "X-TBA-Auth-Key": apiKey, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| mode: "cors", | ||
| }); | ||
| if (!response.ok) { | ||
| throw new Error(`HTTP error! status: ${response.status}`); | ||
| } | ||
| const data = await response.json(); | ||
| console.log("TBA data:", data); | ||
| return data; | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| app.get("/fetch", async (req, res) => { | ||
| try { | ||
| const encodedUrl = req.query.url; | ||
| if (!encodedUrl || typeof encodedUrl !== "string") { | ||
| res.status(statusBadUser).json({ error: "missing url param" }); | ||
| return; | ||
| } | ||
| const fullUrl = decodeURIComponent(encodedUrl); | ||
| console.log("Incoming /fetch with url:", fullUrl); | ||
|
|
||
| const data = await fetchData(fullUrl); | ||
| res.status(statusGood).json(data); | ||
| } catch (error) { | ||
| console.error("Error in /fetch:", error); | ||
| res.status(statusBadServer).json({ error: "Failed to fetch data" }); | ||
| } | ||
| }); |
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.
consider making a file called tba.ts in the routes directory, and use Router syntax to show the data. consider looking into how the index.ts in routes works and reading on it
| app.get("/fetch", async (req, res) => { | ||
| try { | ||
| const encodedUrl = req.query.url; | ||
| if (!encodedUrl || typeof encodedUrl !== "string") { | ||
| res.status(statusBadUser).json({ error: "missing url param" }); | ||
| return; | ||
| } | ||
| const fullUrl = decodeURIComponent(encodedUrl); | ||
| console.log("Incoming /fetch with url:", fullUrl); | ||
|
|
||
| const data = await fetchData(fullUrl); | ||
| res.status(statusGood).json(data); | ||
| } catch (error) { | ||
| console.error("Error in /fetch:", error); | ||
| res.status(statusBadServer).json({ error: "Failed to fetch data" }); | ||
| } | ||
| }); |
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.
getting the URL from the user and making a fetch with that can be pretty unsafe. a person can send malicious requests which will make you send requests he makes. consider making multiple get endpoints for different cases, for example an endpoint for matches, for teams and for event data.
| const [teamRank, setTeamRank] = useState<RankItem | null>(null); | ||
| const [searchStatus, setSearchStatus] = useState<"idle" | "loading" | "success" | "error">("idle"); | ||
|
|
||
| const resetInSearch = () => { |
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.
consider using useCallback
| const sortMatches = useCallback((a: MatchesSimpleType, b: MatchesSimpleType) => { | ||
| const timeA = a.predicted_time ?? a.time ?? matchTimeDefault; | ||
| const timeB = b.predicted_time ?? b.time ?? matchTimeDefault; | ||
| const weightA = getLevelWeight(a.comp_level); | ||
| const weightB = getLevelWeight(b.comp_level); | ||
|
|
||
| return (timeA > matchTimeMissing && timeB > matchTimeMissing) ? timeA - timeB | ||
| : (timeA === matchTimeMissing && timeB > matchTimeMissing) ? sortABeforeB | ||
| : (timeA > matchTimeMissing && timeB === matchTimeMissing) ? sortBBeforeA | ||
| : (weightA !== weightB) | ||
| ? weightA - weightB | ||
| : a.match_number - b.match_number; | ||
| }, []); |
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.
can't this function be defined outside of the component?
|
|
||
| useEffect(() => { | ||
| const intervalId: number | undefined = searchStatus === "success" && activeEventKey ? | ||
| window.setInterval(() => { |
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.
consider not using window
| const map: Map<string, string> = new Map(); | ||
| teams.forEach(team => map.set(team.key, team.nickname)); |
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.
consider using a Record<string,string> instead of a map.
| const map: Map<string, string> = new Map(); | |
| teams.forEach(team => map.set(team.key, team.nickname)); | |
| const map: Record<string, string> = {}; | |
| teams.forEach(team => {map[team.key] = team.nickname;}); |
| const { currentGlobalMatch, targetTeamMatches, isEventOver, isTeamDone, isFutureEvent } = useMemo(() => { | ||
| // normal one | ||
| const currentTimeSecs = Math.floor(Date.now() / timeMultiplier); | ||
|
|
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.
Ctrl+S 🙏🏻
the project makes a schedule for playoff and events that happened and will happen