feat: less cls ads

This commit is contained in:
TrèsAbhi committed 2024-10-13 00:26:38 -05:00
1 parent 4f5a8c9a37
commit ad89679959
5 files changed
+63 -46

No files matched your search

+42 -9
View File
@@ -1,17 +1,45 @@
import { Box, type BoxProps } from '@radix-ui/themes'; import { Box, type BoxProps } from '@radix-ui/themes';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useAdExempt } from '../hooks/useAdExempt'; import type { Vector2Tuple } from 'three';
export type AdProps = BoxProps & { export type AdProps = BoxProps & {
id: string; id: string;
commonHeight: 250;
}; };
export function Ad({ id, ...props }: AdProps) { export enum MaxAdSize {
const exempt = useAdExempt(); Size728x90,
Size970x90,
Size970x250,
Size300x250,
Size336x280,
Size320x50,
Size320x100,
Size320x480,
Size160x600,
Size300x600,
}
const MAX_AD_SIZES: Record<MaxAdSize, Vector2Tuple> = {
[MaxAdSize.Size728x90]: [728, 90],
[MaxAdSize.Size970x90]: [970, 90],
[MaxAdSize.Size970x250]: [970, 250],
[MaxAdSize.Size300x250]: [300, 250],
[MaxAdSize.Size336x280]: [336, 280],
[MaxAdSize.Size320x50]: [320, 50],
[MaxAdSize.Size320x100]: [320, 100],
[MaxAdSize.Size320x480]: [320, 480],
[MaxAdSize.Size160x600]: [160, 600],
[MaxAdSize.Size300x600]: [300, 600],
};
export function Ad({ id, commonHeight, ...props }: AdProps) {
// const [width, height] =
// maxAdSize === undefined
// ? [undefined, undefined]
// : MAX_AD_SIZES[maxAdSize].map((dimension) => `${dimension}px`);
useEffect(() => { useEffect(() => {
if (exempt) return;
(window as any).nitroAds.createAd(id, { (window as any).nitroAds.createAd(id, {
refreshTime: 30, refreshTime: 30,
demo: import.meta.env.MODE === 'development', demo: import.meta.env.MODE === 'development',
@@ -24,9 +52,14 @@ export function Ad({ id, ...props }: AdProps) {
position: 'top-right', position: 'top-right',
}, },
}); });
}, [exempt, id]); }, [id]);
if (exempt) return null; return (
<Box
return <Box id={id} width="100%" {...props} />; id={id}
width="100%"
height={commonHeight ? `${commonHeight}px` : 'auto'}
{...props}
/>
);
} }
+8 -19
View File
@@ -1,14 +1,6 @@
import { assertSecret, patreonLoginUrl } from '@blitzkit/core'; import { assertSecret, patreonLoginUrl } from '@blitzkit/core';
import { ArrowRightIcon } from '@radix-ui/react-icons'; import { ArrowRightIcon } from '@radix-ui/react-icons';
import { import { Button, Code, Flex, Link, Separator, Text } from '@radix-ui/themes';
Badge,
Button,
Code,
Flex,
Link,
Separator,
Text,
} from '@radix-ui/themes';
import { useAdExempt } from '../hooks/useAdExempt'; import { useAdExempt } from '../hooks/useAdExempt';
import { App } from '../stores/app'; import { App } from '../stores/app';
import { PatreonIcon } from './PatreonIcon'; import { PatreonIcon } from './PatreonIcon';
@@ -38,16 +30,13 @@ function Content() {
assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH) !== 'opentest' && ( assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH) !== 'opentest' && (
<> <>
<Flex direction="column" gap="3" align="center"> <Flex direction="column" gap="3" align="center">
<Flex align="center" gap="2"> <Text size="5">
<Badge color="green">NEW</Badge> BlitzKit{' '}
<Text size="5"> <Code variant="outline" size="4" color="gray" highContrast>
BlitzKit{' '} opentest
<Code variant="outline" size="4" color="gray" highContrast> </Code>{' '}
opentest is available now{' '}
</Code>{' '} </Text>
is available now{' '}
</Text>
</Flex>
<Link href="https://opentest.blitzkit.app/" target="_blank"> <Link href="https://opentest.blitzkit.app/" target="_blank">
<Button color="green"> <Button color="green">
@@ -10,14 +10,7 @@ import {
type TankDefinition, type TankDefinition,
} from '@blitzkit/core'; } from '@blitzkit/core';
import { useStore } from '@nanostores/react'; import { useStore } from '@nanostores/react';
import { import { Callout, Flex, Link, Text, type FlexProps } from '@radix-ui/themes';
Box,
Callout,
Flex,
Link,
Text,
type FlexProps,
} from '@radix-ui/themes';
import fuzzysort from 'fuzzysort'; import fuzzysort from 'fuzzysort';
import { times } from 'lodash-es'; import { times } from 'lodash-es';
import { Fragment, memo, useEffect, useMemo, useState } from 'react'; import { Fragment, memo, useEffect, useMemo, useState } from 'react';
@@ -481,11 +474,12 @@ export const TankSearch = memo<TankSearchProps>(
!compact && !compact &&
hasAd && hasAd &&
index !== tanks.length - 1 && ( index !== tanks.length - 1 && (
<Box gridColumn="1 / -1"> <Flex gridColumn="1 / -1">
<Ad <Ad
commonHeight={250}
id={`tankopedia-search-ad-${Math.floor(index / 32)}`} id={`tankopedia-search-ad-${Math.floor(index / 32)}`}
/> />
</Box> </Flex>
)} )}
</Fragment> </Fragment>
); );
+1 -4
View File
@@ -5,7 +5,7 @@ let cache: Record<string, boolean | Promise<boolean>> = {};
export function useAdExempt() { export function useAdExempt() {
const patreon = App.use((state) => state.logins.patreon); const patreon = App.use((state) => state.logins.patreon);
const [exempt, setExempt] = useState(true); const [exempt, setExempt] = useState(false);
useEffect(() => { useEffect(() => {
(async () => { (async () => {
@@ -21,9 +21,6 @@ export function useAdExempt() {
if (!response.ok) return resolve(false); if (!response.ok) return resolve(false);
const json = await response.json(); const json = await response.json();
console.log(json);
const exempt = typeof json === 'boolean' && json; const exempt = typeof json === 'boolean' && json;
cache[patreon.token] = exempt; cache[patreon.token] = exempt;
+8 -4
View File
@@ -1,6 +1,6 @@
--- ---
import { Box, Flex, Heading } from '@radix-ui/themes'; import { Box, Flex, Heading } from '@radix-ui/themes';
import { AdWithContext } from '../components/AdWithContext'; import { Ad } from '../components/Ad.tsx';
import HomeHero from '../components/HomeHero.astro'; import HomeHero from '../components/HomeHero.astro';
import { Plugs } from '../components/Plugs.tsx'; import { Plugs } from '../components/Plugs.tsx';
import ToolCard from '../components/ToolCard.astro'; import ToolCard from '../components/ToolCard.astro';
@@ -18,13 +18,15 @@ import BaseLayout from '../layouts/BaseLayout.astro';
<BaseLayout> <BaseLayout>
<HomeHero /> <HomeHero />
<Plugs /> <Plugs client:idle />
<Flex p="4" justify="center" gap="4"> <Flex p="4" justify="center" gap="4">
<Flex maxWidth="64rem" flexGrow="1" gap="4" direction="column"> <Flex maxWidth="64rem" flexGrow="1" gap="4" direction="column">
<ToolCard tool={tankopediaTool} /> <ToolCard tool={tankopediaTool} />
<AdWithContext client:only="react" id="homepage-ad-1" /> <Flex justify="center">
<Ad client:idle id="homepage-ad-1" commonHeight={250} />
</Flex>
<Flex gap="4" direction={{ initial: 'column', sm: 'row' }}> <Flex gap="4" direction={{ initial: 'column', sm: 'row' }}>
{/* <ToolCard tool={playerStatsTool} /> */} {/* <ToolCard tool={playerStatsTool} /> */}
@@ -39,7 +41,9 @@ import BaseLayout from '../layouts/BaseLayout.astro';
<ToolCard tool={discordTool} /> <ToolCard tool={discordTool} />
</Flex> </Flex>
<AdWithContext client:only="react" id="homepage-ad-2" /> <Flex justify="center">
<Ad client:idle id="homepage-ad-2" commonHeight={250} />
</Flex>
<Flex gap="4" direction={{ initial: 'column', sm: 'row' }}> <Flex gap="4" direction={{ initial: 'column', sm: 'row' }}>
<ToolCard tool={moreTool} /> <ToolCard tool={moreTool} />