Skip to content

Commit a853830

Browse files
WEBDEV-7425 Prep component for details page (#30)
* Support empty review display and add gray BG * Adjust cancel button behavior * Switch to correct red color * Improve star accessibility * Add spacing improvement * Switch back to yellow stars with border * Tidy up following rebase * Temporarily change clear btn color for accessibility * Add clearer documentation to form * Switch to fetch request for form submission * Interpret json response from endpoint * Remove duplicated identifier * Remove more unnecessary inputs and logic * Prevent other buttons from submitting form * Adjust review spacing * Remove some temporary logic * Improve component accessibility * Switch to fetch handler service * Restore tests and use mock fetch handler for demo app * Switch out ReviewForRender with Review * Generate submitted review on submit * Tidy up defaults and tests * Support passing in user itemname / screenname * Tidy up following rebase * Experiment with post request for debugging * Revert "Experiment with post request for debugging" This reverts commit 7856bd2. * Include credentials * Tidy up * Adjust mocks to match new API response * Adjust on-submit behavior and date handling * Allow sanitized HTML in error messages * Support review deletion * Allow linebreaks in error messages * Allow for string dates in prev review * Tidy up demo app * Ensure links inside errors match clear stars link * Pass identifier to review component * Adjust error message text * Adjust unrecoverable error height * Tidy up following CR * Delete using screenname instead of itemname * Adjust fetch handler interface import * Add submitter param
1 parent 4822289 commit a853830

15 files changed

+497
-227
lines changed

demo/app-root.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99

1010
import '../src/review-form';
1111
import '../src/review';
12+
import { MockFetchHandler } from '../test/mocks/mock-fetch-handler';
13+
import type { FetchHandlerInterface } from '@internetarchive/fetch-handler-service';
14+
import { ReviewForm } from '../src/review-form';
1215

1316
@customElement('app-root')
1417
export class AppRoot extends LitElement {
@@ -54,6 +57,8 @@ export class AppRoot extends LitElement {
5457
reviewer_itemname: '@foo-bar',
5558
});
5659

60+
private fetchHandler: FetchHandlerInterface = new MockFetchHandler();
61+
5762
private goodRecaptchaManager: RecaptchaManagerInterface =
5863
new RecaptchaManager({
5964
defaultSiteKey: 'demo-key',
@@ -81,13 +86,13 @@ export class AppRoot extends LitElement {
8186
private useCharCounts: boolean = true;
8287

8388
@state()
84-
private useReviewDisplay: boolean = false;
89+
private allowDeletion: boolean = false;
8590

8691
@state()
8792
private review: Review = this.mockOldReview;
8893

89-
@query('#review-input')
90-
private reviewInput!: HTMLTextAreaElement;
94+
@query('ia-review-form')
95+
private reviewForm!: ReviewForm;
9196

9297
render() {
9398
return html` <h2>Toggle ReCaptcha</h2>
@@ -126,8 +131,12 @@ export class AppRoot extends LitElement {
126131
${this.useCharCounts ? 'Remove' : 'Use'} char count limits
127132
</button>
128133
<h2>Toggle review display</h2>
129-
<button @click=${() => (this.useReviewDisplay = !this.useReviewDisplay)}>
130-
Switch to ${this.useReviewDisplay ? 'form view' : 'review view'}
134+
<button
135+
@click=${() => {
136+
this.reviewForm.displayMode = 'form';
137+
}}
138+
>
139+
Switch to form view
131140
</button>
132141
${this.review !== this.mockOldReview
133142
? html`<button @click=${() => (this.review = this.mockOldReview)}>
@@ -149,39 +158,25 @@ export class AppRoot extends LitElement {
149158
Prefill review with text link
150159
</button>`
151160
: nothing}
152-
153-
<div class="review-body-form">
154-
<h2>Adjust review body</h2>
155-
<textarea id="review-input"></textarea>
156-
<button
157-
@click=${() =>
158-
(this.review = new Review({
159-
reviewtitle: 'What a cool book!',
160-
reviewbody: this.reviewInput.value,
161-
reviewer: 'Foo Bar',
162-
reviewdate: new Date().toDateString(),
163-
createdate: '02/07/2025',
164-
reviewer_itemname: '@foo-bar',
165-
}))}
166-
>
167-
Update
168-
</button>
169-
</div>
161+
<button @click=${() => (this.allowDeletion = !this.allowDeletion)}>
162+
${this.allowDeletion ? 'Prevent' : 'Allow'} deletion
163+
</button>
170164
171165
<div class="container">
172166
<ia-review-form
173167
.identifier=${'goody'}
174168
.oldReview=${this.review}
175169
.recaptchaManager=${this.recaptchaManager}
176170
.unrecoverableError=${this.unrecoverableError
177-
? "Sorry, you're not cool enough to write a review for this item."
171+
? 'You must be logged in to write reviews.'
178172
: undefined}
179173
.recoverableError=${this.recoverableError
180-
? "Why not try submitting again? What's the worst thing that could happen?"
174+
? "There's a problem submitting your review, please try again later."
181175
: undefined}
182176
.maxSubjectLength=${this.useCharCounts ? 100 : undefined}
183177
.maxBodyLength=${this.useCharCounts ? 1000 : undefined}
184-
.displayMode=${this.useReviewDisplay ? 'review' : 'form'}
178+
.fetchHandler=${this.fetchHandler}
179+
?canDelete=${this.allowDeletion}
185180
?bypassRecaptcha=${this.bypassRecaptcha}
186181
?submissionInProgress=${true}
187182
></ia-review-form>

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
]
6969
},
7070
"dependencies": {
71+
"@internetarchive/fetch-handler-service": "^1.0.1",
7172
"@internetarchive/ia-activity-indicator": "^0.0.6",
7273
"@internetarchive/ia-styles": "^1.0.0",
7374
"@internetarchive/metadata-service": "^1.0.4",

src/assets/delete-icon.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { svg } from 'lit';
2+
3+
export default svg`
4+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" class="delete-icon">
5+
<rect width="24" height="24" fill="white"/>
6+
<path d="M5 7.5H19L18 21H6L5 7.5Z" stroke="#000000" stroke-linejoin="round"/>
7+
<path d="M15.5 9.5L15 19" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"/>
8+
<path d="M12 9.5V19" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"/>
9+
<path d="M8.5 9.5L9 19" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"/>
10+
<path d="M16 5H19C20.1046 5 21 5.89543 21 7V7.5H3V7C3 5.89543 3.89543 5 5 5H8M16 5L15 3H9L8 5M16 5H8" stroke="#000000" stroke-linejoin="round"/>
11+
</svg>
12+
`;

src/assets/star-basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export default svg`
44
<svg class="star-basic" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
55
<path
66
d="m81.0388846 100-30.9636029-22.5595033-30.7410319 22.5595033 10.6670595-37.3922042-30.0013093-25.2155916h37.5556428l12.5196389-37.3922042 12.3690754 37.3922042h37.5556429l-29.7034563 25.2155916z"
7-
fill="currentColor"
7+
fill="2C2C2C"
88
/>
99
</svg>`;

src/assets/star-selected.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default svg`
44
<svg class="star-selected" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
55
<path
66
d="m81.0388846 100-30.9636029-22.5595033-30.7410319 22.5595033 10.6670595-37.3922042-30.0013093-25.2155916h37.5556428l12.5196389-37.3922042 12.3690754 37.3922042h37.5556429l-29.7034563 25.2155916z"
7-
fill="#f0b445"
7+
fill="#c2820a"
8+
stroke="#c2820a"
9+
stroke-width="3px"
810
/>
911
</svg>`;

src/assets/star-unselected.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default svg`
44
<svg class="star-unselected" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
55
<path
66
d="m81.0388846 100-30.9636029-22.5595033-30.7410319 22.5595033 10.6670595-37.3922042-30.0013093-25.2155916h37.5556428l12.5196389-37.3922042 12.3690754 37.3922042h37.5556429l-29.7034563 25.2155916z"
7-
fill="#e0e0e0"
7+
fill="#ffffff"
8+
stroke="#c2820a"
9+
stroke-width="3px"
810
/>
911
</svg>`;

0 commit comments

Comments
 (0)