Show toast when remix button clicked

This commit is contained in:
Justin Edmund 2023-01-28 21:09:24 -08:00
parent fb76ca6665
commit cd6e58da18
5 changed files with 42 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
import { useSnapshot } from 'valtio' import { useSnapshot } from 'valtio'
import { deleteCookie } from 'cookies-next' import { deleteCookie } from 'cookies-next'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next' import { Trans, useTranslation } from 'next-i18next'
import classNames from 'classnames' import classNames from 'classnames'
import clonedeep from 'lodash.clonedeep' import clonedeep from 'lodash.clonedeep'
import Link from 'next/link' import Link from 'next/link'
@ -43,11 +43,13 @@ const Header = () => {
// State management // State management
const [copyToastOpen, setCopyToastOpen] = useState(false) const [copyToastOpen, setCopyToastOpen] = useState(false)
const [remixToastOpen, setRemixToastOpen] = useState(false)
const [loginModalOpen, setLoginModalOpen] = useState(false) const [loginModalOpen, setLoginModalOpen] = useState(false)
const [signupModalOpen, setSignupModalOpen] = useState(false) const [signupModalOpen, setSignupModalOpen] = useState(false)
const [settingsModalOpen, setSettingsModalOpen] = useState(false) const [settingsModalOpen, setSettingsModalOpen] = useState(false)
const [leftMenuOpen, setLeftMenuOpen] = useState(false) const [leftMenuOpen, setLeftMenuOpen] = useState(false)
const [rightMenuOpen, setRightMenuOpen] = useState(false) const [rightMenuOpen, setRightMenuOpen] = useState(false)
const [originalName, setOriginalName] = useState('')
// Snapshots // Snapshots
const { account } = useSnapshot(accountState) const { account } = useSnapshot(accountState)
@ -61,6 +63,14 @@ const Header = () => {
setCopyToastOpen(false) setCopyToastOpen(false)
} }
function handleRemixToastOpenChanged(open: boolean) {
setRemixToastOpen(open)
}
function handleRemixToastCloseClicked() {
setRemixToastOpen(false)
}
function handleLeftMenuButtonClicked() { function handleLeftMenuButtonClicked() {
setLeftMenuOpen(!leftMenuOpen) setLeftMenuOpen(!leftMenuOpen)
} }
@ -147,10 +157,13 @@ const Header = () => {
} }
function remixTeam() { function remixTeam() {
setOriginalName(party.name ? party.name : t('no_title'))
if (party.shortcode) if (party.shortcode)
api.remix(party.shortcode).then((response) => { api.remix(party.shortcode).then((response) => {
const remix = response.data.party const remix = response.data.party
router.push(`/p/${remix.shortcode}`) router.push(`/p/${remix.shortcode}`)
setRemixToastOpen(true)
}) })
} }
@ -222,6 +235,23 @@ const Header = () => {
) )
} }
const remixToast = () => {
return (
<Toast
open={remixToastOpen}
duration={2400}
type="foreground"
content={
<Trans i18nKey="toasts.remixed">
You remixed <strong>{{ title: originalName }}</strong>
</Trans>
}
onOpenChange={handleRemixToastOpenChanged}
onCloseClick={handleRemixToastCloseClicked}
/>
)
}
const saveButton = () => { const saveButton = () => {
return ( return (
<Tooltip content={t('tooltips.save')}> <Tooltip content={t('tooltips.save')}>
@ -469,6 +499,7 @@ const Header = () => {
{left()} {left()}
{right()} {right()}
{urlCopyToast()} {urlCopyToast()}
{remixToast()}
{settingsModal()} {settingsModal()}
{loginModal()} {loginModal()}
{signupModal()} {signupModal()}

View file

@ -52,5 +52,9 @@
p { p {
line-height: 1.3; line-height: 1.3;
strong {
font-weight: $bold;
}
} }
} }

View file

@ -7,7 +7,7 @@ import './index.scss'
interface Props extends ToastPrimitive.ToastProps { interface Props extends ToastPrimitive.ToastProps {
className?: string className?: string
title?: string title?: string
content: string content: React.ReactNode
onCloseClick: () => void onCloseClick: () => void
} }
@ -39,7 +39,7 @@ const Toast = ({
<p>{content}</p> <p>{content}</p>
</ToastPrimitive.Description> </ToastPrimitive.Description>
{children && ( {children && (
<ToastPrimitive.Action asChild altText={content}> <ToastPrimitive.Action asChild altText="">
{children} {children}
</ToastPrimitive.Action> </ToastPrimitive.Action>
)} )}

View file

@ -397,7 +397,8 @@
} }
}, },
"toasts": { "toasts": {
"copied": "This party's URL was copied to your clipboard" "copied": "This party's URL was copied to your clipboard",
"remixed": "You remixed {{title}}"
}, },
"tokens": { "tokens": {
"remix": "Remixed" "remix": "Remixed"

View file

@ -398,7 +398,8 @@
} }
}, },
"toasts": { "toasts": {
"copied": "この編成のURLはクリップボードにコピーされました" "copied": "この編成のURLはクリップボードにコピーされました",
"remixed": "{{title}}をリミックスしました"
}, },
"tokens": { "tokens": {
"remix": "リミックスされた" "remix": "リミックスされた"