yay, we can add and remove intros, no persistence yet
parent
7b6b5c05f7
commit
768bac3bcf
|
@ -0,0 +1,45 @@
|
||||||
|
<script>
|
||||||
|
import { intros } from './store.ts';
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
export let introList = null;
|
||||||
|
export let exclude = null;
|
||||||
|
export let btnLabel = 'Add';
|
||||||
|
export let emptyMsg = null;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
const onConfirm = () => {
|
||||||
|
dispatch('confirm', selectedIntros)
|
||||||
|
selectedIntros = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
let selectedIntros = [];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="list">
|
||||||
|
{#if !!introList}
|
||||||
|
{#if introList.length > 0}
|
||||||
|
{#each introList as i}
|
||||||
|
<label id="list-item">
|
||||||
|
<input type="checkbox" bind:group={selectedIntros} name="selectedIntros" value={i}>
|
||||||
|
{$intros[i].name} ({!!$intros[i].filename ? $intros[i].filename : $intros[i].url})
|
||||||
|
</label>
|
||||||
|
{/each}
|
||||||
|
{:else if !!emptyMsg}
|
||||||
|
<p style='color: yellow'>{emptyMsg}</p>
|
||||||
|
{:else}
|
||||||
|
{/if}
|
||||||
|
{:else if !!exclude}
|
||||||
|
{#each $intros as intro, i}
|
||||||
|
{#if (!exclude.includes(i))}
|
||||||
|
<label id="list-item">
|
||||||
|
<input type="checkbox" bind:group={selectedIntros} name="selectedIntros" value={i}>
|
||||||
|
{intro.name} ({!!intro.filename ? intro.filename : intro.url})
|
||||||
|
</label>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
{:else}
|
||||||
|
{/if}
|
||||||
|
<button on:click={onConfirm}>{btnLabel}</button>
|
||||||
|
</div>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<script>
|
||||||
|
import { member, intros } from './store.ts';
|
||||||
|
|
||||||
|
const login = async (username) => {
|
||||||
|
await intros.fetchIntros();
|
||||||
|
await member._fakeLogin(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
let enteredUsername = '';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p style="color:red;">You need to login first</p>
|
||||||
|
<input bind:value={enteredUsername}>
|
||||||
|
<button on:click={() => loginPromise = login(enteredUsername)}>Login</button>
|
|
@ -8,6 +8,9 @@
|
||||||
</head>
|
</head>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
background-color: #313052;
|
background-color: #313052;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +19,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
div#list {
|
div#list {
|
||||||
display: flex;
|
display: inline-flex;
|
||||||
|
width: 85%;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-start;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#list-item {
|
#list-item {
|
||||||
|
@ -28,6 +32,7 @@
|
||||||
background-color: #1f1f36;
|
background-color: #1f1f36;
|
||||||
padding: 0.5em 0.5em 0.5em;
|
padding: 0.5em 0.5em 0.5em;
|
||||||
margin: 0 0 16px 0px;
|
margin: 0 0 16px 0px;
|
||||||
|
width: 100%;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,16 @@
|
||||||
<script>
|
<script>
|
||||||
import { member, intros } from '../store.ts';
|
import { member, intros } from '../store.ts';
|
||||||
|
import Login from '../Login.svelte';
|
||||||
|
import IntroSelector from '../IntroSelector.svelte';
|
||||||
|
|
||||||
let selectedIntros = [];
|
const addIntros = (event) => {
|
||||||
let selectedToRemoveIntros = [];
|
console.log($member.intros)
|
||||||
|
$member.intros = $member.intros.concat(event.detail);
|
||||||
const login = () => {
|
console.log($member.intros)
|
||||||
intros.fetchIntros()
|
|
||||||
member._fakeLogin("DayOldRice")
|
|
||||||
}
|
}
|
||||||
|
const removeIntros = (event) => {
|
||||||
const addIntros = () => {
|
$member.intros = $member.intros.filter((intro) => !event.detail.includes(intro));
|
||||||
$member.intros = $member.intros.concat(selectedIntros)
|
|
||||||
selectedIntros = [];
|
|
||||||
}
|
}
|
||||||
const removeIntros = () => {
|
|
||||||
$member.intros = $member.intros.filter((intro) => !selectedToRemoveIntros.includes(intro))
|
|
||||||
|
|
||||||
selectedToRemoveIntros = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$: console.log(selectedToRemoveIntros)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>MemeJoin - A bot for user intros</h1>
|
<h1>MemeJoin - A bot for user intros</h1>
|
||||||
|
@ -27,35 +18,17 @@
|
||||||
{#if !!$member}
|
{#if !!$member}
|
||||||
<p>{$member.username}</p>
|
<p>{$member.username}</p>
|
||||||
|
|
||||||
{#if $member.intros.length > 0}
|
<h3>Your Intros</h3>
|
||||||
<h3>Current Set Intros</h3>
|
<IntroSelector
|
||||||
<div id="list">
|
introList={$member.intros}
|
||||||
{#each $member.intros as intro}
|
on:confirm={removeIntros}
|
||||||
<label id="list-item">
|
btnLabel="Remove"
|
||||||
<input type="checkbox" bind:group={selectedToRemoveIntros} name="selectedToRemoveIntros" value={intro}>
|
emptyMsg="You don't have any intros, try adding one"/>
|
||||||
{$intros[intro].name} ({$intros[intro].filename})
|
|
||||||
</label>
|
|
||||||
{/each}
|
|
||||||
<button on:click={removeIntros}>Remove</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<h3 style='color:yellow'>You don't have any intros, try adding one</h3>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<h3>Add Intros</h3>
|
<h3>Add Intros</h3>
|
||||||
<div id="list">
|
<IntroSelector exclude={$member.intros} on:confirm={addIntros} />
|
||||||
{#each $intros as intro, i}
|
|
||||||
{#if (!$member.intros.includes(i))}
|
|
||||||
<label id="list-item">
|
|
||||||
<input type="checkbox" bind:group={selectedIntros} name="selectedIntros" value={i}>
|
|
||||||
{intro.name}
|
|
||||||
</label>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
<button on:click={addIntros}>Add</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
{:else}
|
||||||
<p style="color:red;">You need to login first</p>
|
<Login />
|
||||||
<button on:click={login}>Login</button>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue