@@ -22,6 +22,8 @@ import { LIGHT_ITEM_DETAILS_QUERY } from 'utils/graphql'
2222import { useQuery } from '@apollo/client'
2323import SearchBar from 'components/light-search-bar'
2424import { parseIpfs } from 'utils/ipfs-parse'
25+ import { itemToStatusCode , STATUS_CODE } from 'utils/item-status'
26+ import { truncateAtWord } from 'utils/truncate-at-word'
2527import { fetchMetaEvidence } from 'hooks/tcr-view'
2628
2729export const ITEM_TOUR_DISMISSED = 'ITEM_TOUR_DISMISSED'
@@ -78,7 +80,9 @@ const ItemDetails = ({ itemID, search }) => {
7880 const [ ipfsItemData , setIpfsItemData ] = useState ( )
7981 const { timestamp } = useContext ( WalletContext )
8082 const [ modalOpen , setModalOpen ] = useState ( )
81- const { tcrError, metaEvidence } = useContext ( LightTCRViewContext )
83+ const { tcrError, metaEvidence, challengePeriodDuration } = useContext (
84+ LightTCRViewContext
85+ )
8286 const [ appealCost , setAppealCost ] = useState ( )
8387
8488 // subgraph item entities have id "<itemID>@<listaddress>"
@@ -114,7 +118,7 @@ const ItemDetails = ({ itemID, search }) => {
114118 return ordered
115119 }
116120
117- const result = {
121+ return {
118122 ...item , // Spread to convert from array to object.
119123 errors : [ ] ,
120124 columns : metaEvidence . metadata . columns ,
@@ -123,11 +127,62 @@ const ItemDetails = ({ itemID, search }) => {
123127 ipfsItemData . values
124128 )
125129 }
126- return result
127130 } , [ item , metaEvidence , ipfsItemData ] )
128131
129132 const { metadata } = metaEvidence || { }
130133 const { decodedData } = decodedItem || { }
134+ const { tcrTitle, itemName } = metadata || { }
135+
136+ const statusCode = useMemo ( ( ) => {
137+ if ( ! item || ! timestamp || ! challengePeriodDuration ) return null
138+ return itemToStatusCode ( item , timestamp , challengePeriodDuration )
139+ } , [ item , timestamp , challengePeriodDuration ] )
140+
141+ const getStatusPhrase = statusCode => {
142+ switch ( statusCode ) {
143+ case STATUS_CODE . REGISTERED :
144+ return 'is verified to be safe'
145+ case STATUS_CODE . SUBMITTED :
146+ return 'is pending verification'
147+ case STATUS_CODE . REMOVAL_REQUESTED :
148+ return 'has removal requested'
149+ case STATUS_CODE . CHALLENGED :
150+ return 'is under challenge'
151+ case STATUS_CODE . CROWDFUNDING :
152+ return 'is crowdfunding appeal'
153+ case STATUS_CODE . CROWDFUNDING_WINNER :
154+ return 'won crowdfunding appeal'
155+ case STATUS_CODE . PENDING_SUBMISSION :
156+ return 'awaits submission'
157+ case STATUS_CODE . PENDING_REMOVAL :
158+ return 'awaits removal'
159+ case STATUS_CODE . WAITING_ARBITRATOR :
160+ return 'awaits arbitrator ruling'
161+ case STATUS_CODE . ABSENT :
162+ return 'is not listed'
163+ default :
164+ return 'has unknown status'
165+ }
166+ }
167+
168+ const capitalizeFirst = s => s ?. charAt ( 0 ) . toUpperCase ( ) + s ?. slice ( 1 )
169+
170+ const fullSeoTitle =
171+ decodedItem && metadata
172+ ? `${ capitalizeFirst ( itemName ) } - ${ tcrTitle } - Kleros · Curate`
173+ : 'Kleros · Curate'
174+ const truncatedSeoTitle = truncateAtWord ( fullSeoTitle , 160 )
175+
176+ const fullSeoMetaDescription =
177+ decodedItem && metadata && statusCode !== null
178+ ? `${ decodedData . join ( ' ' ) } - ${ getStatusPhrase ( statusCode ) } on ${
179+ metadata . tcrTitle
180+ } in Kleros Curate`
181+ : 'View item details on Kleros Curate.'
182+ const truncatedSeoMetaDescription = truncateAtWord (
183+ fullSeoMetaDescription ,
184+ 160
185+ )
131186
132187 // If this is a TCR in a TCR of TCRs, we fetch its metadata as well
133188 // to build a better item details card.
@@ -197,17 +252,11 @@ const ItemDetails = ({ itemID, search }) => {
197252 />
198253 )
199254
200- const { tcrTitle, itemName } = metadata || { }
201- const capitalizeFirst = s => s . charAt ( 0 ) . toUpperCase ( ) + s . slice ( 1 )
202- const title =
203- decodedItem && metadata
204- ? `${ capitalizeFirst ( itemName ) } - ${ tcrTitle } - Kleros · Curate`
205- : 'Kleros · Curate'
206-
207255 return (
208256 < >
209257 < Helmet >
210- < title > { title } </ title >
258+ < title > { truncatedSeoTitle } </ title >
259+ < meta name = "description" content = { truncatedSeoMetaDescription } />
211260 </ Helmet >
212261 < StyledBanner >
213262 < Breadcrumb separator = ">" >
0 commit comments