Fix review form save button

This commit is contained in:
Pieter Vander Vennet 2021-06-21 12:44:26 +02:00
parent b9b504aebc
commit aa1c9d0398
2 changed files with 27 additions and 16 deletions

View file

@ -28,7 +28,7 @@ export class SaveButton extends Toggle {
super( super(
save, save,
pleaseLogin, pleaseLogin,
osmConnection?.userDetails?.map(userDetails => userDetails.loggedIn) ?? new UIEventSource<any>(false) osmConnection?.isLoggedIn ?? new UIEventSource<any>(false)
) )
} }

View file

@ -14,6 +14,7 @@ import Toggle from "../Input/Toggle";
export default class ReviewForm extends InputElement<Review> { export default class ReviewForm extends InputElement<Review> {
IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false);
private readonly _value: UIEventSource<Review>; private readonly _value: UIEventSource<Review>;
private readonly _comment: BaseUIElement; private readonly _comment: BaseUIElement;
private readonly _stars: BaseUIElement; private readonly _stars: BaseUIElement;
@ -22,7 +23,6 @@ export default class ReviewForm extends InputElement<Review> {
private readonly _postingAs: BaseUIElement; private readonly _postingAs: BaseUIElement;
private readonly _osmConnection: OsmConnection; private readonly _osmConnection: OsmConnection;
constructor(onSave: ((r: Review, doneSaving: (() => void)) => void), osmConnection: OsmConnection) { constructor(onSave: ((r: Review, doneSaving: (() => void)) => void), osmConnection: OsmConnection) {
super(); super();
this._osmConnection = osmConnection; this._osmConnection = osmConnection;
@ -51,14 +51,27 @@ export default class ReviewForm extends InputElement<Review> {
new VariableUiElement(osmConnection.userDetails.map((ud: UserDetails) => ud.name)) new VariableUiElement(osmConnection.userDetails.map((ud: UserDetails) => ud.name))
.SetClass("review-author")]) .SetClass("review-author")])
.SetStyle("display:flex;flex-direction: column;align-items: flex-end;margin-left: auto;") .SetStyle("display:flex;flex-direction: column;align-items: flex-end;margin-left: auto;")
const reviewIsSaved = new UIEventSource<boolean>(false)
const reviewIsSaving = new UIEventSource<boolean>(false)
this._saveButton = this._saveButton =
new SaveButton(this._value.map(r => self.IsValid(r)), undefined) new Toggle(Translations.t.reviews.saved.Clone().SetClass("thanks"),
.onClick(() => { new Toggle(
self._saveButton = Translations.t.reviews.saving_review.Clone(); Translations.t.reviews.saving_review.Clone(),
new SaveButton(
this._value.map(r => self.IsValid(r)), osmConnection
).onClick(() => {
reviewIsSaving.setData(true),
onSave(this._value.data, () => { onSave(this._value.data, () => {
self._saveButton = Translations.t.reviews.saved.Clone().SetClass("thanks"); reviewIsSaved.setData(true)
}); });
}).SetClass("break-normal") }),
reviewIsSaving
),
reviewIsSaved
).SetClass("break-normal")
this._isAffiliated = new CheckBoxes([Translations.t.reviews.i_am_affiliated.Clone()]) this._isAffiliated = new CheckBoxes([Translations.t.reviews.i_am_affiliated.Clone()])
@ -113,8 +126,6 @@ export default class ReviewForm extends InputElement<Review> {
.ConstructElement() .ConstructElement()
} }
IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false);
IsValid(r: Review): boolean { IsValid(r: Review): boolean {
if (r === undefined) { if (r === undefined) {
return false; return false;