1- import { css , html , LitElement , nothing } from 'lit' ;
2- import { customElement , query , state } from 'lit/decorators.js' ;
1+ import { css , html , HTMLTemplateResult , LitElement } from 'lit' ;
2+ import { customElement , state } from 'lit/decorators.js' ;
33
44import { Review } from '@internetarchive/metadata-service' ;
55import {
@@ -9,9 +9,10 @@ import {
99
1010import '../src/review-form' ;
1111import '../src/review' ;
12+ import '../src/ia-reviews' ;
13+
1214import { MockFetchHandler } from '../test/mocks/mock-fetch-handler' ;
1315import type { FetchHandlerInterface } from '@internetarchive/fetch-handler-service' ;
14- import { ReviewForm } from '../src/review-form' ;
1516
1617@customElement ( 'app-root' )
1718export class AppRoot extends LitElement {
@@ -57,59 +58,72 @@ export class AppRoot extends LitElement {
5758 reviewer_itemname : '@foo-bar' ,
5859 } ) ;
5960
61+ private reviews = [
62+ this . mockOldReview ,
63+ new Review ( {
64+ stars : 2 ,
65+ reviewtitle : 'Eh, just ok' ,
66+ reviewbody : 'It was fine.' ,
67+ reviewer : 'Bar Baz' ,
68+ reviewdate : '04/20/2025' ,
69+ createdate : '04/19/2025' ,
70+ reviewer_itemname : '@bar-baz' ,
71+ } ) ,
72+ new Review ( {
73+ stars : 5 ,
74+ reviewtitle : 'My favorite book!!!!!' ,
75+ reviewbody : 'Wow, what a great read' ,
76+ reviewer : 'Bar Foo' ,
77+ reviewdate : '04/19/2025' ,
78+ createdate : '04/19/2025' ,
79+ reviewer_itemname : '@bar-foo' ,
80+ } ) ,
81+ ] ;
82+
6083 private fetchHandler : FetchHandlerInterface = new MockFetchHandler ( ) ;
6184
62- private goodRecaptchaManager : RecaptchaManagerInterface =
85+ private mockRecaptchaManager : RecaptchaManagerInterface =
6386 new RecaptchaManager ( {
6487 defaultSiteKey : 'demo-key' ,
6588 } ) ;
6689
67- private badRecaptchaManager : RecaptchaManagerInterface = new RecaptchaManager (
68- {
69- defaultSiteKey : 'i-am-a-bad-key-that-will-fail' ,
70- } ,
71- ) ;
72-
73- @state ( )
74- private recaptchaManager ?: RecaptchaManagerInterface ;
75-
7690 @state ( )
7791 private bypassRecaptcha : boolean = true ;
7892
7993 @state ( )
8094 private unrecoverableError : boolean = false ;
8195
82- @state ( )
83- private recoverableError : boolean = false ;
84-
8596 @state ( )
8697 private useCharCounts : boolean = true ;
8798
8899 @state ( )
89100 private allowDeletion : boolean = false ;
90101
102+ @state ( )
103+ private useExistingReviews : boolean = true ;
104+
91105 @state ( )
92106 private review : Review = this . mockOldReview ;
93107
94- @query ( 'ia-review-form' )
95- private reviewForm ! : ReviewForm ;
108+ @state ( )
109+ private reviewsDisabled : boolean = false ;
110+
111+ @state ( )
112+ private reviewsFrozen : boolean = false ;
96113
97114 render ( ) {
98- return html ` <h2> Toggle ReCaptcha</ h2>
99- ${ ! this . recaptchaManager
100- ? html `
101- <butto n
102- @click = ${ ( ) =>
103- ( this . recaptchaManager = this . goodRecaptchaManager ) }
104- >
105- Turn on ReCaptcha (good site key)</ butto n
106- > <butto n
107- @click = ${ ( ) => ( this . recaptchaManager = this . badRecaptchaManager ) }
108- >
109- Turn on ReCaptcha (bad site key)
110- </ butto n>
111- `
112- : nothing }
115+ return html ` <h2> General Settings</ h2>
116+ <butto n
117+ @click = ${ ( ) => ( this . useExistingReviews = ! this . useExistingReviews ) }
118+ >
119+ ${ this . useExistingReviews ? 'Remove' : 'Show' } exis ting reviews
120+ </ butto n>
121+ <butto n @click = ${ ( ) => ( this . reviewsDisabled = ! this . reviewsDisabled ) } >
122+ ${ this . reviewsDisabled ? 'Enable' : 'Disable' } reviews
123+ </ butto n>
124+ <butto n @click = ${ ( ) => ( this . reviewsFrozen = ! this . reviewsFrozen ) } >
125+ ${ this . reviewsFrozen ? 'Unfreeze' : 'Freeze' } reviews
126+ </ butto n>
113127 <butto n @click = ${ ( ) => ( this . bypassRecaptcha = ! this . bypassRecaptcha ) } >
114128 ${ ! this . bypassRecaptcha ? 'Bypass' : 'Enable' } ReCaptcha
115129 </ butto n>
@@ -119,75 +133,71 @@ export class AppRoot extends LitElement {
119133 >
120134 ${ this . unrecoverableError ? 'Hide' : 'Show' } unrecoverable error
121135 </ butto n>
122- <butto n
123- @click = ${ ( ) => {
124- this . unrecoverableError = false ;
125- this . recoverableError = ! this . recoverableError ;
126- } }
127- >
128- ${ this . recoverableError ? 'Hide' : 'Show' } recoverable error
129- </ butto n>
130136 <butto n @click = ${ ( ) => ( this . useCharCounts = ! this . useCharCounts ) } >
131137 ${ this . useCharCounts ? 'Remove' : 'Use' } char count limits
132138 </ butto n>
133139 <h2> Toggle review dis play</ h2>
134- <butto n
135- @click = ${ ( ) => {
136- this . reviewForm . displayMode = 'form' ;
137- } }
138- >
139- Switch to for m view
140- </ butto n>
141- ${ this . review !== this . mockOldReview
142- ? html `<butto n @click = ${ ( ) => ( this . review = this . mockOldReview ) } >
143- Prefill normal review
144- </ butto n> `
145- : nothing }
146- ${ this . review !== this . longReview
147- ? html `<butto n @click = ${ ( ) => ( this . review = this . longReview ) } >
148- Prefill long review
149- </ butto n> `
150- : nothing }
151- ${ this . review !== this . reviewWithLink
152- ? html `<butto n @click = ${ ( ) => ( this . review = this . reviewWithLink ) } >
153- Prefill review with link
154- </ butto n> `
155- : nothing }
156- ${ this . review !== this . reviewWithTextLink
157- ? html `<butto n @click = ${ ( ) => ( this . review = this . reviewWithTextLink ) } >
158- Prefill review with text link
159- </ butto n> `
160- : nothing }
140+ ${ this . renderReviewToggle ( this . mockOldReview , 'normal review' ) }
141+ ${ this . renderReviewToggle ( this . longReview , 'long review' ) }
142+ ${ this . renderReviewToggle ( this . reviewWithLink , 'review with link' ) }
143+ ${ this . renderReviewToggle (
144+ this . reviewWithTextLink ,
145+ 'review with text link' ,
146+ ) }
161147 <butto n @click = ${ ( ) => ( this . allowDeletion = ! this . allowDeletion ) } >
162148 ${ this . allowDeletion ? 'Prevent' : 'Allow' } deletion
163149 </ butto n>
164150
165151 <div class= "container" >
166- <ia- review - f or m
152+ <ia- reviews
167153 .identifier = ${ 'goody' }
168- .oldReview = ${ this . review }
169- .recaptchaManager = ${ this . recaptchaManager }
170- .unrecoverableError = ${ this . unrecoverableError
154+ .reviews = ${ this . useExistingReviews ? this . reviews : undefined }
155+ .recaptchaManager = ${ this . mockRecaptchaManager }
156+ .submitterItemname = ${ '@foo-bar' }
157+ .submitterScreenname = ${ 'Foo Bar' }
158+ .reviewSubmissionError = ${ this . unrecoverableError
171159 ? 'You must be logged in to write reviews.'
172160 : undefined }
173- .recoverableError = ${ this . recoverableError
174- ? "There's a problem submitting your review, please try again later."
175- : undefined }
176161 .maxSubjectLength = ${ this . useCharCounts ? 100 : undefined }
177162 .maxBodyLength = ${ this . useCharCounts ? 1000 : undefined }
178163 .fetchHandler = ${ this . fetchHandler }
179164 ?canDelete= ${ this . allowDeletion }
180165 ?bypassRecaptcha= ${ this . bypassRecaptcha }
181- ?submis sionInProgress= ${ true }
182- > </ ia- review- for m>
166+ ?reviewsDis abled= ${ this . reviewsDisabled }
167+ ?reviewsFrozen= ${ this . reviewsFrozen }
168+ > </ ia- reviews>
183169 </ div> ` ;
184170 }
185171
172+ private renderReviewToggle (
173+ review : Review ,
174+ reviewName : string ,
175+ ) : HTMLTemplateResult {
176+ return html `
177+ <butto n
178+ @click = ${ ( ) => {
179+ this . switchInOutReview ( review ) ;
180+ } }
181+ >
182+ ${ this . review !== review ? 'Prefill' : 'Remove' } ${ reviewName }
183+ </ butto n>
184+ ` ;
185+ }
186+
187+ private switchInOutReview ( review : Review ) : void {
188+ this . useExistingReviews = true ;
189+
190+ if ( this . review !== review ) {
191+ this . review = review ;
192+ } else this . review = this . mockOldReview ;
193+ }
194+
186195 static styles = css `
187196 .container {
188197 max-width : 750px ;
189198 margin : 10px auto;
190199 font-size : 1.4rem ;
200+ margin-top : 50px ;
191201 }
192202
193203 h2 ,
0 commit comments