Moved priceinfo to its own component

This commit is contained in:
DrMint 2024-06-27 22:43:06 +02:00
parent 6eb64b48a2
commit cc79e51841
6 changed files with 56 additions and 65 deletions

View File

@ -41,7 +41,7 @@ if (values.length === 0) return;
flex-wrap: wrap; flex-wrap: wrap;
gap: 6px; gap: 6px;
place-items: center; place-items: center;
translate: 0px 3px; translate: 0px 2px;
&.with-border { &.with-border {
& > div, & > div,

View File

@ -54,20 +54,15 @@ const { t } = await getI18n(Astro.locals.currentLocale);
<style> <style>
#container { #container {
display: grid; display: flex;
grid-template-columns: auto 1fr;
gap: 0.5em 1em; gap: 0.5em 1em;
align-items: start; flex-wrap: wrap;
@media (max-width: 35em) {
grid-template-columns: 1fr;
}
& > #values { & > #values {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 0.5em; gap: 6px;
margin-top: 0.5em; translate: 0px 6px;
} }
} }
</style> </style>

View File

@ -0,0 +1,37 @@
---
import Metadata from "components/Metadata.astro";
import { getI18n } from "src/i18n/i18n";
import { convert } from "src/utils/currencies";
interface Props {
price: {
amount: number;
currency: string;
};
}
const { price } = Astro.props;
const { formatPrice, t } = await getI18n(Astro.locals.currentLocale);
const preferredCurrency = Astro.locals.currentCurrency;
const convertedPrice = {
amount: convert(price.currency, preferredCurrency, price.amount),
currency: preferredCurrency,
};
let priceText = price.amount === 0 ? t("collectibles.price.free") : formatPrice(price);
if (price.amount > 0 && price.currency !== convertedPrice.currency) {
priceText += ` (${formatPrice(convertedPrice)})`;
}
---
{/* ------------------------------------------- HTML ------------------------------------------- */}
<Metadata
icon="material-symbols:sell-outline"
title={t("collectibles.price")}
values={[{ name: priceText }]}
withBorder={false}
/>

View File

@ -47,14 +47,10 @@ const { formatInches, formatMillimeters, t } = await getI18n(Astro.locals.curren
<style> <style>
#size { #size {
display: grid; display: flex;
grid-template-columns: auto 1fr; gap: 0.5em 1em;
flex-wrap: wrap;
gap: 1em 2em; gap: 1em 2em;
align-items: start;
@media (max-width: 35em) {
grid-template-columns: 1fr;
}
& > #values { & > #values {
display: flex; display: flex;

View File

@ -1,5 +1,5 @@
--- ---
import TitleIcon from "components/TitleIcon.astro"; import Metadata from "components/Metadata.astro";
import { getI18n } from "src/i18n/i18n"; import { getI18n } from "src/i18n/i18n";
interface Props { interface Props {
@ -12,26 +12,9 @@ const { formatPounds, formatGrams, t } = await getI18n(Astro.locals.currentLocal
{/* ------------------------------------------- HTML ------------------------------------------- */} {/* ------------------------------------------- HTML ------------------------------------------- */}
<div id="container"> <Metadata
<TitleIcon title={t("collectibles.weight")} icon="material-symbols:scale" /> icon="material-symbols:scale"
<p>{formatGrams(weight)}{" "}({formatPounds(weight)})</p> title={t("collectibles.weight")}
</div> values={[{ name: `${formatGrams(weight)} (${formatPounds(weight)})` }]}
withBorder={false}
{/* ------------------------------------------- CSS -------------------------------------------- */} />
<style>
#container {
display: grid;
grid-template-columns: auto 1fr;
gap: 0.5em 1em;
align-items: center;
@media (max-width: 35em) {
grid-template-columns: 1fr;
}
& > p {
margin-top: 0.5em;
}
}
</style>

View File

@ -13,16 +13,16 @@ import SubitemSection from "./_components/SubitemSection.astro";
import ContentsSection from "./_components/ContentsSection/ContentsSection.astro"; import ContentsSection from "./_components/ContentsSection/ContentsSection.astro";
import { formatInlineTitle, formatLocale, formatRichTextToString } from "src/utils/format"; import { formatInlineTitle, formatLocale, formatRichTextToString } from "src/utils/format";
import AsideLayout from "components/AppLayout/AsideLayout.astro"; import AsideLayout from "components/AppLayout/AsideLayout.astro";
import { convert } from "src/utils/currencies";
import Attributes from "components/Attributes.astro"; import Attributes from "components/Attributes.astro";
import type { Attribute } from "src/utils/attributes"; import type { Attribute } from "src/utils/attributes";
import { payload } from "src/utils/payload"; import { payload } from "src/utils/payload";
import { sizesToSrcset } from "src/utils/img"; import { sizesToSrcset } from "src/utils/img";
import RichText from "components/RichText/RichText.astro"; import RichText from "components/RichText/RichText.astro";
import SubFilesSection from "./_components/SubFilesSection.astro"; import SubFilesSection from "./_components/SubFilesSection.astro";
import PriceInfo from "./_components/PriceInfo.astro";
const slug = Astro.params.slug!; const slug = Astro.params.slug!;
const { getLocalizedMatch, getLocalizedUrl, t, formatDate, formatPrice } = await getI18n( const { getLocalizedMatch, getLocalizedUrl, t, formatDate } = await getI18n(
Astro.locals.currentLocale Astro.locals.currentLocale
); );
@ -116,28 +116,6 @@ if (languages.length > 0) {
withBorder: true, withBorder: true,
}); });
} }
if (price) {
const preferredCurrency = Astro.locals.currentCurrency;
const convertedPrice = {
amount: convert(price.currency, preferredCurrency, price.amount),
currency: preferredCurrency,
};
let priceText = price.amount === 0 ? t("collectibles.price.free") : formatPrice(price);
if (price.amount > 0 && price.currency !== convertedPrice.currency) {
priceText += ` (${formatPrice(convertedPrice)})`;
}
additionalAttributes.push({
title: t("collectibles.price"),
icon: "material-symbols:sell-outline",
values: [{ name: priceText }],
withBorder: false,
});
}
--- ---
{/* ------------------------------------------- HTML ------------------------------------------- */} {/* ------------------------------------------- HTML ------------------------------------------- */}
@ -211,6 +189,8 @@ if (price) {
<div id="attributes"> <div id="attributes">
<Attributes attributes={[...attributes, ...additionalAttributes]}> <Attributes attributes={[...attributes, ...additionalAttributes]}>
{price && <PriceInfo price={price} />}
<AvailabilityInfo urls={urls} price={price !== undefined} releaseDate={releaseDate} /> <AvailabilityInfo urls={urls} price={price !== undefined} releaseDate={releaseDate} />
{size && <SizeInfo size={size} />} {size && <SizeInfo size={size} />}