Skip to content

Add more options for customizations and translations#52

Open
simonlerpard wants to merge 1 commit into
omahili:masterfrom
simonlerpard:add_more_options
Open

Add more options for customizations and translations#52
simonlerpard wants to merge 1 commit into
omahili:masterfrom
simonlerpard:add_more_options

Conversation

@simonlerpard

Copy link
Copy Markdown

Adding multiple options to improve customizations and language adoptions,
as well as the currency position.

It's no breaking change, simply just more options 😃

@simonlerpard

Copy link
Copy Markdown
Author

Also a lot of package updates during npm install. But that was just a bonus. There are still a lot of major versions needed to be updated etc.

private ticket: CartTicket;
private seatPriceTd: HTMLTableCellElement;
private currency: string;
private currencyBehind: boolean;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better alternative and naming for this property could be:

private currencyPosition: 'start' | 'end';


const { cart } = store.getOptions();
this.currency = cart?.currency || DEFAULT_CURRENCY;
this.currencyBehind = cart?.currencyBehind ?? false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I would create a constant DEFAULT_CURRENCY_POSITION and set it to 'start', so this would be:

this.currencyPosition = cart?.currencyPosition || DEFAULT_CURRENCY_POSITION;

return `${this.currency}${price.toFixed(2)}`;
return this.currencyBehind
? `${price.toFixed(2)}${this.currency}`
: `${this.currency}${price.toFixed(2)}`;

@omahili omahili Oct 12, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can format the price once before creating the string:

const formattedValue = price.toFixed(2);
return this.currencyPosition === 'start'
  ? `${this.currency}${formattedValue}`
  : `${formattedValue}${this.currency}`;


const { cart } = this.store.getOptions();
this.currency = cart?.currency || DEFAULT_CURRENCY;
this.currencyBehind = cart?.currencyBehind ?? false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same improvements for currencyBehind as mentioned for CartItem.

this.element.textContent = `Total: ${this.currency}${total.toFixed(2)}`;
const totalString = this.currencyBehind
? `${total.toFixed(2)}${this.currency}`
: `${this.currency}${total.toFixed(2)}`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here I would create formattedValue before building the string.

const description = `${seatType.label} (${currency}${seatType.price})`;
const currencyLocation = cart?.currencyBehind
? `${seatType.price}${currency}`
: `${currency}${seatType.price}`;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currencyLocation naming can be improved here to formattedCurrency.

Comment thread src/types/options.ts
titleLabel?: string;
totalLabel?: string;
currencyBehind?: boolean;
showTotal?: boolean;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showTotal was added but it's not used anywhere.

Comment thread src/types/options.ts
submitLabel?: string;
titleLabel?: string;
totalLabel?: string;
currencyBehind?: boolean;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above this would become:

currencyPosition: 'start' | 'end';

Comment thread package-lock.json

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you probably used a newer version of npm and this has lockfileVersion 3. However I wouldn't update it in this PR, so it would be nice if you could revert it to original.

@omahili

omahili commented Oct 12, 2023

Copy link
Copy Markdown
Owner

Hi @simonlerpard, thank you very much for contributing! I left a few comments here and there to improve namings and options structure.

@simonlerpard

Copy link
Copy Markdown
Author

Awesome @omahili, I kind of did this in a rush... (without actually thinking it through all the way 😜)

I've just quickly looked at your comments and they are very reasonable. I'll look into this further soon. Hopefully during the weekend or the next. I'll update the PR again when it's done.

@omahili

omahili commented Oct 12, 2023

Copy link
Copy Markdown
Owner

No worries @simonlerpard! For the labels I'm actually thinking if it makes more sense to have a full object in the options for locales like:

locales: {
  en: {
    front: 'Front',
    currency: '£',
  },
  it: {
    front: 'Fronte',
    currency: '€',
  }
}

And possibly a function to set locale like:

sc.setLocale('it')

So for now I removed all comments regarding labels. I will evaluate the solution mentioned here and eventually create another PR. I will let you know anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants