feat: ok so i had to implement variants hhhh

no more amogus
This commit is contained in:
Ax333l 2023-01-16 21:29:11 +01:00
parent e1d1e9fbe5
commit cbf523a365
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
3 changed files with 81 additions and 30 deletions

View File

@ -1,14 +1,19 @@
<script lang="ts"> <script lang="ts">
import Modal from './Dialogue.svelte';
import Variants from './Variants.svelte';
export let name: string; export let name: string;
export let logo: string;
export let filename: string;
export let id: string;
export let selected: Array<string>; export let selected: Array<string>;
export let variants;
export let clicked = false; export let clicked = false;
const handleClick = () => { let has_variants = variants.length > 1;
clicked = !clicked; let modalOpen = false;
// TODO: cycle between them.
let current = variants[0];
function select_logo(id) {
// clicked = !clicked;
if (selected.includes(id)) { if (selected.includes(id)) {
selected = selected.filter((e) => e !== id); selected = selected.filter((e) => e !== id);
} else { } else {
@ -17,16 +22,36 @@
selected = selected; selected = selected;
} }
console.log(selected); console.log(selected);
}
const handleClick = () => {
if (!has_variants) {
select_logo(current.id);
} else {
modalOpen = !modalOpen;
}
}; };
</script> </script>
<Modal bind:modalOpen>
<svelte:fragment slot="title">{name}</svelte:fragment>
<svelte:fragment slot="description">
guhhhhhhhhhhhhhhhhhhhhh
</svelte:fragment>
<Variants />
</Modal>
<!-- SHUT UP --> <!-- SHUT UP -->
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="option" on:click={handleClick} on:keypress={handleClick} tabindex="0" class:clicked> <div class="option" on:click={handleClick} on:keypress={handleClick} tabindex="0" class:clicked>
<img src={logo} alt={filename} /> <img src={current.gdrive_direct_url} alt={current.filename} />
<div class="text"> <div class="text">
<h2>{name}</h2> <h2>{name}</h2>
<h6>{filename}</h6> <h6>{current.filename}</h6>
{#if has_variants}
<h4>This logo has variants</h4>
{/if}
</div> </div>
</div> </div>
@ -53,6 +78,10 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
h4 {
font-weight: 800;
}
h6 { h6 {
font-size: 0.9rem; font-size: 0.9rem;
overflow: hidden; overflow: hidden;

View File

@ -0,0 +1 @@
<img src="https://cdn.discordapp.com/emojis/1063976228660457552.gif?size=48&quality=lossless" style="width: 20rem;" alt="h">

View File

@ -8,8 +8,26 @@
import Button from '$lib/components/atoms/Button.svelte'; import Button from '$lib/components/atoms/Button.svelte';
let modalOpen = false; let modalOpen = false;
let selected: Array<string> = []; let selected = {};
let logos: Array<any> = []; function calc_ui_selected_count(v) {
let n = 0;
for (const item of Object.values(v)) {
if (item.length != 0) {
console.log(item);
n += 1;
}
}
return n;
}
function calc_selected_logo_ids(v) {
return [...Object.values(v)].map(data => data.variants).flat();
}
// afn please don't do this lol this is shitty code
$: ui_selected_count = calc_ui_selected_count(selected);
$: selected_logo_ids = calc_selected_logo_ids(selected);
let logos = [];
let logo_ids = [];
let transitionDirection = 5; let transitionDirection = 5;
let logoAmount = 4; let logoAmount = 4;
let currentPage = 0; let currentPage = 0;
@ -48,10 +66,16 @@
const response = await fetch('https://poll.revanced.app/logos'); const response = await fetch('https://poll.revanced.app/logos');
const json = await response.json(); const json = await response.json();
// make better json for (const name of Object.keys(json)) {
for (const name of Object.keys(json)) { // lol the performance
logos.push({ name, ...json[name] }); selected[name] = [];
}
logos.push({ name, variants: json[name].logos });
logo_ids = [...logo_ids, ...json[name].logos.map(v => v.id)];
}
console.log(logos);
console.log(logo_ids);
console.log(selected_logo_ids);
// randomize the order of the logos to minimize bias // randomize the order of the logos to minimize bias
for (let i = logos.length - 1; i > 0; i--) { for (let i = logos.length - 1; i > 0; i--) {
@ -109,6 +133,7 @@
async function submitBallot() { async function submitBallot() {
// console.log(token); // console.log(token);
throw Error("This shit needs to be redone now hhhhhhh");
const data = { const data = {
votes: logos.map((logo) => ({ cid: logo.id, vote: selected.includes(logo.id) })) votes: logos.map((logo) => ({ cid: logo.id, vote: selected.includes(logo.id) }))
}; };
@ -145,7 +170,7 @@
<h3>ReVanced</h3> <h3>ReVanced</h3>
<h1>{finalPage ? 'Review selected logos' : 'Select logos'}</h1> <h1>{finalPage ? 'Review selected logos' : 'Select logos'}</h1>
<h2> <h2>
{selected.length}/{logos.length} selected · Page {Number(currentPage) + 1}/{logoPages + 1} {ui_selected_count}/{logos.length} selected · Page {Number(currentPage) + 1}/{logoPages + 1}
</h2> </h2>
<div class="top-custom-button-container"> <div class="top-custom-button-container">
<button on:click={() => (modalOpen = !modalOpen)}>How does this work?</button> <button on:click={() => (modalOpen = !modalOpen)}>How does this work?</button>
@ -154,33 +179,29 @@
</div> </div>
<div class="options-grid"> <div class="options-grid">
{#each logos.slice(min, max) as { id, gdrive_direct_url, name, filename }} {#each logos.slice(min, max) as { variants, name }}
{#key currentPage} {#key currentPage}
<span in:fly={{ x: transitionDirection, easing: expoOut, duration: 1000 }}> <span in:fly={{ x: transitionDirection, easing: expoOut, duration: 1000 }}>
<LogoOption <LogoOption
bind:selected bind:selected={selected[name]}
clicked={selected.includes(id)} clicked={selected[name].length != 0}
{id} {variants}
logo={gdrive_direct_url}
{name} {name}
{filename}
/> />
</span> </span>
{/key} {/key}
{/each} {/each}
{#if finalPage} {#if finalPage}
{#each logos as { id, gdrive_direct_url, name, filename }} {#each logos as { variants, name }}
{#if selected.includes(id)} {#if selected[name].length != 0}
<span in:fly={{ x: transitionDirection, easing: expoOut, duration: 1000 }}> <span in:fly={{ x: transitionDirection, easing: expoOut, duration: 1000 }}>
<LogoOption <LogoOption
bind:selected bind:selected
clicked={selected.includes(id)} clicked={selected[name].length != 0}
{id} {variants}
logo={gdrive_direct_url} {name}
{name} />
{filename}
/>
</span> </span>
{/if} {/if}
{/each} {/each}