-
-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
10 changed files
with
345 additions
and
29 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
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,47 @@ | ||
import clsx from 'clsx' | ||
import type { FC } from 'react' | ||
import type { ToastProps, TypeOptions } from 'react-toastify/dist/types' | ||
|
||
import { MotionButtonBase } from '../ui/button' | ||
|
||
const typeMap: Record<TypeOptions, JSX.Element> = { | ||
success: <i className="icon-[mingcute--check-fill] text-uk-green-light" />, | ||
error: <i className="icon-[mingcute--close-fill] text-uk-red-light" />, | ||
info: <i className="icon-[mingcute--information-fill] text-uk-blue-light" />, | ||
warning: <i className="icon-[mingcute--alert-fill] text-uk-orange-light" />, | ||
default: ( | ||
<i className="icon-[mingcute--information-fill] text-uk-blue-light" /> | ||
), | ||
} | ||
|
||
export const ToastCard: FC<{ | ||
message: string | ||
toastProps?: ToastProps | ||
iconElement?: JSX.Element | ||
closeToast?: () => void | ||
}> = (props) => { | ||
const { iconElement, message, closeToast } = props | ||
|
||
return ( | ||
<div | ||
className={clsx( | ||
'relative w-full overflow-hidden rounded-xl shadow-out-sm', | ||
'my-4 mr-4 px-4 py-5', | ||
'bg-base-100/90 backdrop-blur-sm', | ||
'border border-slate-100/80 dark:border-neutral-900/80', | ||
'space-x-4', | ||
'flex items-center', | ||
)} | ||
> | ||
{iconElement ?? typeMap[props.toastProps?.type ?? 'default']} | ||
<span>{message}</span> | ||
|
||
<MotionButtonBase | ||
className="absolute bottom-0 right-3 top-0 flex items-center text-sm text-base-content/40 duration-200 hover:text-base-content/80" | ||
onClick={closeToast} | ||
> | ||
<i className="icon-[mingcute--close-fill] p-2" /> | ||
</MotionButtonBase> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use client' | ||
|
||
import { useQueryClient } from '@tanstack/react-query' | ||
import { motion } from 'framer-motion' | ||
import { produce } from 'immer' | ||
import type { NoteWrappedPayload } from '@mx-space/api-client' | ||
|
||
import { MotionButtonBase } from '~/components/ui/button' | ||
import { microReboundPreset } from '~/constants/spring' | ||
import { useNoteData } from '~/hooks/data/use-note' | ||
import { toast } from '~/lib/toast' | ||
import { queries } from '~/queries/definition' | ||
import { apiClient } from '~/utils/request' | ||
|
||
export const NoteActionAside = () => { | ||
return ( | ||
<div className="absolute bottom-0 max-h-[300px] flex-col space-y-4"> | ||
<LikeButton /> | ||
</div> | ||
) | ||
} | ||
|
||
const LikeButton = () => { | ||
const note = useNoteData() | ||
|
||
const queryClient = useQueryClient() | ||
if (!note) return null | ||
const id = note.id | ||
const handleLike = () => { | ||
apiClient.note.likeIt(id).then(() => { | ||
queryClient.setQueriesData( | ||
queries.note.byNid(note.nid.toString()), | ||
(old: any) => { | ||
return produce(old as NoteWrappedPayload, (draft) => { | ||
draft.data.count.like += 1 | ||
}) | ||
}, | ||
) | ||
}) | ||
} | ||
return ( | ||
<MotionButtonBase | ||
className="flex flex-col space-y-2" | ||
onClick={() => { | ||
handleLike() | ||
toast('谢谢你!', undefined, { | ||
iconElement: ( | ||
<motion.i | ||
className="icon-[mingcute--heart-fill] text-uk-red-light" | ||
initial={{ | ||
scale: 0.96, | ||
}} | ||
animate={{ | ||
scale: 1.12, | ||
}} | ||
transition={{ | ||
...microReboundPreset, | ||
delay: 1, | ||
repeat: 5, | ||
}} | ||
/> | ||
), | ||
}) | ||
}} | ||
> | ||
<i className="icon-[mingcute--heart-fill] text-[24px] opacity-80 duration-200 hover:text-uk-red-light hover:opacity-100" /> | ||
</MotionButtonBase> | ||
) | ||
} |
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,26 @@ | ||
import { createElement } from 'react' | ||
import { toast as Toast } from 'react-toastify' | ||
import type { ToastOptions, TypeOptions } from 'react-toastify' | ||
|
||
import { ToastCard } from '~/components/common/ToastCard' | ||
|
||
export const toast = ( | ||
message: string, | ||
type?: TypeOptions, | ||
options?: ToastOptions & { | ||
iconElement?: JSX.Element | ||
}, | ||
) => { | ||
const { iconElement, ...rest } = options || {} | ||
return Toast(createElement(ToastCard, { message, iconElement }), { | ||
type, | ||
position: 'bottom-right', | ||
autoClose: 3000, | ||
pauseOnHover: true, | ||
hideProgressBar: true, | ||
|
||
closeOnClick: true, | ||
closeButton: false, | ||
...rest, | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
@import './print.css'; | ||
@import './clerk.css'; | ||
@import './image-zoom.css'; | ||
@import './toastify.css'; |
Oops, something went wrong.