-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 🔖 release new app version
- Loading branch information
Showing
32 changed files
with
619 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
prisma/migrations/20230224000616_remove_upvotes_and_add_favorite/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the `Upvote` table. If the table is not empty, all the data it contains will be lost. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "Upvote" DROP CONSTRAINT "Upvote_deckId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Upvote" DROP CONSTRAINT "Upvote_userId_fkey"; | ||
|
||
-- DropTable | ||
DROP TABLE "Upvote"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "Favorite" ( | ||
"id" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"userId" TEXT NOT NULL, | ||
"deckId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "Favorite_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Favorite_userId_deckId_key" ON "Favorite"("userId", "deckId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Favorite" ADD CONSTRAINT "Favorite_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Favorite" ADD CONSTRAINT "Favorite_deckId_fkey" FOREIGN KEY ("deckId") REFERENCES "Deck"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/components/deck-card-list/components/favorite-button.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useState } from 'react' | ||
|
||
import { HeartIcon as EmptyHeartIcon } from '@heroicons/react/24/outline' | ||
import { HeartIcon as FilledHeartIcon } from '@heroicons/react/24/solid' | ||
import { useSession } from 'next-auth/react' | ||
|
||
import { api } from '~/utils/api' | ||
import { notify } from '~/utils/toast' | ||
|
||
import type { FavoriteButtonProps } from '../types/deck-card-list.types' | ||
|
||
export function InnerFavoriteButton(props: FavoriteButtonProps) { | ||
const { deck } = props | ||
|
||
const { data: user } = useSession() | ||
const apiContext = api.useContext() | ||
|
||
const invalidateDeckQueries = () => { | ||
apiContext.decks.invalidate() | ||
} | ||
|
||
const { mutate: addFavorite } = api.decks.addFavorite.useMutation({ | ||
onSuccess: invalidateDeckQueries, | ||
}) | ||
const { mutate: removeFavorite } = api.decks.removeFavorite.useMutation({ | ||
onSuccess: invalidateDeckQueries, | ||
}) | ||
|
||
const [isFavorite, setIsFavorite] = useState(deck.isFavorite) | ||
const [favorites, setFavorites] = useState(deck.favorites) | ||
|
||
const Icon = isFavorite ? FilledHeartIcon : EmptyHeartIcon | ||
|
||
const handleButtonClick = () => { | ||
if (!user) { | ||
notify.warning('Você precisa estar logado para executar essa ação!') | ||
return | ||
} | ||
|
||
const toggleFavorite = isFavorite ? removeFavorite : addFavorite | ||
toggleFavorite({ deckId: deck.id }) | ||
setIsFavorite(!isFavorite) | ||
setFavorites(favorites + (isFavorite ? -1 : 1)) | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={handleButtonClick} | ||
className='absolute bottom-0 right-0 flex items-center gap-2 p-2' | ||
> | ||
<span>{favorites}</span> | ||
<Icon className='h-8 w-8 text-primary-900' /> | ||
</button> | ||
) | ||
} | ||
|
||
export function FavoriteButton(props: FavoriteButtonProps) { | ||
return ( | ||
<InnerFavoriteButton | ||
{...props} | ||
/** | ||
* Add key so the component gets updated when favorites or isFavorite changes | ||
*/ | ||
key={`${props.deck.isFavorite}-${props.deck.favorites}`} | ||
/> | ||
) | ||
} |
70 changes: 0 additions & 70 deletions
70
src/components/deck-card-list/components/upvote-button.component.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { DeckCardList } from './deck-card-list.component' | ||
export { DecksToBeReviewed } from './decks-to-be-reviewed.component' | ||
export { UserFavoriteDecks } from './user-favorite-decks.component' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import type { Deck } from '@prisma/client' | ||
|
||
export type DeckCardListProps = { | ||
decks: Array<Deck & { isUpvoted: boolean; upvotes: number }> | ||
decks: Array<Deck & { isFavorite: boolean; favorites: number }> | ||
} | ||
|
||
export type ErrorProps = { | ||
onRetryPress: () => void | ||
} | ||
|
||
export type UpvoteButtonProps = { | ||
export type FavoriteButtonProps = { | ||
deck: DeckCardListProps['decks'][number] | ||
} |
3 changes: 3 additions & 0 deletions
3
src/components/deck-card-list/types/user-favorite-decks.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type UserFavoriteDecksProps = { | ||
isVisible?: boolean | ||
} |
58 changes: 58 additions & 0 deletions
58
src/components/deck-card-list/user-favorite-decks.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { InView } from 'react-intersection-observer' | ||
|
||
import { api } from '~/utils/api' | ||
|
||
import { Loader } from '../loader' | ||
import { DeckCardList } from './deck-card-list.component' | ||
import type { UserFavoriteDecksProps } from './types/user-favorite-decks.types' | ||
|
||
export function UserFavoriteDecks(props: UserFavoriteDecksProps) { | ||
const { isVisible = true } = props | ||
|
||
const { | ||
data, | ||
isError, | ||
refetch, | ||
isLoading, | ||
hasNextPage, | ||
fetchNextPage, | ||
isFetchingNextPage, | ||
} = api.decks.favorites.useInfiniteQuery( | ||
{}, | ||
{ | ||
getNextPageParam: lastPage => lastPage.nextCursor, | ||
keepPreviousData: true, | ||
enabled: isVisible, | ||
}, | ||
) | ||
|
||
const decks = data?.pages.flatMap(page => page.decks) ?? [] | ||
const hasLoadedDecks = decks.length > 0 | ||
|
||
const renderContent = () => { | ||
if (isLoading) return <DeckCardList.Loading /> | ||
|
||
if (!hasLoadedDecks && isError) { | ||
return <DeckCardList.Error onRetryPress={refetch} /> | ||
} | ||
|
||
return <DeckCardList decks={decks} /> | ||
} | ||
|
||
return ( | ||
<div className='flex flex-col items-center'> | ||
{renderContent()} | ||
<InView | ||
as='div' | ||
className='mt-5 flex w-full items-center justify-center' | ||
onChange={inView => { | ||
if (inView && hasNextPage && !isError && !isFetchingNextPage) { | ||
fetchNextPage() | ||
} | ||
}} | ||
> | ||
{isFetchingNextPage ? <Loader /> : null} | ||
</InView> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
8e6d7bf
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.
Successfully deployed to the following URLs:
briskly – ./
briskly-emiliosheinz.vercel.app
briskly.app
briskly-git-main-emiliosheinz.vercel.app