Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-149125 and MWPW-147035 #19

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions web-components/src/merch-stock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { LitElement, css, html } from 'lit';
import { EVENT_MERCH_STOCK_CHANGE } from './constants.js';
import { MatchMediaController } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';
import { MOBILE_LANDSCAPE } from './media.js';

export class MerchStock extends LitElement {
static styles = [
Expand Down Expand Up @@ -35,8 +33,6 @@ export class MerchStock extends LitElement {

checked = false;

#mobile = new MatchMediaController(this, MOBILE_LANDSCAPE);

constructor() {
super();
}
Expand Down Expand Up @@ -71,7 +67,6 @@ export class MerchStock extends LitElement {

render() {
if (!this.planType) return;
if (this.#mobile.matches) return;
return html`
<sp-checkbox
size="s"
Expand Down
6 changes: 4 additions & 2 deletions web-components/src/merch-subscription-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
EVENT_MERCH_STOCK_CHANGE,
EVENT_OFFER_SELECTED,
} from './constants.js';
import { TABLET_DOWN } from './media.js';
import { TABLET_DOWN, MOBILE_LANDSCAPE } from './media.js';

class MerchSubscriptionPanel extends LitElement {
static styles = [styles];
Expand All @@ -21,6 +21,7 @@ class MerchSubscriptionPanel extends LitElement {
continueText = 'Continue';

#mobileAndTablet = new MatchMediaController(this, TABLET_DOWN);
#mobile = new MatchMediaController(this, MOBILE_LANDSCAPE);

constructor() {
super();
Expand Down Expand Up @@ -125,7 +126,7 @@ class MerchSubscriptionPanel extends LitElement {
}

handleOfferSelect(event) {
if (this.offerSelect?.stock) {
if (this.stock && this.offerSelect?.stock) {
this.stock.planType = event.detail.planType;
}
this.requestUpdate();
Expand Down Expand Up @@ -181,6 +182,7 @@ class MerchSubscriptionPanel extends LitElement {
}

get stock() {
if (this.#mobile.matches) return null;
return this.querySelector('merch-stock');
}

Expand Down
12 changes: 9 additions & 3 deletions web-components/src/merch-twp-d2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,19 @@ export class MerchTwpD2P extends LitElement {
this.singleCard = card;
}

unSelectSingleCard() {
async unSelectSingleCard() {
if (!this.singleCard) return;
this.singleCard.setAttribute(
'slot',
this.singleCard.getAttribute('data-slot')
);
this.singleCard.removeAttribute('data-slot');
this.step = 1;
const cardToBeSelected = this.singleCard;
this.singleCard = undefined;
await this.tabElement?.updateComplete;
this.selectedTabPanel.card = cardToBeSelected;
this.selectCard(cardToBeSelected, true);
}

handleContinue() {
Expand Down Expand Up @@ -370,7 +374,9 @@ export class MerchTwpD2P extends LitElement {
}

get preselectedCardId() {
const preselectedCardIds = parseState()['select-cards']?.split(',').reduce((res, item) => {
const params = new URLSearchParams(window.location.search);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should not use the search params but hash.

const selectCards = params.get('select-cards');
const preselectedCardIds = selectCards?.split(',').reduce((res, item) => {
const formattedItem = decodeURIComponent(item.trim().toLowerCase());
formattedItem && res.push(formattedItem);
return res;
Expand Down Expand Up @@ -405,7 +411,7 @@ export class MerchTwpD2P extends LitElement {
if (selectedCard) {
selectedCard.selected = undefined;
}
selectedCard = this.cardToBePreselected || card;
selectedCard = !selectedCard && this.cardToBePreselected ? this.cardToBePreselected : card;
selectedCard.selected = true;
if (tabPanel) {
tabPanel.card = selectedCard;
Expand Down
2 changes: 1 addition & 1 deletion web-components/test/merch-twp-d2p.test.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ runTests(async () => {
});

it('preselects the card from hash', async () => {
document.location.hash = 'select-cards=photoshop&creat&creati';
document.location.search = 'select-cards=photoshop&creat&creati';
await applyTemplate('cci-footer,preselect-card', false);
const merchCard = document.querySelector(
'merch-card[aria-selected]'
Expand Down