Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Create a proof-of-concept for Pinia migration #906

Merged
merged 31 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
99142ea
Install Pinia
dhruvkb Feb 21, 2022
b30c432
Update the active media store to use Pinia
dhruvkb Feb 21, 2022
361730e
Delete the Vuex store
dhruvkb Feb 21, 2022
9989251
Update type definition and use it
dhruvkb Feb 21, 2022
c2e2df5
Document the store composition variable
dhruvkb Feb 21, 2022
61945b9
Fix a lint error that Prettier did not catch locally
dhruvkb Feb 21, 2022
846b0c2
Use `~` instead of `@` in imports
dhruvkb Feb 21, 2022
c4221bb
Update the nav store to use Pinia
dhruvkb Feb 21, 2022
299f255
Merge branch 'main' into pinia
dhruvkb Feb 21, 2022
5173d09
Rename store
dhruvkb Feb 21, 2022
46b1639
Make mutation payload fields non-nullable
dhruvkb Feb 21, 2022
1ce982a
Merge branch 'main' into pinia
dhruvkb Feb 21, 2022
2c9c8ba
Fix leftover incorrect usage of the active media store
dhruvkb Feb 21, 2022
1f66bfe
Make active media setup store and add unit tests (#997)
obulat Feb 23, 2022
53f4029
Merge branch 'main' into pinia
obulat Feb 24, 2022
8a218f0
Merge branch 'main' into pinia
obulat Feb 27, 2022
580b96f
merge main
obulat Mar 2, 2022
113e46c
fix possibly undefined
obulat Mar 2, 2022
0db4452
Add tests and other small fixes
obulat Mar 2, 2022
e9f017e
Update nuxt.config.ts
obulat Mar 2, 2022
7c59473
Move converted modules to /stores/ and add unit tests
obulat Mar 2, 2022
5934ff1
Merge branch 'pinia' of github.com:WordPress/openverse-frontend into …
obulat Mar 2, 2022
819ad80
Fix linting error
obulat Mar 2, 2022
7c8bd91
Update nuxt.config.ts
obulat Mar 2, 2022
5820d15
Add changes from review
obulat Mar 2, 2022
dcfcfb2
Register component
obulat Mar 2, 2022
cf4229b
Merge branch 'pinia' of github.com:WordPress/openverse-frontend into …
obulat Mar 2, 2022
6942747
Make properties readonly
obulat Mar 2, 2022
66fd73b
Merge branch 'main' into pinia
obulat Mar 2, 2022
d701ee9
Remove dublicates
obulat Mar 2, 2022
4647efe
Merge branch 'main' into pinia
obulat Mar 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// WebStorm fix for `~` alias not working:
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000771544-ESLint-does-not-work-with-webpack-import-resolver-in-2017-3
process.chdir(__dirname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! What a weird find.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely. It seems that the bug reports are from 2018, but I'm having this problem now 🤷

module.exports = {
root: true,
env: {
Expand Down
7 changes: 7 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const config: NuxtConfig = {
'@nuxtjs/style-resources',
'@nuxtjs/svg',
'@nuxtjs/eslint-module',
['@pinia/nuxt', { disableVuex: false }],
obulat marked this conversation as resolved.
Show resolved Hide resolved
],
// Load the scss variables into every component:
// No need to import them. Since the variables will not exist in the final build,
Expand Down Expand Up @@ -223,6 +224,12 @@ const config: NuxtConfig = {
// Enables use of IDE debuggers
extend(config, ctx) {
config.devtool = ctx.isClient ? 'source-map' : 'inline-source-map'
// Mitigates import errors for Pinia
obulat marked this conversation as resolved.
Show resolved Hide resolved
config.module?.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
})
},
},
storybook: {
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@nuxtjs/sentry": "^5.1.5",
"@nuxtjs/sitemap": "^2.4.0",
"@nuxtjs/svg": "^0.3.0",
"@pinia/nuxt": "^0.1.8",
"@popperjs/core": "^2.11.2",
"@tailwindcss/line-clamp": "^0.3.1",
"@wordpress/is-shallow-equal": "^4.3.1",
Expand Down Expand Up @@ -77,6 +78,7 @@
"lodash.throttle": "^4.1.1",
"node-html-parser": "^5.1.0",
"nuxt": "^2.15.4",
"pinia": "^2.0.11",
"postcss-focus-visible": "^6.0.3",
"reakit-utils": "^0.15.2",
"seeded-rand": "^2.0.1",
Expand All @@ -92,6 +94,7 @@
"@nuxtjs/eslint-module": "^3.0.2",
"@nuxtjs/storybook": "^4.1.1",
"@nuxtjs/style-resources": "^1.0.0",
"@pinia/testing": "^0.0.9",
"@playwright/test": "^1.16.2",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/user-event": "^13.2.1",
Expand Down Expand Up @@ -120,6 +123,7 @@
"jest": "^26.6.3",
"jest-transform-stub": "^2.0.0",
"lint-staged": "^11.1.1",
"pinia": "^2.0.11",
"postcss": "^8.4.5",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
Expand Down
63 changes: 63 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions src/components/VAudioTrack/VAudioTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ import {

import { useActiveAudio } from '~/composables/use-active-audio'

import { ACTIVE, MEDIA } from '~/constants/store-modules'
import { MEDIA } from '~/constants/store-modules'

import {
PAUSE_ACTIVE_MEDIA_ITEM,
SET_ACTIVE_MEDIA_ITEM,
} from '~/constants/mutation-types'
import { useActiveMediaStore } from '~/store/active-media'

import VPlayPause from '~/components/VAudioTrack/VPlayPause.vue'
import VWaveform from '~/components/VAudioTrack/VWaveform.vue'
Expand Down Expand Up @@ -123,6 +120,7 @@ export default defineComponent({
},
props: propTypes,
setup(props, { emit }) {
const activeMediaStore = useActiveMediaStore()
const store = useStore()
const route = useRoute()

Expand Down Expand Up @@ -204,15 +202,15 @@ export default defineComponent({
const setPlaying = () => {
status.value = 'playing'
activeAudio.obj.value = localAudio
store.commit(`${ACTIVE}/${SET_ACTIVE_MEDIA_ITEM}`, {
activeMediaStore.setActiveMediaItem({
type: 'audio',
id: props.audio.id,
})
updateTimeLoop()
}
const setPaused = () => {
status.value = 'paused'
store.commit(`${ACTIVE}/${PAUSE_ACTIVE_MEDIA_ITEM}`)
activeMediaStore.pauseActiveMediaItem()
}
const setPlayed = () => (status.value = 'played')
const setTimeWhenPaused = () => {
Expand Down Expand Up @@ -252,7 +250,7 @@ export default defineComponent({
localAudio.removeEventListener('durationchange', setDuration)

if (
route.value.params.id == props.audio.id ||
route.value.params.id === props.audio.id ||
store.getters[`${MEDIA}/results`]?.items?.[props.audio.id]
) {
/**
Expand Down Expand Up @@ -301,7 +299,7 @@ export default defineComponent({
() => audioDuration.value ?? props.audio?.duration / 1e3 ?? 0 // seconds
)

const message = computed(() => store.state.active.message)
const message = computed(() => activeMediaStore.message)

/* Interface with VPlayPause */

Expand Down
15 changes: 5 additions & 10 deletions src/components/VAudioTrack/VGlobalAudioTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
</template>

<script>
import {
computed,
defineComponent,
ref,
useStore,
watch,
} from '@nuxtjs/composition-api'
import { computed, defineComponent, ref, watch } from '@nuxtjs/composition-api'

import { useActiveMediaStore } from '~/store/active-media'

import { useActiveAudio } from '~/composables/use-active-audio'

Expand Down Expand Up @@ -107,8 +103,7 @@ export default defineComponent({
* @param {import('@nuxtjs/composition-api').ExtractPropTypes<typeof propTypes>} props
*/
setup(props) {
const store = useStore()

const activeMediaStore = useActiveMediaStore()
const activeAudio = useActiveAudio()

const status = ref('paused')
Expand Down Expand Up @@ -200,7 +195,7 @@ export default defineComponent({
() => audioDuration.value ?? props.audio?.duration / 1e3 ?? 0
) // seconds

const message = computed(() => store.state.active.message)
const message = computed(() => activeMediaStore.message)

/* Interface with VPlayPause */

Expand Down
20 changes: 6 additions & 14 deletions src/components/VGlobalAudioSection/VGlobalAudioSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
<script>
import { useStore, useRoute, watch, computed } from '@nuxtjs/composition-api'

import { ACTIVE } from '~/constants/store-modules'
import {
SET_MESSAGE,
EJECT_ACTIVE_MEDIA_ITEM,
} from '~/constants/mutation-types'

import { useActiveAudio } from '~/composables/use-active-audio'
import { useActiveMediaStore } from '~/store/active-media'

import closeIcon from '~/assets/icons/close-small.svg'

export default {
name: 'VGlobalAudioSection',
setup() {
const activeMediaStore = useActiveMediaStore()
const store = useStore()
const route = useRoute()

Expand All @@ -34,7 +30,7 @@ export default {
/* Active audio track */

const audio = computed(() => {
const trackId = store.state.active.id
const trackId = activeMediaStore.id
if (trackId) {
return store.state.media.results.audio.items[trackId]
}
Expand All @@ -60,9 +56,7 @@ export default {
errorMsg = 'err_unsupported'
break
}
store.commit(`${ACTIVE}/${SET_MESSAGE}`, {
message: errorMsg,
})
activeMediaStore.setMessage({ message: errorMsg })
}

watch(
Expand All @@ -78,9 +72,7 @@ export default {
{ immediate: true }
)

const handleClose = () => {
store.commit(`${ACTIVE}/${EJECT_ACTIVE_MEDIA_ITEM}`)
}
const handleClose = activeMediaStore.ejectActiveMediaItem

/* Router observation */

Expand All @@ -91,7 +83,7 @@ export default {
!routeNameVal.includes('audio')
) {
activeAudio.obj.value?.pause()
store.commit(`${ACTIVE}/${EJECT_ACTIVE_MEDIA_ITEM}`)
activeMediaStore.ejectActiveMediaItem()
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/components/VNoticeBar/meta/NoticeBar.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Story,
} from '@storybook/addon-docs'

import NoticeBar from '@/components/VNoticeBar/VNoticeBar'
import NoticeBar from '~/components/VNoticeBar/VNoticeBar'

<Meta title="Components/Notice bar" component={NoticeBar} />

Expand Down
6 changes: 0 additions & 6 deletions src/constants/mutation-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ export const SET_MEDIA_ITEM = 'SET_MEDIA_ITEM'
export const SET_MEDIA_PROVIDERS = 'SET_MEDIA_PROVIDERS'
export const SET_PROVIDERS_FILTERS = 'SET_PROVIDERS_FILTERS'
export const SET_MEDIA = 'SET_MEDIA'
export const SET_EMBEDDED = 'SET_EMBEDDED'
export const SET_REFERRED = 'SET_REFERRED'
export const SET_SEARCH_TYPE = 'SET_SEARCH_TYPE'
export const CLEAR_OTHER_MEDIA_TYPE_FILTERS = 'CLEAR_OTHER_MEDIA_TYPE_FILTERS'
export const SET_ACTIVE_MEDIA_ITEM = 'SET_ACTIVE_MEDIA_ITEM'
export const PAUSE_ACTIVE_MEDIA_ITEM = 'PAUSE_ACTIVE_MEDIA_ITEM'
export const EJECT_ACTIVE_MEDIA_ITEM = 'EJECT_ACTIVE_MEDIA_ITEM'
export const SET_MESSAGE = 'SET_MESSAGE'
export const RESET_MEDIA = 'RESET_MEDIA'
export const REPLACE_FILTERS = 'REPLACE_FILTERS'
export const SET_QUERY = 'SET_QUERY'
2 changes: 0 additions & 2 deletions src/constants/store-modules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const RELATED = 'related'
export const ACTIVE = 'active'
export const PROVIDER = 'provider'
export const NAV = 'nav'
export const USAGE_DATA = 'usage-data'
export const SEARCH = 'search'
export const MEDIA = 'media'
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/blank.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</template>

<script>
import { defineComponent, useStore } from '@nuxtjs/composition-api'
import { computed, defineComponent } from '@nuxtjs/composition-api'

import iframeHeight from '~/mixins/iframe-height'

import { NAV } from '~/constants/store-modules'
import { useNav } from '~/store/nav'

import VTranslationStatusBanner from '~/components/VTranslationStatusBanner.vue'

Expand All @@ -22,8 +22,8 @@ export default defineComponent({
components: { VMigrationNotice, VTranslationStatusBanner },
mixins: [iframeHeight],
setup() {
const store = useStore()
const isReferredFromCc = store.state[NAV].isReferredFromCc
const navStore = useNav()
const isReferredFromCc = computed(() => navStore.isReferredFromCc)
return { isReferredFromCc }
},
head() {
Expand Down
Loading