Skip to content

Commit

Permalink
Merge pull request #10 from sergio222-dev/develop
Browse files Browse the repository at this point in the history
* added the ability to set the deck's splash art
  • Loading branch information
sergio222-dev authored Jul 31, 2024
2 parents ca1a068 + 65dee0a commit f0d8923
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 321 deletions.
9 changes: 5 additions & 4 deletions src/components/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { component$, Slot } from "@builder.io/qwik";
import type { ButtonHTMLAttributes } from "@builder.io/qwik";
import { component$, Slot } from "@builder.io/qwik";

interface ButtonProps {
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
}

export const Button = component$<ButtonProps>(() => {
export const Button = component$<ButtonProps>(({ class: className, ...props}) => {
return (
<button class="bg-secondary rounded px-4 py-1"><Slot/></button>
<button class={`bg-secondary rounded px-1 py-1 disabled:bg-gray-400 ${className}`} {...props}><Slot/></button>
)
});
16 changes: 16 additions & 0 deletions src/components/button/ButtonIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ButtonHTMLAttributes } from "@builder.io/qwik";
import { Slot } from "@builder.io/qwik";
import { component$ } from "@builder.io/qwik";
import { Button } from "~/components/button/Button";

interface ButtonIconProps extends ButtonHTMLAttributes<HTMLButtonElement> {

}

export const ButtonIcon = component$<ButtonIconProps>(({ class: className, ...props }) => {
return (
<Button class={`border-black border-2 rounded-full p-0 ${className}`} {...props} >
<Slot/>
</Button>
)
});
1 change: 1 addition & 0 deletions src/components/button/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Button';
export * from './ButtonIcon';
44 changes: 44 additions & 0 deletions src/components/deckCard/DeckCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { component$ } from "@builder.io/qwik";
import { Link } from "@builder.io/qwik-city";
import { createClientBrowser } from "~/lib/supabase-qwik";

interface DeckCardProps {
id: number;
splashArt?: string;
name: string;
path?: string;
}

export const DeckCard = component$<DeckCardProps>(({ id, splashArt, name, path = '/decks/preview' }) => {
const supabase = createClientBrowser();

return (
<Link
href={`${path}/${id}`}
class="aspect-[4/3] w-[100%] 2xl:w-[calc(20%-0.5rem)] xl:w-[calc(25%-0.5rem)] lg:w-[calc(25%-0.5rem)] md:w-[calc(33%-0.5rem)] sm:w-[calc(50%-0.5rem)]"
>
<div
class={`aspect-[4/3] bg-[radial-gradient(transparent,#000000)] shadow hover:shadow-[0_0_4px_0]
hover:shadow-primary border-2 border-secondary hover:border-primary rounded-[24px] cursor-pointer
bg-no-repeat bg-[length:160%_auto] bg-[50%_30%] relative flex flex-col items-center text-white
p-4
`}
{...(splashArt ? {
style: {
backgroundImage: `radial-gradient(transparent, rgb(0, 0, 0)), url(${supabase.storage.from(
'CardImages/cards').getPublicUrl(splashArt + '.webp').data.publicUrl})`
}
} : {})}
>
<div class="font-bold">
{name}
</div>
<div class="hidden mt-auto justify-between">
<p>
{/*{d.description}*/}
</p>
</div>
</div>
</Link>
);
});
1 change: 1 addition & 0 deletions src/components/deckCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './DeckCard';
1 change: 0 additions & 1 deletion src/features/appbar/Appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const Appbar = component$(() => {
const location = useLocation();

const user = useContext(UserContext);
console.log('rendered');

return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/features/createDeck/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Create = component$(() => {

return (
<div>

<CreateForm/>
<CardFilter/>
<CardListDeck/>
Expand Down
24 changes: 7 additions & 17 deletions src/features/createDeck/components/CardDeck.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { component$, useComputed$, useContext, useSignal, useStylesScoped$ } from '@builder.io/qwik';
import { component$, useContext, useSignal, useStylesScoped$ } from '@builder.io/qwik';
import {
PopoverCard
} from "~/components/popoverCard/PopoverCard";
import type { Card } from '~/models/Card';
} from "~/components/popoverCard/PopoverCard";
import { useDeckQuantity } from "~/hooks/useDeckQuantity";
import type { Card } from '~/models/Card';
import {
DeckCreationContext
} from '~/stores/deckCreationContext';
} from '~/stores/deckCreationContext';

interface CardDeckProps {
card: Card;
Expand All @@ -19,27 +20,16 @@ export const CardDeck = component$<CardDeckProps>(({ card }) => {
const showPreview = useSignal(false);
const previewRef = useSignal<HTMLDivElement>();

const deckQuantity = useComputed$(() => {
const masterDeckQuantity = Object.entries(deckData.masterDeck)
.map(([, c]) => c)
.find(c => c.id === card.id)?.quantity ?? 0;
const treasureDeckQuantity = Object.entries(deckData.treasureDeck)
.map(([, c]) => c)
.find(c => c.id === card.id)?.quantity ?? 0;
return masterDeckQuantity + treasureDeckQuantity;
});
const [deckQuantity] = useDeckQuantity(deckData, card.id);

const sideQuantity = useComputed$(() => {
return Object.entries(deckData.sideDeck).map(([, c]) => c).find(c => c.id === card.id)?.quantity ?? 0;
});
const [sideQuantity] = useDeckQuantity(deckData, card.id, true);

useStylesScoped$(`
.card-text-shadow {
text-shadow: -1px 1px 0 #FFF, 1px 1px 0 #FFF, 1px -1px 0 #FFF;
}
`);


return (
<div
class="md:w-[calc(33%-1.5rem)] lg:w-[calc(33%-1.5rem)] xl:w-[calc(20%-1.5rem)] 2xl:w-[calc(16.33%-1.5rem)] w-full transition-all hover:bg-[length:100%_auto] hover:ring-4 ring-2 h-[80px] bg-no-repeat bg-[length:120%_auto] bg-[50%_25%] relative"
Expand Down
39 changes: 17 additions & 22 deletions src/features/createDeck/components/CardDeckControl.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { component$, useComputed$, useContext, useSignal } from '@builder.io/qwik';
import { Icon } from "~/components/icons/Icon";
import { PopoverCard } from "~/components/popoverCard/PopoverCard";
import type { DeckCard } from '~/models/Deck';
import { DeckCreationContext } from "~/stores/deckCreationContext";
import { component$, useContext, useSignal } from '@builder.io/qwik';
import { ButtonIcon } from "~/components/button/ButtonIcon";
import { Icon } from "~/components/icons/Icon";
import { PopoverCard } from "~/components/popoverCard/PopoverCard";
import { useDeckQuantity } from "~/hooks/useDeckQuantity";
import type { DeckCard } from '~/models/Deck';
import { DeckCreationContext } from "~/stores/deckCreationContext";

interface CardDeckControlProps {
card: DeckCard;
Expand All @@ -18,30 +20,20 @@ export const CardDeckControl = component$<CardDeckControlProps>(({ card, orienta

const deckData = d.deckData;

const deckQuantity = useComputed$(() => {
const masterDeckQuantity = Object.entries(deckData.masterDeck)
.map(([, c]) => c)
.find(c => c.id === card.id)?.quantity ?? 0;
const treasureDeckQuantity = Object.entries(deckData.treasureDeck)
.map(([, c]) => c)
.find(c => c.id === card.id)?.quantity ?? 0;
const sideDeckQuantity = Object.entries(deckData.sideDeck)
.map(([, c]) => c)
.find(c => c.id === card.id)?.quantity ?? 0;

return isSide ? sideDeckQuantity : masterDeckQuantity + treasureDeckQuantity;
});
const [deckQuantity] = useDeckQuantity(deckData, card.id, isSide);

return (
<div
class={`aspect-[3/4] ${orientation === 'horizontal' ?
class={`aspect-[3/4] bg-cover ${d.deckData.splashArtId === card.id ?
'border-secondary' :
'border-primary'} border-4 ${orientation === 'horizontal' ?
'md:w-[12.5%] sm:w-[25%] w-1/4 lg:w-[10%] xl:w-[8%] 2xl:w-[6%]' :
'md:w-[25%] sm:w-[25%] w-1/4 lg:w-[20%] xl:w-[16%] 2xl:w-[16.6%]'} bg-no-repeat bg-[length:100%_100%] relative flex flex-col`}
style={{
backgroundImage: `url(${card.image})`
}}
>
<PopoverCard show={showPreview.value} image={card.image} ref={previewRef} />
<PopoverCard show={showPreview.value} image={card.image} ref={previewRef}/>

<div
class={`absolute text-white select-none top-[5%] left-[5%] ${isSide ?
Expand All @@ -52,8 +44,11 @@ export const CardDeckControl = component$<CardDeckControlProps>(({ card, orienta
<span>{deckQuantity.value}</span>
</div>

<div class="top-[5%] cursor-pointer inline right-[5%] select-none text-white absolute bg-orange-600 rounded-[50%] border-2 border-black p-1">
<Icon name="art" width={16} fill="white"/>
<div class="top-[5%] inline right-[5%] absolute">
<ButtonIcon disabled={d.deckData.splashArt === card.image}
onClick$={() => d.setSplashArt(card.image, card.id)}>
<Icon name="art" width={16} height={16} class="fill-primary"/>
</ButtonIcon>
</div>

<div
Expand Down
30 changes: 8 additions & 22 deletions src/features/deckList/DeckList.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import { $, component$ } from "@builder.io/qwik";
import { Link } from "@builder.io/qwik-city";
import type { ColumnDefinition } from "~/components/dataGrid/DataGrid";
import { DataGrid } from "~/components/dataGrid/DataGrid";
import { component$ } from "@builder.io/qwik";
import { DeckCard } from "~/components/deckCard";
import { useListPublicDeckLoader } from "~/providers/loaders/decks";

const columns: ColumnDefinition[] = [
{
id: 'name',
label: 'Name',
cell: $((row) => <Link href={`/decks/preview/${row.id}`}>{row.name}</Link>)
},
{
id: 'description',
label: 'Description'
},
{
id: 'likes',
label: 'Likes'
}
];

export const DeckList = component$(() => {
const decks = useListPublicDeckLoader();

return (
<div>
<DataGrid columns={columns} rows={decks.value.decks}/>
<div class="flex flex-wrap gap-[0.5rem]">
{decks.value.decks.map(d => {
return (
<DeckCard id={d.id} name={d.name} splashArt={d.splashArt} key={d.id}/>
);
})}
</div>
)
});
30 changes: 8 additions & 22 deletions src/features/myDecks/MyDecks.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import { $, component$ } from "@builder.io/qwik";
import { Link } from "@builder.io/qwik-city";
import type { ColumnDefinition } from "~/components/dataGrid/DataGrid";
import { DataGrid } from "~/components/dataGrid/DataGrid";
import { component$ } from "@builder.io/qwik";
import { DeckCard } from "~/components/deckCard";
import { useListMyDeckLoader } from "~/providers/loaders/decks";

const columns: ColumnDefinition[] = [
{
id: 'name',
label: 'Name',
cell: $((row) => <Link href={`/decks/create/${row.id}`}>{row.name}</Link>)
},
{
id: 'description',
label: 'Description'
},
{
id: 'likes',
label: 'Likes'
}
];

export const MyDecks = component$(() => {
const decks = useListMyDeckLoader();

return (
<div>
<DataGrid columns={columns} rows={decks.value.decks}/>
<div class="flex flex-wrap gap-[0.5rem]">
{decks.value.decks.map(d => {
return (
<DeckCard path="/decks/create" id={d.id} name={d.name} splashArt={d.splashArt} key={d.id}/>
);
})}
</div>
)
});
4 changes: 4 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
@tailwind components;
@tailwind utilities;

* {
box-sizing: border-box;
}

.theme-dark {
--qwik-primary: rgb(33 37 41);
--qwik-secondary: #E7AE32;
Expand Down
22 changes: 22 additions & 0 deletions src/hooks/useDeckQuantity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useComputed$ } from "@builder.io/qwik";
import type { DeckState } from "~/models/Deck";

export const useDeckQuantity = (deck: DeckState, cardId: number, isSide = false) => {

const deckQuantity = useComputed$(() => {
const masterDeckQuantity = Object.entries(deck.masterDeck)
.map(([, c]) => c)
.find(c => c.id === cardId)?.quantity ?? 0;
const treasureDeckQuantity = Object.entries(deck.treasureDeck)
.map(([, c]) => c)
.find(c => c.id === cardId)?.quantity ?? 0;
const sideDeckQuantity = Object.entries(deck.sideDeck)
.map(([, c]) => c)
.find(c => c.id === cardId)?.quantity ?? 0;

return isSide ? sideDeckQuantity : masterDeckQuantity + treasureDeckQuantity;
});

return [deckQuantity];

}
2 changes: 2 additions & 0 deletions src/models/Deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DeckItem {
name: string;
description: string | null;
likes: number;
splashArt?: string;
}

export interface DeckState {
Expand All @@ -22,4 +23,5 @@ export interface DeckState {
isPrivate: boolean;
likes: number;
splashArt?: string;
splashArtId?: number;
}
Loading

0 comments on commit f0d8923

Please sign in to comment.