Skip to content

Commit

Permalink
Use toRefs to preserve reactivity of props.audio
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Sep 5, 2023
1 parent b84cea0 commit 2219a4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</template>

<script lang="ts">
import { ref, onMounted, defineComponent, PropType } from "vue"
import { toRefs, ref, onMounted, defineComponent, PropType } from "vue"
import { rand, hash } from "~/utils/prng"
import { lerp, dist, bezier, Point } from "~/utils/math"
Expand All @@ -60,7 +60,8 @@ export default defineComponent({
},
},
setup(props) {
const { isHidden: shouldBlur } = useSensitiveMedia(props.audio)
const { audio } = toRefs(props)
const { isHidden: shouldBlur } = useSensitiveMedia(audio)
const i18n = useI18n()
const helpText = (
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/VAudioTrack/layouts/VGlobalLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</template>

<script lang="ts">
import { defineComponent, PropType } from "vue"
import { toRefs, defineComponent, PropType } from "vue"
import type { AudioDetail } from "~/types/media"
Expand All @@ -42,7 +42,8 @@ export default defineComponent({
},
},
setup(props) {
const { isHidden: shouldBlur } = useSensitiveMedia(props.audio)
const { audio } = toRefs(props)
const { isHidden: shouldBlur } = useSensitiveMedia(audio)
return {
shouldBlur,
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/composables/use-sensitive-media.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from "vue"
import { computed, unref, Ref } from "vue"

import type { Media } from "~/types/media"

Expand All @@ -7,14 +7,17 @@ import { useAnalytics } from "~/composables/use-analytics"

import type { SensitiveMediaVisibility } from "~/constants/content-safety"

type SensitiveFields = Pick<Media, "id" | "sensitivity" | "isSensitive">

/**
* A helper composable for working with sensitive media.
* Provides the current visibility of a sensitive media,
* along with toggles for hiding/revealing the media.
*/
export function useSensitiveMedia(
media: Pick<Media, "id" | "sensitivity" | "isSensitive"> | null
rawMedia: SensitiveFields | Ref<SensitiveFields> | null
) {
const media = unref(rawMedia)
const uiStore = useUiStore()
const { sendCustomEvent } = useAnalytics()

Expand Down

0 comments on commit 2219a4e

Please sign in to comment.