Skip to content
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

the card component #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions nepalingo-web/src/components/button/Button.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you also delete the old button.tsx file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, i think i just renamed the old botton.tsx

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { forwardRef } from 'react';

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {

}

const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
const { className, children, ...rest } = props;

const buttonClasses = `bg-blue-500 hover:md:bg-opacity-80 text-white font-bold py-2 px-4 rounded ${className}`;

return (
<button ref={ref} className={buttonClasses} {...rest}>
{children}
</button>
);
});

Button.displayName = 'Button';

export default Button;
58 changes: 58 additions & 0 deletions nepalingo-web/src/components/card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { useState } from 'react';
import { PiSpeakerHighFill } from "react-icons/pi";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have fontawesome installed as a dependency - can we use an icon from there?


const Card: React.FC<{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can import this in line 1 similar to how you did useState

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with React.MouseEvent below

Word: string;
TranslatedWord: string;
Pronunciation: string;
DevenagiriSpelling: string;
ImageUrl: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types look great! A few things to account for - the ImageUrl and PronounciationUrl should be optional because not all words from the API have them available.

PronounciationUrl: string;
}> = ({ Word, TranslatedWord, Pronunciation, DevenagiriSpelling, ImageUrl, PronounciationUrl }) => {
const [isFlipped, setIsFlipped] = useState(false);
const [audio, setAudio] = useState<HTMLAudioElement | null>(null);

const handleFlip = () => {
setIsFlipped(!isFlipped);
};

const handlePronunciation = (event: React.MouseEvent) => {
event.stopPropagation(); // Prevent the card from flipping
if (audio) {
if (!audio.paused) {
audio.pause();
audio.currentTime = 0;
} else {
audio.play();
}
} else {
const newAudio = new Audio(PronounciationUrl);
setAudio(newAudio);
newAudio.play();
}
};

return (
<div>
<div className={`border-2 border-slate-400 relative w-96 h-72 ${isFlipped ? 'flipped' : ''}`} onClick={handleFlip} style={{ perspective: '1000px' }}>
<div className="text-4xl font-bold absolute inset-0 text-black flex justify-center items-center backface-hidden" style={{ transform: isFlipped ? 'rotateY(180deg)' : 'rotateY(0deg)', transition: 'transform 0.6s' }}>
{!isFlipped && <div>{Word}</div>}
</div>
<div className="absolute inset-0 bg-white text-black flex justify-center items-center backface-hidden transform rotateY-180 font-bold" style={{ transform: isFlipped ? 'rotateY(0deg)' : 'rotateY(-180deg)', transition: 'transform 0.6s' }}>
<div className="flex flex-col items-start justify-center">
<img src={ImageUrl} alt={Word} className="absolute left-2 top-1/2 transform -translate-y-1/2 object-cover w-40 h-60" />
<p className="absolute right-10 top-16 text-2xl font-bold">{TranslatedWord}</p>
<p className="absolute right-10 top-28 text-sm">{DevenagiriSpelling}</p>
<p className="absolute right-10 top-36 text-xs">{Pronunciation}</p>
<button onClick={handlePronunciation} className="absolute right-10 bottom-10">
<PiSpeakerHighFill />

</button>
</div>
</div>
</div>
</div>
);
};

export default Card;
26 changes: 23 additions & 3 deletions nepalingo-web/src/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind base;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make sure that lint runs on this file - the spacing looks a bit off

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the lint catches formatting issues like this, but try to get rid of the extra spaces in this file.
On a related note, there are also lint issues that you need to fix. Error that appear when you run the command pnpm run lint. You can also see the errors in github actions like so:

CleanShot 2024-07-08 at 22 05 27

Fix any errors that appear for your files, you can ignore the errors that appear related to useNewari.

@tailwind components;
@tailwind utilities;

.backface-hidden {
backface-visibility: hidden;
}

.flipped .rotateY-180 {
transform: rotateY(0deg);
}

.flipped .rotateY-0 {
transform: rotateY(-180deg);
}

.rotateY-180 {
transform: rotateY(180deg);
}

.rotateY-0 {
transform: rotateY(0deg);
}
Loading