toggle favorite inspiration working + tab my favorite
This commit is contained in:
parent
0a412d48a4
commit
0ee0181206
6 changed files with 41 additions and 14 deletions
|
|
@ -2,7 +2,7 @@ Alt:
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Favoriteforusers:
|
Favoriteforusers: - user://HfuumN8s
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
|
Alt:
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Favoriteforusers:
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ Alt:
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Favoriteforusers: - user://WWjXgPWk
|
Favoriteforusers:
|
||||||
|
|
||||||
|
- user://WWjXgPWk
|
||||||
|
- user://HfuumN8s
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@ return [
|
||||||
$array = $favoriteForUsers->toArray();
|
$array = $favoriteForUsers->toArray();
|
||||||
$yaml = Data::encode($array, 'yaml');
|
$yaml = Data::encode($array, 'yaml');
|
||||||
|
|
||||||
$file->update([
|
$newFile = $file->update([
|
||||||
'favoriteForUsers' => $yaml
|
'favoriteForUsers' => $yaml
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return json_encode('Image ' . $action . ' favoris de l\'utilisateur ' . $user->email() . '.');
|
return json_encode($newFile->favoriteForUsers()->value());
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<figure class="flex" :style="'--rows: ' + (index % 2 ? 2 : 3)">
|
<figure
|
||||||
|
v-if="currentTab === 'all' || isFavorite"
|
||||||
|
class="flex"
|
||||||
|
:style="'--rows: ' + (index % 2 ? 2 : 3)"
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
class="favorite"
|
class="favorite"
|
||||||
aria-label="Ajouter aux favoris"
|
aria-label="Ajouter aux favoris"
|
||||||
|
|
@ -34,6 +38,7 @@ import { useApiStore } from "../../stores/api";
|
||||||
const { item, inspirationUri } = defineProps({
|
const { item, inspirationUri } = defineProps({
|
||||||
item: Object,
|
item: Object,
|
||||||
inspirationUri: String,
|
inspirationUri: String,
|
||||||
|
currentTab: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleFavoriteRoute = "/toggle-favorite.json";
|
const toggleFavoriteRoute = "/toggle-favorite.json";
|
||||||
|
|
@ -47,9 +52,9 @@ watch(isFavorite, (value) => {
|
||||||
userUuid: user.uuid,
|
userUuid: user.uuid,
|
||||||
inspirationUri,
|
inspirationUri,
|
||||||
};
|
};
|
||||||
api
|
api.fetchRoute(toggleFavoriteRoute, "POST", data).then((newValue) => {
|
||||||
.fetchRoute(toggleFavoriteRoute, "POST", data)
|
item.favoriteForUsers = newValue;
|
||||||
.then((res) => console.log(res));
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,16 @@
|
||||||
<section :id="currentTab" class="inspiration">
|
<section :id="currentTab" class="inspiration">
|
||||||
<Header :inspiration="currentInspiration" />
|
<Header :inspiration="currentInspiration" />
|
||||||
<div class="grid masonry">
|
<div class="grid masonry">
|
||||||
<Image
|
<template
|
||||||
v-for="(item, index) in currentInspiration.media"
|
v-for="(item, index) in currentInspiration.media"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:item="item"
|
>
|
||||||
:inspirationUri="currentInspiration.uri"
|
<Image
|
||||||
/>
|
:item="item"
|
||||||
|
:inspirationUri="currentInspiration.uri"
|
||||||
|
:currentTab="currentTab"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
@ -27,12 +31,14 @@ import Selector from "../components/inspirations/Selector.vue";
|
||||||
import Header from "../components/inspirations/Header.vue";
|
import Header from "../components/inspirations/Header.vue";
|
||||||
import Tabs from "../components/Tabs.vue";
|
import Tabs from "../components/Tabs.vue";
|
||||||
import Image from "../components/inspirations/Image.vue";
|
import Image from "../components/inspirations/Image.vue";
|
||||||
|
import { useUserStore } from "../stores/user";
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
|
|
||||||
const { data } = defineProps({
|
const { data } = defineProps({
|
||||||
data: Object,
|
data: Object,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const user = useUserStore().user;
|
||||||
const currentTab = ref("all");
|
const currentTab = ref("all");
|
||||||
const tabs = computed(() => {
|
const tabs = computed(() => {
|
||||||
return [
|
return [
|
||||||
|
|
@ -47,13 +53,18 @@ const tabs = computed(() => {
|
||||||
label: "Mes Favoris",
|
label: "Mes Favoris",
|
||||||
id: "favorites",
|
id: "favorites",
|
||||||
icon: "favorite",
|
icon: "favorite",
|
||||||
count: 6, // TODO: dynamiser (favorites.count)
|
count: favoriteImages.value.length, // TODO: dynamiser (favorites.count)
|
||||||
isActive: currentTab.value === "favorites",
|
isActive: currentTab.value === "favorites",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentInspiration = data.inspirations[0];
|
const currentInspiration = ref(data.inspirations[0]);
|
||||||
|
const favoriteImages = computed(() => {
|
||||||
|
return currentInspiration.value.media.filter(
|
||||||
|
(image) => image.favoriteForUsers?.includes(user.uuid) ?? false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
function changeTab(newValue) {
|
function changeTab(newValue) {
|
||||||
currentTab.value = newValue;
|
currentTab.value = newValue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue