-
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.
- Loading branch information
Showing
8 changed files
with
107 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
".next/**/*" | ||
], | ||
"rules": { | ||
"no-unused-vars": "error", | ||
"import/order": [ | ||
"error", | ||
{ | ||
|
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 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,59 @@ | ||
'use client'; | ||
|
||
import { useOptimistic, useState } from 'react'; | ||
|
||
import { changeFaveStatus } from '@/app/actions/list.action'; | ||
|
||
import { Button } from './ui/button'; | ||
|
||
export function FavoriteListButton({ | ||
isFave = false, | ||
spaceId, | ||
listId | ||
}: { | ||
isFave?: boolean | null; | ||
listId: string; | ||
spaceId: string; | ||
}) { | ||
const [favoriteStatus, setfavoriteStatus] = useState(isFave); | ||
|
||
const [favoriteOptimisticStatus, updateOptimisticStatus] = useOptimistic< | ||
typeof favoriteStatus, | ||
typeof favoriteStatus | ||
>(favoriteStatus, (_, newState) => { | ||
return newState; | ||
}); | ||
|
||
return ( | ||
<form | ||
action={async (formData: FormData) => { | ||
const faveStatus = !!formData.get('favorite'); | ||
|
||
updateOptimisticStatus(faveStatus); | ||
|
||
await changeFaveStatus(formData); | ||
setfavoriteStatus(faveStatus); | ||
}} | ||
> | ||
<input type="text" name="listId" defaultValue={listId} hidden readOnly /> | ||
<input | ||
type="text" | ||
name="spaceId" | ||
defaultValue={spaceId} | ||
hidden | ||
readOnly | ||
/> | ||
<input | ||
type="checkbox" | ||
name="favorite" | ||
checked={!favoriteOptimisticStatus} | ||
hidden | ||
readOnly | ||
/> | ||
|
||
<Button variant="secondary" size="icon"> | ||
{favoriteOptimisticStatus ? '★' : '☆'} | ||
</Button> | ||
</form> | ||
); | ||
} |
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,3 +1,4 @@ | ||
/* eslint no-unused-vars: 0 */ | ||
import { headers } from 'next/headers'; | ||
import { userAgent } from 'next/server'; | ||
|
||
|
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,10 +1,11 @@ | ||
import { PrismaAdapter } from '@next-auth/prisma-adapter'; | ||
import NextAuth, { DefaultSession } from 'next-auth'; | ||
import NextAuth from 'next-auth'; | ||
import Google from 'next-auth/providers/google'; | ||
|
||
import { prisma } from '@/lib/prisma'; | ||
|
||
declare module '../node_modules/.pnpm/@[email protected]/node_modules/@auth/core/types.d.ts' { | ||
// eslint-disable-next-line | ||
interface Session { | ||
user: { | ||
id: string; | ||
|
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