Skip to content

Commit

Permalink
Add lint step to frontend ci
Browse files Browse the repository at this point in the history
  • Loading branch information
nnayk committed Dec 8, 2023
1 parent cd497b8 commit 1b568b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/frontend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Install dependencies
uses: actions/checkout@v4
- run: npm install
# - run: npm run lint
- run: npm run lint
39 changes: 17 additions & 22 deletions Frontend/src/pages/vote.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// src/pages/vote.js
import React, { useEffect, useState } from 'react';
import Image from 'next/image';
import React, { useEffect, useState } from "react";
import Image from "next/image";
import { isAuthenticated } from "./auth";
import axios from 'axios';
import styles from './vote.module.css';
import axios from "axios";
import styles from "./vote.module.css";

const backendUrl = "http://localhost:5000"; // Assuming your backend runs on port 5000

Expand Down Expand Up @@ -38,6 +38,7 @@ export default function Vote() {

useEffect(() => {
fetchTwoDistinctImages();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const fetchRandomImage = async () => {
Expand All @@ -63,20 +64,18 @@ export default function Vote() {
const handleImageClick = async (id) => {
setSelectedImage(id);


const winner = images.find((image) => image._id.$oid === id);
const loser = images.find((image) => image._id.$oid !== id);

const winner = images.find(image => image._id.$oid === id);
const loser = images.find(image => image._id.$oid !== id);

const newEloWinner = calculateNewElo(winner.elo, loser.elo, true);
const newEloLoser = calculateNewElo(loser.elo, winner.elo, false);

await updateElo(winner._id.$oid, newEloWinner, loser._id.$oid, newEloLoser);

setTimeout(() => {
fetchTwoDistinctImages();
setSelectedImage(null);
}, 400);
}, 400);
};

const updateElo = async (winnerId, newEloWinner, loserId, newEloLoser) => {
Expand All @@ -85,13 +84,13 @@ export default function Vote() {
imageIdOne: winnerId,
newEloOne: newEloWinner,
imageIdTwo: loserId,
newEloTwo: newEloLoser
newEloTwo: newEloLoser,
});
} catch (error) {
console.error("Error updating ELO", error);
}
};

return (
<div className="bg-gray-100 min-h-screen flex flex-col justify-center items-center">
<div className={styles.container}>
Expand All @@ -102,17 +101,17 @@ export default function Vote() {
selectedImage === null
? styles.default
: selectedImage === image._id.$oid
? styles.winning
: styles.losing
? styles.winning
: styles.losing
} border border-5 border-black opacity-50 hover:scale-105 transform transition duration-50 ease-in-out`}
onClick={() => handleImageClick(image._id.$oid)}
>
<Image
src={image.url}
alt='Votable Image'
alt="Votable Image"
width={1024}
height={1024}
style={{ width: '100%', height: '100%' }}
style={{ width: "100%", height: "100%" }}
/>
</div>
))}
Expand All @@ -121,14 +120,11 @@ export default function Vote() {
);
}




export async function getServerSideProps(context) {
const { req } = context;
const token = req.cookies["token"];

if (!await isAuthenticated(token)) {
if (!(await isAuthenticated(token))) {
// If the user is not authenticated, redirect them to the login page
return {
redirect: {
Expand All @@ -143,4 +139,3 @@ export async function getServerSideProps(context) {
props: {}, // Will be passed to the page component as props
};
}

0 comments on commit 1b568b3

Please sign in to comment.