-
Notifications
You must be signed in to change notification settings - Fork 53
added favorites section #117
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| .fav-button { | ||
| /* Match the Generate button visual style from RandomQuote.css */ | ||
| font-size: 1.2rem; | ||
| background: white; | ||
| border-radius: 5px; | ||
| padding: 18px 20px; | ||
| border: 1px solid #4b4b4b; | ||
| box-shadow: 1px 1px 3px #4b4b4b; | ||
| margin: 10px 0; | ||
| transition-duration: 300ms; | ||
| cursor: pointer; | ||
| } | ||
| .fav-button:hover { | ||
| transform: scale(1.05); | ||
| background: black; | ||
| color: white; | ||
| } | ||
| .fav-button.saved { | ||
| background: #ffeaa7; | ||
| border-color: #ffcc00; | ||
| } | ||
|
|
||
| .fav-button.small { | ||
| /* helper class if a smaller variant is needed */ | ||
| padding: 6px 10px; | ||
| font-size: 1rem; | ||
| box-shadow: none; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import React, {useEffect, useState} from 'react'; | ||
| import './FavoriteButton.css'; | ||
| import { listFavorites, addFavorite, removeFavorite } from '../../utils/favoritesStorage'; | ||
|
|
||
| export default function FavoriteButton({ item }) { | ||
| const [saved, setSaved] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| const all = listFavorites(); | ||
| const exists = all.some((it) => JSON.stringify(it.content) === JSON.stringify(item.content)); | ||
|
||
| setSaved(!!exists); | ||
| }, [item]); | ||
|
|
||
| const handleToggle = () => { | ||
| if (saved) { | ||
| // remove | ||
| const all = listFavorites(); | ||
| const found = all.find((it) => JSON.stringify(it.content) === JSON.stringify(item.content)); | ||
|
||
| if (found) { | ||
| removeFavorite(found.id); | ||
| setSaved(false); | ||
| } | ||
| } else { | ||
| const added = addFavorite(item); | ||
| if (added) setSaved(true); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <button className={`fav-button ${saved ? 'saved' : ''}`} onClick={handleToggle} title={saved ? 'Remove from favorites' : 'Save to favorites'}> | ||
| {saved ? '★ Saved' : '☆ Save'} | ||
| </button> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .fav-button { | ||
| background: transparent; | ||
| border: 1px solid #ccc; | ||
| padding: 6px 10px; | ||
| border-radius: 6px; | ||
| cursor: pointer; | ||
| } | ||
| .fav-button.saved { | ||
| background: #ffeaa7; | ||
| border-color: #ffcc00; | ||
| } |
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.
Imported CSS file doesn't match the CSS module import pattern. Either use the
.module.cssfile that exists (FavoriteButton.module.css) or ensure this plain CSS file exists. Currently both files are created but only the plain CSS is imported.