Skip to content

Commit

Permalink
refactor: separate badge components and wrappers, general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dkonieczek committed Feb 22, 2024
1 parent a8aaad9 commit af8eac5
Show file tree
Hide file tree
Showing 42 changed files with 517 additions and 348 deletions.
4 changes: 3 additions & 1 deletion packages/snap-client/src/Client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ export class Client {
siteId: params.siteId || this.globals.siteId,
};

const [profile, recommendations] = await Promise.all([
const [meta, profile, recommendations] = await Promise.all([
this.meta({ siteId: params.siteId || '' }),
this.requesters.recommend.getProfile(profileParams),
this.requesters.recommend.batchRecommendations(recommendParams),
]);

return {
...profile,
meta,
results: recommendations[0].results,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/snap-client/src/Client/apis/Hybrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class HybridAPI extends API {
},
tags: {
'on-sale': {
location: 'left-middle',
location: 'left-middle-upper',
component: 'BadgePill',
parameters: {
color: '#0000FF',
Expand Down
10 changes: 8 additions & 2 deletions packages/snap-client/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { AppMode } from '@searchspring/snap-toolbox';
import type { MetaRequestModel, SearchResponseModelResult, SearchRequestModel, AutocompleteRequestModel } from '@searchspring/snapi-types';
import type {
MetaRequestModel,
SearchResponseModelResult,
SearchRequestModel,
AutocompleteRequestModel,
MetaResponseModel,
} from '@searchspring/snapi-types';

export type HTTPHeaders = { [key: string]: string };

Expand Down Expand Up @@ -192,4 +198,4 @@ type RecommendationRequestValueFilterModel = {
value: string | number;
};

export type RecommendCombinedResponseModel = ProfileResponseModel & { results: SearchResponseModelResult[] };
export type RecommendCombinedResponseModel = ProfileResponseModel & { results: SearchResponseModelResult[] } & { meta: MetaResponseModel };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/** @jsx jsx */
import { Fragment, h } from 'preact';

import { jsx, css } from '@emotion/react';
import classnames from 'classnames';
import { observer } from 'mobx-react-lite';

import { Theme, useTheme, CacheProvider } from '../../../providers';
import { ComponentProps, StylingCSS } from '../../../types';
import type { ResultBadge, OverlayResultBadge } from '@searchspring/snap-store-mobx';

const CSS = {
BadgeImage: ({}: BadgeImageProps) => {
return css({});
},
};

export const BadgeImage = observer((properties: BadgeImageProps): JSX.Element => {
const globalTheme: Theme = useTheme();

const props: BadgeImageProps = {
// default props
// global theme
...globalTheme?.components?.badgeImage,
// props
...properties,
...properties.theme?.components?.badgeImage,
};
const { badge, disableStyles, className, style } = props;

const styling: { css?: StylingCSS } = {};

if (!disableStyles) {
styling.css = [CSS.BadgeImage(props), style];
} else if (style) {
styling.css = [style];
}

return badge?.parameters?.url ? (
<CacheProvider>
<img
{...styling}
className={classnames(
'ss__badge-image',
`ss__badge-image--${badge.component}`,
`ss__badge-image--${badge.location}`,
`ss__badge-image--${badge.tag}`,
className
)}
alt={badge.label}
src={badge.parameters.url}
/>
</CacheProvider>
) : (
<Fragment />
);
});

export interface BadgeImageProps extends ComponentProps {
badge: ResultBadge | OverlayResultBadge;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BadgeImage';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# BadgeImage // TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/** @jsx jsx */
import { Fragment, h } from 'preact';

import { jsx, css } from '@emotion/react';
import classnames from 'classnames';
import { observer } from 'mobx-react-lite';

import { Theme, useTheme, CacheProvider } from '../../../providers';
import { ComponentProps, StylingCSS } from '../../../types';
import type { ResultBadge, OverlayResultBadge } from '@searchspring/snap-store-mobx';

const CSS = {
BadgePill: (props: BadgePillProps) => {
const { parameters } = props.badge;
const { color, colorText } = parameters;
return css({
padding: '0.2em 0.5em',

background: color || 'rgba(255, 255, 255, 0.5)',
color: colorText || '#000000',
});
},
};

export const BadgePill = observer((properties: BadgePillProps): JSX.Element => {
const globalTheme: Theme = useTheme();

const props: BadgePillProps = {
// default props
// global theme
...globalTheme?.components?.badgePill,
// props
...properties,
...properties.theme?.components?.badgePill,
};
const { badge, disableStyles, className, style } = props;

const styling: { css?: StylingCSS } = {};

if (!disableStyles) {
styling.css = [CSS.BadgePill(props), style];
} else if (style) {
styling.css = [style];
}

return badge ? (
<CacheProvider>
<div
{...styling}
className={classnames(
'ss__badge-pill',
`ss__badge-pill--${badge.component}`,
`ss__badge-pill--${badge.location}`,
`ss__badge-pill--${badge.tag}`,
className
)}
>
{badge.label}
</div>
</CacheProvider>
) : (
<Fragment />
);
});

export interface BadgePillProps extends ComponentProps {
badge: ResultBadge | OverlayResultBadge;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BadgePill';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# BadgePill // TODO

Empty file.

This file was deleted.

Loading

0 comments on commit af8eac5

Please sign in to comment.