collection -> inspiration

This commit is contained in:
isUnknown 2024-09-10 12:09:53 +02:00
parent dfda911664
commit 0d41b27cc3
9 changed files with 61 additions and 16 deletions

View file

@ -85,5 +85,20 @@ return [
'users', 'users',
'system' 'system'
] ]
],
'routes' => [
[
'pattern' => '(:all)logout.php',
'action' => function () {
$kirby = kirby();
$user = $kirby->user();
$user->logout();
session_start();
go($_SESSION['redirect_url']);
return '<html><body>logout</body></html>';
}
]
] ]
]; ];

View file

@ -1,3 +1,15 @@
<script>
const kirbyData = {
user: {
role: '<?= $kirby->user()->role() ?>',
<?php if ($kirby->user()->role() == 'client'): ?>
client: {
name: '<?= $kirby->user()->client()->toPage()->title() ?>',
uuid: '<?= $kirby->user()->client()->toPage()->uuid() ?>',
}
<?php endif ?>
}
}
</script>
</body> </body>
</html> </html>

View file

@ -1,8 +1,9 @@
<?php <?php
$collections = $page->children()->map(function ($child) { $inspirations = $page->children()->map(function ($child) {
return [ return [
'title' => $child->title()->value(), 'title' => $child->title()->value(),
'description' => $child->description()->value(),
'new' => $child->new()->value() === "true" ? true : false, 'new' => $child->new()->value() === "true" ? true : false,
'date' => $child->date()->toDate('Y-MM-d'), 'date' => $child->date()->toDate('Y-MM-d'),
'url' => $child->url(), 'url' => $child->url(),
@ -18,7 +19,7 @@ $collections = $page->children()->map(function ($child) {
})->values(); })->values();
$specificData = [ $specificData = [
"collections" => $collections "inspirations" => $inspirations
]; ];
$data = array_merge($genericData, $specificData); $data = array_merge($genericData, $specificData);

View file

@ -4,14 +4,20 @@
<script setup> <script setup>
import { useApiStore } from "./stores/api"; import { useApiStore } from "./stores/api";
import { useUserStore } from "./stores/user";
import { ref } from "vue"; import { ref } from "vue";
import home from "./views/Home.vue"; import home from "./views/Home.vue";
import inspirations from "./views/Inspirations.vue"; import inspirations from "./views/Inspirations.vue";
import { storeToRefs } from "pinia";
const components = { const components = {
home, inspirations home,
inspirations,
}; };
const { user } = storeToRefs(useUserStore());
user.value = kirbyData.user;
const data = ref(null); const data = ref(null);
const api = useApiStore(); const api = useApiStore();
api.fetchPageData().then((res) => (data.value = res)); api.fetchPageData().then((res) => (data.value = res));

View file

@ -73,7 +73,7 @@
<a href="#">Profil</a> <a href="#">Profil</a>
</li> </li>
<li data-icon="logout"> <li data-icon="logout">
<a href="#">Déconnexion</a> <a href="/logout.php">Déconnexion</a>
</li> </li>
</ul> </ul>
</footer> </footer>

View file

@ -1,14 +1,14 @@
<template> <template>
<header <header
class="flex | text-center" class="flex | text-center"
:style="'--image: url(\'' + collection.cover + '\');'" :style="'--image: url(\'' + inspiration.cover + '\');'"
> >
<!-- $inspiration->cover()->url() --> <!-- $inspiration->cover()->url() -->
<h2 <h2
class="inspiration__title | font-serif | text-lg" class="inspiration__title | font-serif | text-lg"
:class="{ new: collection.new }" :class="{ new: inspiration.new }"
> >
{{ collection.title }} {{ inspiration.title }}
</h2> </h2>
<!-- $inspiration->title() + class="new" if $inspiration->new()->isTrue() --> <!-- $inspiration->title() + class="new" if $inspiration->new()->isTrue() -->
<time <time
@ -18,7 +18,7 @@
> >
<!-- $inspiration->date() --> <!-- $inspiration->date() -->
<p class="inspiration__description"> <p class="inspiration__description">
{{ collection.description }} {{ inspiration.description }}
</p> </p>
</header> </header>
</template> </template>
@ -27,13 +27,13 @@
import dayjs from "dayjs"; import dayjs from "dayjs";
import "dayjs/locale/fr"; import "dayjs/locale/fr";
const { collection } = defineProps({ const { inspiration } = defineProps({
collection: Object, inspiration: Object,
}); });
dayjs.locale("fr"); dayjs.locale("fr");
const frenchFormattedDate = dayjs(collection.date).format("MMMM YYYY"); const frenchFormattedDate = dayjs(inspiration.date).format("MMMM YYYY");
</script> </script>
<style scoped> <style scoped>

View file

@ -1,6 +1,7 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { useApiStore } from "./api.js"; import { useApiStore } from "./api.js";
import { ref, computed } from "vue"; import { ref, computed } from "vue";
import { useUserStore } from "./user.js";
export const useProjectsStore = defineStore("projects", () => { export const useProjectsStore = defineStore("projects", () => {
const projects = ref([]); const projects = ref([]);

8
src/stores/user.js Normal file
View file

@ -0,0 +1,8 @@
import { defineStore } from "pinia";
import { ref } from "vue";
export const useUserStore = defineStore("user", () => {
const user = ref(null);
return { user };
});

View file

@ -19,9 +19,9 @@
<!-- TabPanel --> <!-- TabPanel -->
<section class="inspiration"> <section class="inspiration">
<Header :collection="currentCollection" /> <Header :inspiration="currentInspiration" />
<div class="grid masonry"> <div class="grid masonry">
<template v-for="(item, index) in currentCollection.media"> <template v-for="(item, index) in currentInspiration.media">
<figure class="flex" :style="'--rows: ' + (index % 2 ? 2 : 3)"> <figure class="flex" :style="'--rows: ' + (index % 2 ? 2 : 3)">
<button <button
class="favorite" class="favorite"
@ -72,13 +72,15 @@ const tabs = computed(() => {
{ {
label: "Les inspirations", label: "Les inspirations",
id: "all", id: "all",
count: currentCollection.media.length, count: currentInspiration.media.length,
isActive: true, isActive: true,
}, },
]; ];
}); });
const currentCollection = data.collections[0]; const currentInspiration = data.inspirations[0];
function toggleFavorite() {}
</script> </script>
<style scoped> <style scoped>