11import { useState , useCallback , useEffect , useMemo } from 'react'
2- import { useDispatch } from 'react-redux'
2+ import { useDispatch , useSelector } from 'react-redux'
33import Link from 'next/link'
44import PropTypes from 'prop-types'
55
@@ -20,17 +20,20 @@ import { MESSAGE_SEVERITY } from '@/store/app/appSlice'
2020function FormItemsView ( { card } ) {
2121 const [ embedUrl , setEmbedUrl ] = useState ( '' )
2222 const dispatch = useDispatch ( )
23+ const notification = useSelector ( state => state . app . notification )
2324 const collapse = useMediaQuery ( '(max-width:1100px)' )
2425
2526 const subDirectory = ( process . env . NEXT_PUBLIC_BASE_PATH !== '' )
2627 ? process . env . NEXT_PUBLIC_BASE_PATH
2728 : ''
2829
29- const incrementTimestamp = useCallback ( ( ) => {
30+ const incrementTimestamp = useCallback ( ( isCard = true ) => {
3031 const timestamp = Math . floor ( ( new Date ( ) ) . getTime ( ) / 1000 )
3132
3233 return ( card !== null )
33- ? `${ window . location . origin } ${ subDirectory } /cards/embed?id=${ card . id } &ts=${ timestamp } `
34+ ? ( isCard )
35+ ? `${ window . location . origin } ${ subDirectory } /cards/embed?id=${ card . id } &ts=${ timestamp } `
36+ : `${ window . location . origin } ${ subDirectory } /cards/gallery?category=${ card . category } &ts=${ timestamp } `
3437 : window . location . origin
3538 } , [ card , subDirectory ] )
3639
@@ -41,12 +44,12 @@ function FormItemsView ({ card }) {
4144 } , [ card , subDirectory ] )
4245
4346 useEffect ( ( ) => {
44- const embed = incrementTimestamp ( )
47+ const embed = incrementTimestamp ( true )
4548 setEmbedUrl ( embed )
4649 } , [ incrementTimestamp ] )
4750
48- const copyToClipboard = ( ) => {
49- const embed = incrementTimestamp ( )
51+ const copyToClipboard = ( isCard = true ) => {
52+ const embed = incrementTimestamp ( isCard )
5053 setEmbedUrl ( embed )
5154 navigator . clipboard . writeText ( embed )
5255
@@ -122,13 +125,19 @@ function FormItemsView ({ card }) {
122125 </ Link >
123126 </ Typography >
124127
125- < Button size = "small" disableElevation variant = "contained" color = "secondary" onClick = { copyToClipboard } >
128+ < Button
129+ size = "small"
130+ disableElevation variant = "contained"
131+ color = "secondary"
132+ disabled = { notification !== '' }
133+ onClick = { ( ) => copyToClipboard ( true ) }
134+ >
126135 < ContentPasteIcon sx = { { fontSize : '20px' } } />
127136 </ Button >
128137 </ Box >
129138
130139 < Typography variant = "caption" >
131- Press the Copy Button to copy the IFrame embed URL to clipboard
140+ Press the Copy Button to copy this card's IFrame embed URL to clipboard
132141 </ Typography >
133142
134143 { /** Cards Gallery URL */ }
@@ -143,7 +152,21 @@ function FormItemsView ({ card }) {
143152 { cardGalleryURL }
144153 </ Link >
145154 </ Typography >
155+
156+ < Button
157+ size = "small"
158+ disableElevation variant = "contained"
159+ color = "secondary"
160+ disabled = { notification !== '' }
161+ onClick = { ( ) => copyToClipboard ( false ) }
162+ >
163+ < ContentPasteIcon sx = { { fontSize : '20px' } } />
164+ </ Button >
146165 </ Box >
166+
167+ < Typography variant = "caption" >
168+ Press the Copy Button to copy the < b > { card . category } </ b > cards gallery embed URL to clipboard
169+ </ Typography >
147170 </ div >
148171 </ Box >
149172 </ Box >
0 commit comments