Skip to content

Commit

Permalink
Merge pull request #6 from SlovakNationalGallery/NSNG-424-refactor-in…
Browse files Browse the repository at this point in the history
…teraction-store

ready: Refactor Interaction store
  • Loading branch information
FrantisekMichalSebestyen authored Nov 16, 2023
2 parents f280688 + e32e6ff commit 8436e64
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 270 deletions.
6 changes: 3 additions & 3 deletions src/components/bucketlist/Bucketlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ const props = defineProps<{
id: string
}>()
const bucketlistStore = useBucketlistStore()
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
const bucketlist = ref<Bucketlist | null>(null)
const found = computed(() => {
return bucketlist.value?.items.filter((item) => interactionStore.isItemViewed(item.id))
return bucketlist.value?.items.filter((item) => itemStore.isItemViewed(item.id))
})
const notFound = computed(() => {
return bucketlist.value?.items.filter((item) => !interactionStore.isItemViewed(item.id))
return bucketlist.value?.items.filter((item) => !itemStore.isItemViewed(item.id))
})
const unlocked = computed(() => !notFound.value?.length)
Expand Down
26 changes: 0 additions & 26 deletions src/components/interactions/InteractionItem.vue

This file was deleted.

18 changes: 0 additions & 18 deletions src/components/interactions/InteractionItemFavourited.vue

This file was deleted.

13 changes: 0 additions & 13 deletions src/components/interactions/InteractionItemViewed.vue

This file was deleted.

21 changes: 0 additions & 21 deletions src/components/interactions/InteractionPlaceViewed.vue

This file was deleted.

21 changes: 0 additions & 21 deletions src/components/interactions/InteractionSectionViewed.vue

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/interactions/InteractionStory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}"
@click="emit('navigate', link)"
>
<SvgChatCircle
<SvgChatCircle
v-if="!activeOrTransitioning || interactionStore.hasVisitedAllLinks(link.story_id)"
class="flex-none"
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
:class="{ 'text-center': !isFrontpage }"
>
{{ $t(isOpenedAbout ? 'About the App' : title) }}
<span v-if="isMyCollection">({{ interactionStore.viewedItemsCount }})</span>
<span v-if="isMyCollection">({{ itemStore.viewedItemsCount }})</span>
</h1>
<div v-if="isMyCollection" class="flex-1 border-l-2 border-transparent px-3 text-right">
<!-- <button class="rounded-xl bg-green px-3 py-1 text-sm font-bold" @click="scroll('share')">
Expand All @@ -45,7 +45,7 @@ import About from '@/components/about/About.vue'
import HistoryBack from '@/components/misc/HistoryBack.vue'
const route = useRoute()
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
const isOpenedAbout = ref(false)
const isActive = ref(false)
Expand All @@ -69,8 +69,8 @@ const scroll = (id: string) => {
})
}
interactionStore.$onAction(({ name }) => {
if (name === 'addItemViewed' && !interactionStore.viewedItemsCount) {
itemStore.$onAction(({ name }) => {
if (name === 'addItemViewed' && !itemStore.viewedItemsCount) {
displayTooltip()
}
})
Expand Down
6 changes: 3 additions & 3 deletions src/components/misc/ViewedItemsCount.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<router-link to="/collection" class="relative">
<div class="flex h-full items-center justify-end">
<div class="mr-1 text-lg font-bold">{{ interactionStore.viewedItemsCount }}</div>
<SvgEye :class="{ '!fill-green': interactionStore.viewedItemsCount }" />
<div class="mr-1 text-lg font-bold">{{ itemStore.viewedItemsCount }}</div>
<SvgEye :class="{ '!fill-green': itemStore.viewedItemsCount }" />
</div>
<Transition
enter-active-class="transition-all"
Expand All @@ -24,5 +24,5 @@ defineProps<{
showTooltip?: boolean
}>()
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
</script>
10 changes: 5 additions & 5 deletions src/components/timeline/Timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<article class="mt-8 mb-6 px-4">
<h3 class="flex items-center justify-between gap-x-1 text-1.5xl font-medium leading-6">
<span class="grow">{{ $t('Explored artworks') }}</span>
<span>{{ interactionStore.viewedItemsCount }}</span>
<SvgEye :class="{ '!fill-green': interactionStore.viewedItemsCount }" />
<span>{{ itemStore.viewedItemsCount }}</span>
<SvgEye :class="{ '!fill-green': itemStore.viewedItemsCount }" />
</h3>
<!-- <template v-if="interactionStore.viewedItemsCount">
<!-- <template v-if="storyStore.viewedItemsCount">
<ShareCollection class="mt-4" />
<div class="mt-3">
{{ $t('Save the link to your artworks and return to them anywhere') }}
Expand All @@ -26,7 +26,7 @@
<template #description>{{ $t('The artwork will be saved to your history') }}</template>
</Thumbnail>
</router-link>
<ItemLoader v-for="id in interactionStore.viewedItemIds" :id="id" v-slot="{ item }" :key="id">
<ItemLoader v-for="id in itemStore.viewedItemsIds" :id="id" v-slot="{ item }" :key="id">
<router-link :to="`/item/${id}`">
<ItemThumbnail :item="item" />
</router-link>
Expand All @@ -40,5 +40,5 @@ import Thumbnail from '@/components/general/Thumbnail.vue'
import ItemLoader from '@/components/general/ItemLoader.vue'
import ItemThumbnail from '@/components/general/ItemThumbnail.vue'
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
</script>
5 changes: 3 additions & 2 deletions src/composables/Survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { getActiveLanguage } from 'laravel-vue-i18n'

export function useSurvey() {
const interactionStore = useInteractionStore()

const { viewedItemsCount, stories } = storeToRefs(interactionStore)
const itemStore = useItemStore()
const { stories } = storeToRefs(interactionStore)
const { viewedItemsCount } = storeToRefs(itemStore)
const isDone = ref(useStorage('isSurveyDone', false))
const wasExited = ref(useStorage('wasSurveyExited', false))
const SURVEY_ID =
Expand Down
6 changes: 0 additions & 6 deletions src/models/Interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import BaseModel from '@/models/_BaseModel'

export default class Interaction extends BaseModel {
public declare id: string
public declare name: string
public declare author: string
public declare title: string
public declare type: 'story' | 'itemFavourited' | 'itemViewed' | 'sectionViewed' | 'placeViewed'
public declare size: number

public linkId: string | null
constructor(o: any) {
super(o)
Expand Down
28 changes: 0 additions & 28 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<TransitionGroup name="interactions">
<template v-for="(interaction, i) in interactionStore.interactions" :key="i">
<InteractionStory
v-if="interaction.type === 'story'"
:ref="(component) => setStoryRef(component!, interaction)"
:story="storyStore.get(interaction.id)!"
:link-id="interaction.linkId!"
Expand All @@ -13,26 +12,6 @@
@navigate="(link) => navigate(interaction, link)"
@undo="undo(interaction)"
/>
<InteractionItemFavourited
v-else-if="interaction.type === 'itemFavourited'"
:item="itemStore.get(interaction.id)!"
class="my-4"
/>
<InteractionItemViewed
v-else-if="interaction.type === 'itemViewed'"
:item="itemStore.get(interaction.id)!"
class="my-4"
/>
<InteractionSectionViewed
v-else-if="interaction.type === 'sectionViewed'"
:section="sectionStore.get(interaction.id)!"
class="my-4"
/>
<InteractionPlaceViewed
v-else-if="interaction.type === 'placeViewed'"
:place="placeStore.get(interaction.id)!"
class="my-4"
/>
</template>
</TransitionGroup>
</div>
Expand All @@ -46,18 +25,11 @@ import type { ILink } from '@/models/_Interfaces'
import type { Component } from 'vue'
import CodePanel from '@/components/layout/CodePanel.vue'
import InteractionItemFavourited from '@/components/interactions/InteractionItemFavourited.vue'
import InteractionItemViewed from '@/components/interactions/InteractionItemViewed.vue'
import InteractionSectionViewed from '@/components/interactions/InteractionSectionViewed.vue'
import InteractionPlaceViewed from '@/components/interactions/InteractionPlaceViewed.vue'
import InteractionStory from '@/components/interactions/InteractionStory.vue'
import Interaction from '@/models/Interaction'
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
const sectionStore = useSectionStore()
const storyStore = useStoryStore()
const placeStore = usePlaceStore()
const storyMap = new Map()
Expand Down
9 changes: 3 additions & 6 deletions src/pages/item/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,21 @@ import Bucketlist from '@/models/Bucketlist'
const route = useRoute()
const bucketlistStore = useBucketlistStore()
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
const item = ref<Item>()
const bucketlist = ref<Bucketlist>()
const unlocked = computed(() => found.value?.length === bucketlist.value?.items.length)
const found = computed(() =>
bucketlist.value?.items.filter((item) => interactionStore.isItemViewed(item.id))
bucketlist.value?.items.filter((item) => itemStore.isItemViewed(item.id))
)
const unlocked = computed(() => found.value?.length === bucketlist.value?.items.length)
onMounted(async () => {
const { id } = useParams()
item.value = await itemStore.load(id)
interactionStore.addItemViewed(item.value.id)
itemStore.addItemViewed(item.value.id)
const defaultBucketlist = item.value.bucketlists.find(
(bucketlist) => bucketlist.id === import.meta.env.VITE_DEFAULT_BUCKETLIST
)
Expand Down
2 changes: 0 additions & 2 deletions src/pages/place/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ import ResponsiveVideoEmbed from '@/components/general/ResponsiveVideoEmbed.vue'
import Place from '@/models/Place'
const route = useRoute()
const interactionStore = useInteractionStore()
const placeStore = usePlaceStore()
const place = ref<Place | null>(null)
onMounted(async () => {
const { id } = useParams()
place.value = await placeStore.load(id)
place.value?.id && interactionStore.addPlaceViewed(place.value.id)
})
const codeImage = computed(() => {
Expand Down
4 changes: 0 additions & 4 deletions src/pages/section/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import ItemThumbnail from '@/components/general/ItemThumbnail.vue'
import ItemImage from '@/components/general/ItemImage.vue'
import Section from '@/models/Section'
// const interactionStore = useInteractionStore()
const sectionStore = useSectionStore()
const section = ref<Section | null>(null)
Expand All @@ -59,9 +58,6 @@ const { id } = useParams()
onMounted(async () => {
section.value = await sectionStore.load(id)
// TODO: where did item come from?
// interactionStore.addSectionViewed(item.value.id)
})
const codeImage = computed(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/pages/section/[sectionId]/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,21 @@ import Item from '@/models/Item'
const route = useRoute()
const bucketlistStore = useBucketlistStore()
const interactionStore = useInteractionStore()
const itemStore = useItemStore()
const item = ref<Item | null>(null)
const bucketlist = ref<Bucketlist | null>(null)
const found = computed(() =>
bucketlist.value?.items.filter((item) => interactionStore.isItemViewed(item.id))
bucketlist.value?.items.filter((item) => itemStore.isItemViewed(item.id))
)
const unlocked = computed(() => found.value?.length === bucketlist.value?.items.length)
onMounted(async () => {
const { id } = useParams()
item.value = await itemStore.load(id)
interactionStore.addItemViewed(item.value.id)
itemStore.addItemViewed(item.value.id)
const defaultBucketlist = item.value.bucketlists.find(
(bucketlist) => bucketlist.id === import.meta.env.VITE_DEFAULT_BUCKETLIST
)
Expand Down
Loading

0 comments on commit 8436e64

Please sign in to comment.