Skip to content

Commit

Permalink
fix(count): change number to string
Browse files Browse the repository at this point in the history
  • Loading branch information
bdebon committed Nov 18, 2022
1 parent d451b5c commit 5379b2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions apps/devchoices-next/pages/question/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { PageTransitionWrapper, Question } from '@benjamincode/shared/ui'
import { QuestionContext } from '../_app'
import Image from 'next/future/image'
import { NextSeo } from 'next-seo'
import { TwitterIcon, TwitterShareButton } from 'next-share'

export const getStaticProps = async (context: { params: { slug: string } }): Promise<{ props: QuestionPageProps }> => {
const slug = context.params.slug
Expand Down Expand Up @@ -64,15 +63,16 @@ export function QuestionPage(props: QuestionPageProps) {
// todo replace with values fetched from database
fetch(`${process.env.NEXT_PUBLIC_API_URL}?slug=${slug}`)
.then((res) => res.json())
.then((data) => {
const left = data.find((v: VoteInterface) => v.position === 0) || { count: 0 }
const right = data.find((v: VoteInterface) => v.position === 1) || { count: 0 }
.then((data: VoteInterface[]) => {
console.log(data)
const left = data.find((v: VoteInterface) => v.position === '0') || { count: 0 }
const right = data.find((v: VoteInterface) => v.position === '1') || { count: 0 }
setVoteValues([+left.count, +right.count])
})
.catch(() => {
setVoteValues([Math.trunc(Math.random() * 1000), Math.trunc(Math.random() * 1000)])
})
}, [setVoteValues])
}, [setVoteValues, slug])

useEffect(() => {
const nextQuestion = computeNextQuestion()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface VoteInterface {
count: string
position: number
position: string
}

0 comments on commit 5379b2e

Please sign in to comment.