Festalist.svelte 3.74 KB
<script>
    import { fly } from 'svelte/transition'
    import SideBar from './SideBar.svelte';
    let icon_show = true;
    let sidebar_show = false;

    function showBar() {
        sidebar_show = true;
    }

    function hide() {
        if (window.scrollY < 400) {
            icon_show = true;
        } else {
            icon_show = false;
            sidebar_show = false;
        }
    }

    import { District, City, Changed } from '../Stores/DistrictStore';
    import { AllFestas } from "../Stores/AllFestas";
    import { DisplayedFestas } from "../Stores/DisplayedFestas";

    let festaChecked = [];
    $: festaList = $AllFestas.filter( v => {
        if(v.addr1) {
            let district = v.addr1.split(" ")[0];
            let city = v.addr1.split(" ")[1];
            return ($District === "" || district === $District) &&
                    ($City === "" || city === $City);
        } else {
            return false;
        }
    });
    $: festaParsed = festaList.map( (v, i) => { 
        return { "id" : i, "title" : v.title, "addr1" : v.addr1, "contentid" : v.contentid, "checked" : false }
    });
    $: if ($Changed) {
        let len = festaList.length >= 9 ? 9 : festaList.length;
        festaChecked = [];
        for(let i = 0; i < len; i++)
            check(i);
    }
    $: DisplayedFestas.set(festaChecked);

    function check(idx) {
        if (!festaParsed[idx].checked) {
            if(festaChecked.length <= 8) {
                festaParsed[idx].checked = true;
                festaChecked = festaChecked.concat(festaList[idx]);
            } else {
                alert("9개 이상 선택하실 수 없습니다.");
            }
        } else {
            festaParsed[idx].checked = false;
            festaChecked = festaChecked.filter( v => {
                return v.contentid !== festaParsed[idx].contentid;
            });
        }            
    }
</script>

<style>
    .sidebtn {
        border-radius: 5px;
        border: 0px;
        width: 70px;
        height: 70px;
        position: fixed;
        left: -20px;
        top: 200px;
        padding-right: 10px;
        text-align: right;
        background-color: #e65100;
        color: #ffffff;
		box-shadow: 0 10px 20px rgb(0 0 0 / 15%);
    }

    .sidebtn:focus {
        background-color: #f57c00;
    }

    .sidebtn:hover {
        background-color: #ef6c00;
    }

    .festa {
		border: 1px solid #aaa;
		border-radius: 2px;
		box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
		padding: 2px;
        margin-bottom: 5px;
    }

    .festa:hover {
        background-color: #fff3e0;
    }

    .festa:focus {
        background-color: #ffe0b2;
    }

    .selected {
        background-color: #ffe0b2;
		border: 1px solid #aaa;
		border-radius: 2px;
		box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
		padding: 2px;
        margin-bottom: 5px;
    }

    .title {
        font-weight: bold;
        border-bottom: 2px solid #ff3e00;
    }

    .addr {
        display: flex;
        align-items: center;
    }

    .addr img {
        width: 20px;
        height: 20px;
    }

</style>

<svelte:window on:scroll={hide}></svelte:window>

{#if (icon_show)}
    <button class="sidebtn"
    transition:fly="{{ x : -50, duration : 400}}"
    on:click={showBar}>
        행사<br>목록
    </button>
{/if}
<SideBar bind:show={sidebar_show}>

    {#if festaParsed.length > 0}
        {#each festaParsed as festa}
            <div class="{festa.checked ? "selected" : "festa"}"
                on:click={() => {check(festa.id)}}>
                <div class="title">{festa.title}</div>
                <div class="addr"><img alt="pin" src="/public/map-pin.png"><div>{festa.addr1}</div></div>            
            </div>
        {/each}
    {:else}
        개최되는 축제가 없습니다.
    {/if}

</SideBar>