Skip to content

Commit

Permalink
Merge pull request #320 from DecentralCardGame/card-creator-fixes
Browse files Browse the repository at this point in the history
Card creator fixes
  • Loading branch information
patrickwieth authored Oct 7, 2024
2 parents c693919 + a00cf83 commit 1d37edb
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ export default {
</script>

<style lang="scss">
.vue-notification {
// types (green, amber, red)
&.success {
color: #000000;
background: #4cbb17;
border-left-color: #006400;
}
&.error {
background: #d82027;
border-left-color: #800000;
}
}
@font-face {
font-family: 'Museo900-Regular';
font-weight: normal;
Expand Down
4 changes: 2 additions & 2 deletions src/components/elements/GalleryComponent.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div
id="galleryWrapper"
class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-5 gap-16"
class="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 min-[1800px]:grid-cols-5 gap-12"
>
<div
v-for="card in state.cards"
:key="card.id"
class="hover:scale-105 drop-shadow-glowCCYellow"
class="hover:scale-110 drop-shadow-glowCCYellow"
@click="emit('cardClicked', card.id)"
>
<div>
Expand Down
65 changes: 65 additions & 0 deletions src/def-composables/useCouncil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useTx } from "@/def-composables/useTx";
import { ref, watch, type Ref, computed } from "vue";
import * as R from "ramda";
import type { SingleVote } from "decentralcardgame-cardchain-client-ts/DecentralCardGame.cardchain.cardchain";
import type { VoteType } from "decentralcardgame-cardchain-client-ts/DecentralCardGame.cardchain.cardchain/types/cardchain/cardchain/voting";
import { useUser } from "./useUser";
import { useQuery } from "./useQuery"

const KEY = "votingList";
const { multiVoteCard } = useTx();
const { user, queryUser } = useUser();

let stored = window.localStorage.getItem(KEY);
const votes: Ref<SingleVote[]> = ref(
stored ? Object.assign([], JSON.parse(stored)) : []
);
const votableCards = computed(() => {
console.log("USER:", user)
return user.value.votableCards.map(v => Number(v))
});
const cardsLeft = computed(() => {
let taken = votes.value.map((v) => v.cardId);
return votableCards.value.filter((v) => !taken.includes(v));
});
const current = computed(() => cardsLeft.value.at(0));
const next = computed(() => cardsLeft.value.at(1));

const councilStatus = computed(() => user.value.CouncilStatus);

watch(
() => R.clone(votes.value),
(currentValue) => {
console.log("Saving current votes: ", currentValue);
window.localStorage.setItem(KEY, JSON.stringify(currentValue));
}
);

const send = (then: (res: any) => void, err: (res: any) => void) => {
console.log("send", votes.value);
multiVoteCard(
votes.value,
(res: any) => {
queryUser().then(() => {

votes.value = [];
});
then(res);
},
err
);
};

const add = (cardId: number, voteType: VoteType) => {
console.log("vote ", voteType, " for ", cardId);
votes.value.push({
cardId,
voteType,
});
};

const isEmpty = computed(() => votes.value.length == 0);

export const useCouncil = () => {
return { councilStatus, add, send, isEmpty, current, next, cardsLeft };
};
6 changes: 3 additions & 3 deletions src/def-composables/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const useNotificationsInstance = () => {
group: "bottom-right-notification",
title: title,
text: text,
type: "notification--alert",
type: "error",
duration: 5000
});
});
Expand All @@ -34,7 +34,7 @@ const useNotificationsInstance = () => {
group: "bottom-right-notification",
title: title,
text: text,
type: "notification--success",
type: "success",
duration: 5000
});
});
Expand All @@ -44,7 +44,7 @@ const useNotificationsInstance = () => {
group: "bottom-right-notification",
title: title,
text: text,
type: "notification--info",
type: "info",
duration: 5000
});
});
Expand Down
6 changes: 6 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const LearnPage = () => import("@/views/LearnPage.vue");
const DownloadPage = () => import("@/views/DownloadPage.vue");
const CommunityPage = () => import("@/views/About/CommunityPage.vue");
const EncounterVotingPage = () => import("@/views/Voting/EncounterVotingPage.vue")
const EncounterCouncilPage = () => import("@/views/Voting/EncounterCouncilPage.vue")
const Rewards = () => import("@/views/Rewards.vue");
const Discord = () => import("@/views/Discord.vue");

Expand Down Expand Up @@ -87,6 +88,11 @@ const routes = [
name: "EncounterVoting",
component: EncounterVotingPage,
},
{
path: "/vote/council",
name: "EncounterCouncil",
component: EncounterCouncilPage,
},
{
path: "/cardview/:id",
name: "CardView",
Expand Down
17 changes: 13 additions & 4 deletions src/views/CardCreatorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Congratulations!
</div>
<div class="p-4">
You successfully minted your card!
You successfully {{ mode == Mode.EDIT ? "edited" : "minted" }} your card!
</div>
<BaseCCButton
class="p-16 pb-60"
Expand Down Expand Up @@ -701,7 +701,7 @@
v-model="model.notes"
class="py-3 px-2 mx-3 bg-transparent text-white text-opacity-100 text-s focus:border-black border-0 border-solid focus:outline-none focus:ring-0 placeholder-white placeholder-opacity-50"
placeholder="Or some kind words."
maxLength="25"
maxLength="50"
>
</div>

Expand Down Expand Up @@ -739,7 +739,8 @@
:model="model"
/>
</div>
<div class="text-left flex flex-col">

<div class="text-left flex flex-col justify-between">
<div class="py-5 flex flex-col items-start">
<div class="pl-12 py-3 text-s font-bold">
SUMMARY
Expand Down Expand Up @@ -1493,6 +1494,7 @@ export default {
this.model.image,
this.model.fullArt,
this.resetCard,
() => {},
(err) => {
this.notifyFail("Update Artwork failed", err);
console.error(err);
Expand Down Expand Up @@ -1697,6 +1699,12 @@ export default {
checkASCII(newModel.FlavourText, "Flavour Text");
checkASCII(newModel.CardName, "Card Name");
// we want to reduce to 2 tags
if (newModel.Tags.length > 2) {
console.log("too many tags, dropping 3rd")
newModel.Tags.length = 2
}
let newCard = newModel.toChainCard();
newCard.artist = this.designateArtist ? this.artistAddress : this.address;
Expand Down Expand Up @@ -1724,7 +1732,7 @@ export default {
if (this.mode == Mode.EDIT) {
let handleErr = (err) => {
this.notifyFail("Update Card failed", err);
console.error(err);
console.log(err);
};
saveCardContent(this.model.id, newCard, this.resetCard, handleErr);
Expand All @@ -1734,6 +1742,7 @@ export default {
newCard.image,
newCard.fullArt,
this.successScreen,
() => {},
handleErr,
);
} else if (!this.address) {
Expand Down
151 changes: 151 additions & 0 deletions src/views/Voting/EncounterCouncilPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<template>
<div class="flex flex-col text-lg bg-cc-yellow">
<div class="text-center pt-12 pb-6">
<p class="text-4xl pb-2">
Council Encounter
</p>
<p>Make a decision for the card draft below. <br>
Another player has designed this card. <br>
Your review is needed to make it a valid card for ranked play!</p>
</div>
<div class="bg-black text-white flex justify-center">
<div class="p-8">
<div
v-if="!loggedIn"
class="text-center"
>
<p class="pb-4">
To vote on cards you have to <b>login</b> first!
</p>
<RouterCCButton :to="{ name: 'Login' }">
Login
</RouterCCButton>
</div>
<div v-else-if="current">
<div class="w-64 inline-block align-top mr-12">
<p>
<b>{{ state.currentCard.CardName }}</b><br>
<i v-if="state.currentCard.FlavourText">
"{{ state.currentCard.FlavourText }}"
</i>
<br><br>
<b>Advanced Card Information</b> <br>
Votepool: {{ votePool }} <br>
Status: {{ state.currentCard.status }} <br>
</p>
<br>
<keyword-component :keywords="state.currentCard.Keywords" />
</div>
<div class="inline-block">
<CardComponent
:model="state.currentCard"
class="h-[35rem]"
/>
</div>
</div>
<div v-else-if="!cardsLeft.length && !isEmpty">
<p class="pb-4">
To make your votes take effect, you have to send them to the chain.
</p>
<BaseCCButton @click="sendToChain()">
Send votes to chain
</BaseCCButton>
</div>
</div>
</div>
<div
v-if="cardsLeft.length"
class="flex justify-center flex-wrap gap-4 py-12"
>
<SmallCCButton
v-for="(elem, idx) in [
{ text: 'Fair Enough', type: VoteType.fairEnough },
{ text: 'Overpowered', type: VoteType.overpowered },
{ text: 'Underpowered', type: VoteType.underpowered },
{ text: 'Inappropriate', type: VoteType.inappropriate },
]"
:key="idx"
:type="Color.RED"
@click="vote(elem.type)"
>
{{ elem.text }}
</SmallCCButton>
<SmallCCButton
v-if="!isEmpty"
:type="Color.RED"
@click="sendToChain()"
>
Send votes to chain
</SmallCCButton>
</div>
</div>
</template>

<script setup lang="ts">
import CardComponent from "@/components/elements/CardComponent.vue";
import KeywordComponent from "@/components/elements/KeywordComponent.vue";
import { useLoggedIn } from "@/def-composables/useLoggedIn";
import { Card } from "@/model/Card";
import { useNotifications } from "@/def-composables/useNotifications";
import { useCouncil } from "@/def-composables/useCouncil";
import { computed, onMounted, reactive, watch } from "vue";
import { VoteType } from "decentralcardgame-cardchain-client-ts/DecentralCardGame.cardchain.cardchain/types/cardchain/cardchain/voting";
import { useCards } from "@/def-composables/useCards";
import BaseCCButton from "@/components/elements/CCButton/BaseCCButton.vue";
import SmallCCButton from "@/components/elements/CCButton/SmallCCButton.vue";
import { Color } from "@/components/utils/color";
import RouterCCButton from "@/components/elements/CCButton/RouterCCButton.vue";
const { loggedIn } = useLoggedIn();
const { notifySuccess } = useNotifications();
const { getCard } = useCards();
const { councilStatus, add, send, isEmpty, cardsLeft, current, next } = useCouncil();
const initialState: {
currentCard: Card;
} = {
currentCard: new Card(),
};
const state = reactive(initialState);
const votePool = computed(() =>
state.currentCard.votePool.normalize().pretty(),
);
const vote = (type: VoteType) => add(current.value!, type);
const loadCard = () => {
if (current.value) {
getCard(current.value!).then((parsedCard: Card) => {
if (parsedCard) {
state.currentCard = parsedCard;
} else {
console.error("card could not be parsed", parsedCard);
}
});
}
if (next.value) {
getCard(next.value!);
}
};
onMounted(() => {
console.log("Council Status:", councilStatus.value)
if (loggedIn.value) {
loadCard();
}
});
watch(current, loadCard);
const sendToChain = () => {
send(
() => {
notifySuccess("Success!", "Voted succesfully!");
},
(err) => {
console.log(err);
},
);
};
</script>

0 comments on commit 1d37edb

Please sign in to comment.