Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/app/board/[boardId]/_components/Header/SelectModeHeader.tsx
  • Loading branch information
junseublim committed Jan 22, 2025
2 parents 01982a3 + 26bd99b commit e8503c0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/app/board/[boardId]/_contexts/SelectModeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface SelectContextProps {
selectedIds: number[]
setIsSelectMode: (isSelectMode: boolean) => void
toggleSelectedId: (id: number) => void
resetSelectedIds: () => void
MAX_SELECT_COUNT: number
}

Expand All @@ -16,6 +17,7 @@ const SelectContext = createContext<SelectContextProps>({
selectedIds: [],
setIsSelectMode: () => {},
toggleSelectedId: () => {},
resetSelectedIds: () => {},
MAX_SELECT_COUNT: 0,
})

Expand Down Expand Up @@ -58,13 +60,18 @@ export const SelectContextProvider = ({
}
}

const resetSelectedIds = () => {
setSelectedIds([])
}

const value = useMemo(
() => ({
isSelectMode,
setIsSelectMode,
selectedIds,
toggleSelectedId,
MAX_SELECT_COUNT: 9,
resetSelectedIds,
}),
[isSelectMode, selectedIds],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import DownloadIcon from 'public/icons/download.svg'
import ScreenshotLoading from 'public/images/screenshot_loading.gif'
import { useEffect, useState } from 'react'
import { sendGTMEvent } from '@next/third-parties/google'
import Toast from '@/components/Toast'
import GoBackModal from './GoBackModal'

const DecorateScreenshot = () => {
Expand All @@ -31,6 +32,8 @@ const DecorateScreenshot = () => {
const [isDownloaded, setIsDownloaded] = useState(false)
const { isDecorating, setIsDecorating } = useSticker()
const [isGoBackModalOpen, setIsGoBackModalOpen] = useState(false)
const [showDownloadCompleteToast, setShowDownloadCompleteToast] =
useState(false)
const router = useRouter()

useEffect(() => {
Expand Down Expand Up @@ -76,7 +79,9 @@ const DecorateScreenshot = () => {
.then((res) => res.blob())
.then((blob) => {
const screenshotUrl = URL.createObjectURL(blob)
downloadImage(screenshotUrl, boardName)
downloadImage(screenshotUrl, boardName).then(() => {
setShowDownloadCompleteToast(true)
})
setIsLoadingDownload(false)
setIsDownloaded(true)
})
Expand Down Expand Up @@ -168,6 +173,15 @@ const DecorateScreenshot = () => {
</span>
</SubmitBtn>
)}
<Toast
className="bottom-1/2"
isOpen={showDownloadCompleteToast}
setClose={() => {
setShowDownloadCompleteToast(false)
}}
>
파일에 저장되었습니다!
</Toast>
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const StickerIcon = ({ num }: StickerIconProps) => {

const SelectSticker = () => {
const { status } = useSession()
const stickerMenus = status ? STICKER_MENU : GUEST_STICKER_MENU
const stickerMenus =
status === 'authenticated' ? STICKER_MENU : GUEST_STICKER_MENU

return (
<div className="w-md mx-auto flex h-dvh max-w-md flex-1 flex-col bg-gray-1000/70 py-10 backdrop-blur-md">
Expand Down
15 changes: 13 additions & 2 deletions src/components/Toast/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { ReactNode, useEffect, useState } from 'react'
import ReactDOM from 'react-dom'
import { twMerge } from 'tailwind-merge'

interface ToastProps {
isOpen: boolean
setClose: () => void
children: ReactNode
duration?: number
className?: string
}

const Toast = ({ isOpen, setClose, children, duration = 3000 }: ToastProps) => {
const Toast = ({
isOpen,
setClose,
children,
duration = 3000,
className = '',
}: ToastProps) => {
const [isVisible, setIsVisible] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -39,7 +47,10 @@ const Toast = ({ isOpen, setClose, children, duration = 3000 }: ToastProps) => {
return isOpen
? ReactDOM.createPortal(
<div
className={`fixed bottom-10 left-1/2 -translate-x-1/2 transform rounded-3xl bg-gray-1000 bg-opacity-60 px-4 py-1 backdrop-blur-[2px] ${isVisible ? 'opacity-100' : 'opacity-0'} transition-opacity duration-300`}
className={twMerge(
`fixed bottom-10 left-1/2 -translate-x-1/2 transform rounded-3xl bg-gray-1000 bg-opacity-60 px-4 py-1 backdrop-blur-[2px] ${isVisible ? 'opacity-100' : 'opacity-0'} transition-opacity duration-300`,
className,
)}
onTransitionEnd={handleTransitionEnd}
>
<div className="whitespace-nowrap font-jooree text-gray-0">
Expand Down
27 changes: 20 additions & 7 deletions src/lib/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ export const getImageWidthHeight = (
}

export const downloadImage = (imageUrl: string, imageName = 'file') => {
const a = document.createElement('a')
a.href = imageUrl
a.download = `${imageName}.png`
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(imageUrl)
return new Promise<void>((resolve, reject) => {
try {
const a = document.createElement('a')
a.href = imageUrl
a.download = `${imageName}.png`
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(imageUrl)
window.addEventListener(
'focus',
() => {
resolve()
},
{ once: true },
)
} catch (e) {
reject(e)
}
})
}

0 comments on commit e8503c0

Please sign in to comment.