<template>
    <div>
        <h1>Folders</h1>
        <ul>
            <li v-for="folder in folders" :key="folder.folder">
                <router-link :to="`/folder/${folder.folder}`">{{ folder.folder }} ({{ folder.count }})</router-link>
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    name: 'FoldersView',
    data() {
        return {
            folders: [],
        }
    },
    methods: {
        async reload() {
            const res = await fetch('/api/folders');
            const data = await res.json();
            console.log(data);
            this.folders = data.folders.sort((a, b) => new Date(b.folder) - new Date(a.folder));
        },
    },
    mounted() {
        this.reload();
    },
}
</script>

<style scoped></style>