Skip to content

Commit

Permalink
feat: add hide/reveal logic on words
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenius1424 committed Oct 29, 2024
1 parent 875f3b2 commit ccd8047
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 26 deletions.
3 changes: 2 additions & 1 deletion apps/learnbefore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"i18next": "^23.11.5",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-http-backend": "^2.5.2",
"lucide-react": "^0.383.0",
"postcss": "^8.4.38",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand All @@ -25,11 +26,11 @@
"tesseract.js": "^5.1.0"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/types": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@repo/eslint-config": "workspace:*",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.3.0",
Expand Down
65 changes: 65 additions & 0 deletions apps/learnbefore/src/components/word-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { useState } from "react"
import { Eye, EyeOff, BookOpen, Check, X } from "lucide-react"
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "@ui/components/ui/card"
import { Button } from "@ui/components/ui/button"
import { Word } from "@repo/types/words.ts"

type WordCardProps = {
word: Word
}

export const WordCard: React.FC<WordCardProps> = ({ word }) => {
const [showMeaning, setShowMeaning] = useState(false)

const handleCardClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (!(e.target as HTMLElement).closest("button")) {
setShowMeaning(!showMeaning)
}
}
return (
<Card onClick={handleCardClick} className="w-full max-w-md">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-2xl font-bold">{word.word}</CardTitle>
<div className="flex items-center space-x-2">
<Button
variant="ghost"
size="icon"
onClick={() => setShowMeaning(!showMeaning)}
aria-label={showMeaning ? "Hide meaning" : "Show meaning"}
>
{showMeaning ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</Button>
<Button variant="ghost" size="icon" aria-label="Ignore word">
<X className="h-4 w-4" />
</Button>
</div>
</CardHeader>
{showMeaning && (
<CardContent>
<p className="text-muted-foreground mb-1">{word.translation}</p>
<p className="font-medium">{word.meaning}</p>
</CardContent>
)}
<CardFooter className="flex justify-between">
<Button variant="secondary" size="sm">
<BookOpen className="mr-2 h-4 w-4" />
Learn
</Button>
<Button variant="outline" size="sm">
<Check className="mr-2 h-4 w-4" />
Known word
</Button>
</CardFooter>
</Card>
)
}
10 changes: 5 additions & 5 deletions apps/learnbefore/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ if (!PUBLISHABLE_KEY) {
}

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<ClerkProvider publishableKey={PUBLISHABLE_KEY}>
<App />
</ClerkProvider>
</React.StrictMode>,
// <React.StrictMode>
<ClerkProvider publishableKey={PUBLISHABLE_KEY}>
<App />
</ClerkProvider>,
// </React.StrictMode>,
)
20 changes: 2 additions & 18 deletions apps/learnbefore/src/pages/chat-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useState } from "react"
import { AppShell } from "../components/app-shell"
import { Message, Word } from "@repo/types/words.ts"
import { Card, CardContent } from "@repo/ui/components/ui/card"
import { Input } from "@ui/components/ui/input.tsx"
import { Button } from "@ui/components/ui/button.tsx"
import { PaperclipIcon } from "../icons/paperclip-icon.tsx"
Expand All @@ -11,6 +10,7 @@ import { fetchJson } from "../helpers/fetch-json.ts"
import { useScrollToRef } from "../helpers/use-scroll-to-ref.ts"
import { useTextFileUpload } from "../helpers/use-text-file-upload.ts"
import { ChatWelcomeMessage } from "../components/chat-welcome-message.tsx"
import { WordCard } from "../components/word-card.tsx"

export const ChatPage: React.FC = () => {
const [messages, setMessages] = useState<Message[] | null>(null)
Expand Down Expand Up @@ -132,7 +132,7 @@ export const ChatPage: React.FC = () => {
</div>
<div className="flex flex-wrap gap-2 justify-center w-full">
{message.words.map((word, wordIndex) => (
<WordCard key={wordIndex} word={word} />
<WordCard word={word} key={wordIndex} />
))}
</div>
</React.Fragment>
Expand Down Expand Up @@ -182,19 +182,3 @@ export const ChatPage: React.FC = () => {
</AppShell>
)
}

const WordCard: React.FC<{ word: Word }> = ({ word }) => (
<Card className="bg-white shadow rounded-lg p-4">
<CardContent>
<div className="flex items-center space-x-4">
<div>
<p className="text-2xl text-center font-semibold text-gray-800">
{word.word}
{word.translation?.length > 2 ? ` - ${word.translation}` : null}
</p>
<p className="text-sm text-center text-gray-500">{word.meaning}</p>
</div>
</div>
</CardContent>
</Card>
)
2 changes: 1 addition & 1 deletion apps/learnbefore/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
server: {
proxy: {
"/api": {
target: `http://91.92.136.244:${PORT}`,
target: `http://localhost:${PORT}`,
changeOrigin: true,
ws: true,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"dev": "turbo dev --env-mode=loose",
"lint": "turbo lint",
"volta:install": "curl https://get.volta.sh | bash",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
Expand Down
36 changes: 36 additions & 0 deletions packages/ui/src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@ui/lib/utils"

const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
},
)

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
)
}

export { Badge, badgeVariants }
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ccd8047

Please sign in to comment.