Skip to content

Commit

Permalink
chore: πŸ”– release new app version
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliosheinz authored Apr 14, 2023
2 parents 7cf3668 + 34cf9c5 commit db4c957
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["superjson", "trpc", "TRPC"]
"cSpell.words": ["healthcheck", "Healthcheck", "superjson", "trpc", "TRPC"]
}
9 changes: 8 additions & 1 deletion src/contexts/create-new-deck/create-new-deck.context.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useState } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'

import { zodResolver } from '@hookform/resolvers/zod'
Expand Down Expand Up @@ -149,6 +149,13 @@ export function CreateNewDeckContextProvider(
},
)

/**
* Healthcheck to wake up the generate flash cards API
*/
useEffect(() => {
fetch(`${env.NEXT_PUBLIC_BRISKLY_GENERATE_FLASH_CARDS_API_URL}/healthcheck`)
}, [])

const addTopic = (topic: string) => {
setTopics(topics => [
...topics.filter(({ title }) => title !== topic),
Expand Down
2 changes: 2 additions & 0 deletions src/modules/decks/components/study-session-card.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export const StudySessionCard = (props: { deckId: string }) => {
const createStudySessionMutation = api.studySession.create.useMutation({
onSuccess: () => {
apiContext.decks.toBeReviewed.invalidate()
apiContext.decks.withStudySession.invalidate()
apiContext.studySession.getStudySessionBasicInfo.invalidate({ deckId })
},
})
const deleteStudySessionMutation = api.studySession.delete.useMutation({
onSuccess: () => {
apiContext.decks.toBeReviewed.invalidate()
apiContext.decks.withStudySession.invalidate()
apiContext.studySession.getStudySessionBasicInfo.invalidate({ deckId })
notify.success('SessΓ£o de estudo deletada com sucesso!')
},
Expand Down
35 changes: 30 additions & 5 deletions src/modules/decks/create/components/cards.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'

import { PlusCircleIcon } from '@heroicons/react/24/outline'

Expand All @@ -14,6 +14,33 @@ type NewCardModalState = {
cardIdx?: number
}

const loadingSteps = [
'Coletando informaçáes',
'Analisando o contexto',
'Gerando os cards',
]

const CYCLE_INTERVAL = 3000

export const AiPoweredFlashCardsLoader = () => {
const [currentLoadingStep, setCurrentLoadingStep] = useState(0)

useEffect(() => {
const interval = setInterval(() => {
setCurrentLoadingStep(state => (state + 1) % loadingSteps.length)
}, CYCLE_INTERVAL)

return () => clearInterval(interval)
}, [])

return (
<div className='flex flex-col items-center justify-center gap-3'>
<Loader />
<p>{loadingSteps[currentLoadingStep]}</p>
</div>
)
}

export const Cards = () => {
const {
cards,
Expand Down Expand Up @@ -52,7 +79,7 @@ export const Cards = () => {

const renderAiCardsButton = () => {
const successContent = isGeneratingAiPoweredCards ? (
<Loader />
<AiPoweredFlashCardsLoader />
) : (
<span className='text-4xl'>πŸ€–</span>
)
Expand All @@ -67,9 +94,7 @@ export const Cards = () => {
<Card onClick={generateAiPoweredCards}>
{hasErrorGeneratingAiPoweredCards ? errorContent : successContent}
<div className='absolute right-0 top-0 p-3'>
<Tooltip
hint={`AlΓ©m de criar seus prΓ³prios Flashcards manualmente vocΓͺ pode deixar que a nossa InteligΓͺncia Artificial os gere para vocΓͺ se baseando nos tΓ³picos e tΓ­tulo previamente cadastrados acima. Caso ocorra um erro ao gerar os Cards, vocΓͺ pode apenas tentar novamente!`}
/>
<Tooltip hint='AlΓ©m de criar seus prΓ³prios Flashcards manualmente vocΓͺ pode deixar que a nossa InteligΓͺncia Artificial os gere para vocΓͺ se baseando nos tΓ³picos e tΓ­tulo previamente cadastrados acima.' />
</div>
</Card>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DeckCardList } from '~/components/deck-card-list'
import { api } from '~/utils/api'

type UserDecksProps = {
userId: string
isVisible: boolean
}

export function DecksWithStudySession(props: UserDecksProps) {
const { isVisible } = props

const { data, isLoading, isError, refetch } =
api.decks.withStudySession.useQuery(undefined, { enabled: isVisible })

if (isLoading) return <DeckCardList.Loading />

if (isError) {
return <DeckCardList.Error onRetryPress={refetch} />
}

return <DeckCardList decks={data} />
}
11 changes: 11 additions & 0 deletions src/modules/profile/constants/profile-menu-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@ const UserFavoriteDecks = dynamic(() =>
),
)

const DecksWithStudySession = dynamic(() =>
import('../components/decks-with-study-session.component').then(
module => module.DecksWithStudySession,
),
)

export const profileMenuTabs = [
{
name: 'Decks',
content: UserDecks,
isProfileOwnerOnly: false,
},
{
name: 'Meus Estudos',
content: DecksWithStudySession,
isProfileOwnerOnly: true,
},
{
name: 'Para Revisar',
content: DecksToBeReviewed,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/profile/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ const ProfilePage: WithAuthentication<

<section className='flex flex-col md:flex-[8]'>
<Tab.Group>
<Tab.List className='flex space-x-1 p-1'>
<Tab.List className='flex space-x-1 overflow-x-auto p-1'>
{tabs.map(tab => (
<Tab
key={tab.name}
className={({ selected }) =>
classNames(
'border-b-2 py-2 px-5 text-base font-medium leading-5 text-primary-900 ring-primary-50 ring-opacity-60 ring-offset-2 ring-offset-primary-500 focus:outline-none focus:ring-2',
'min-w-max border-b-2 py-2 px-5 text-base font-medium leading-5 text-primary-900 ring-primary-50 ring-opacity-60 ring-offset-2 ring-offset-primary-500 focus:outline-none focus:ring-2',
selected ? 'border-primary-900' : 'border-primary-50',
)
}
Expand Down
27 changes: 27 additions & 0 deletions src/server/api/routers/decks/decks.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ export const decksRouter = createTRPCRouter({
nextCursor,
}
}),
withStudySession: protectedProcedure.query(async ({ ctx }) => {
const { user } = ctx.session

const decks = await ctx.prisma.deck.findMany({
where: {
studySessions: {
some: {
userId: user.id,
},
},
},
orderBy: { createdAt: 'desc' },
include: {
favorites: true,
},
})

return decks.map(deck => ({
...deck,
image: getS3ImageUrl(deck.image),
favorites: deck.favorites.length,
isFavorite: deck.favorites
.map(favorite => favorite.userId)
.includes(user.id),
}))
}),
byUser: protectedProcedure
.input(z.object({ userId: z.string() }))
.query(async ({ input: { userId }, ctx }) => {
Expand Down Expand Up @@ -218,6 +244,7 @@ export const decksRouter = createTRPCRouter({
.includes(signedInUser.id),
}))
}),

addFavorite: protectedProcedure
.input(z.object({ deckId: z.string() }))
.mutation(async ({ input: { deckId }, ctx }) => {
Expand Down

1 comment on commit db4c957

@vercel
Copy link

@vercel vercel bot commented on db4c957 Apr 14, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

briskly – ./

briskly-git-main-emiliosheinz.vercel.app
briskly-emiliosheinz.vercel.app
briskly.app

Please sign in to comment.