Reaction Button Styling
This commit is contained in:
parent
11cba5caf0
commit
1bdc48f5c9
3 changed files with 30 additions and 19 deletions
|
|
@ -8,23 +8,23 @@ export default function Reaction({ slug }: { slug: string }) {
|
||||||
const [haveReacted, setHaveReacted] = useState(false)
|
const [haveReacted, setHaveReacted] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let browserId = localStorage.getItem(BROWSER_ID)
|
let browserId = localStorage.getItem(BROWSER_ID)
|
||||||
|
|
||||||
if (!browserId) {
|
|
||||||
browserId = uuidv7()
|
|
||||||
localStorage.setItem(BROWSER_ID, browserId)
|
|
||||||
}
|
|
||||||
|
|
||||||
api.haveIReacted({ ...reaction, browser_id: browserId }).then((response: boolean) => {
|
|
||||||
setHaveReacted(response)
|
|
||||||
})
|
|
||||||
|
|
||||||
api.reactionCount(slug).then((count) => {
|
if (!browserId) {
|
||||||
setReactionCount(count)
|
browserId = uuidv7()
|
||||||
})
|
localStorage.setItem(BROWSER_ID, browserId)
|
||||||
|
}
|
||||||
|
|
||||||
setReaction(prev => ({ ...prev, browser_id: browserId }))
|
api.haveIReacted({ ...reaction, browser_id: browserId }).then((response: boolean) => {
|
||||||
}, [])
|
setHaveReacted(response)
|
||||||
|
})
|
||||||
|
|
||||||
|
api.reactionCount(slug).then((count) => {
|
||||||
|
setReactionCount(count)
|
||||||
|
})
|
||||||
|
|
||||||
|
setReaction(prev => ({ ...prev, browser_id: browserId }))
|
||||||
|
}, [])
|
||||||
|
|
||||||
const handleReaction = () => {
|
const handleReaction = () => {
|
||||||
let hasError = false
|
let hasError = false
|
||||||
|
|
@ -51,8 +51,17 @@ export default function Reaction({ slug }: { slug: string }) {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button onClick={handleReaction}>
|
<button onClick={handleReaction}
|
||||||
{haveReacted ? "♥" : "🧭"} {reactionCount}
|
|
||||||
|
style="
|
||||||
|
font-size: 1rem;
|
||||||
|
width: 100%;
|
||||||
|
padding:8px;
|
||||||
|
font-family:Arial, Helvetica, sans-serif;
|
||||||
|
">
|
||||||
|
|
||||||
|
|
||||||
|
{haveReacted ? "♥ Yeah!" : "Hattest du Spaß beim Lesen?"} {reactionCount}
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -30,12 +30,14 @@ const localeDate = formatLocalizedDateString(postData.date);
|
||||||
<h3 id="subtitle">{postData.subtitle}</h3>
|
<h3 id="subtitle">{postData.subtitle}</h3>
|
||||||
<span id="introduction">{postData.introduction}</span>
|
<span id="introduction">{postData.introduction}</span>
|
||||||
</div>
|
</div>
|
||||||
<Reaction slug={postData.slug} client:load />
|
|
||||||
<div id="hr-knast">
|
<div id="hr-knast">
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
<article class="markdown-content">
|
<article class="markdown-content">
|
||||||
<slot />
|
<slot />
|
||||||
|
<div id="react">
|
||||||
|
<Reaction slug={postData.slug} client:load />
|
||||||
|
</div>
|
||||||
<NavBack client:load />
|
<NavBack client:load />
|
||||||
<p class="disclaimer">
|
<p class="disclaimer">
|
||||||
Disclaimer: Dieser Artikel ist ausschließlich privat und wird nicht
|
Disclaimer: Dieser Artikel ist ausschließlich privat und wird nicht
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ body {
|
||||||
font-weight: bolder;
|
font-weight: bolder;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
padding: 12px 12px 12px 0;
|
padding: 48px 12px 12px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-btn:hover {
|
.back-btn:hover {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue