@moises.ai/design-system 4.18.6 → 4.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moises.ai/design-system",
3
- "version": "4.18.6",
3
+ "version": "4.18.8",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import { Flex, Text, Spinner } from '@radix-ui/themes'
2
- import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
2
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'
3
3
  import { ArrowLeftIcon } from '../../../icons'
4
4
  import { ProjectsListContext } from '../context'
5
5
  import { NumberPicker } from '../../NumberPicker/NumberPicker'
@@ -7,6 +7,8 @@ import { UserIcon } from '../../../icons'
7
7
  import { Button } from '../../Button/Button'
8
8
  import styles from './ProjectTrackVoice.module.css'
9
9
 
10
+ const DEBOUNCE_MS = 3000
11
+
10
12
  const ProjectTrackVoice = ({
11
13
  ...props
12
14
  }) => {
@@ -20,31 +22,50 @@ const ProjectTrackVoice = ({
20
22
  const [pitchShiftSelected, setpitchShiftSelected] = useState(hasTransfers ? parseInt(transfers?.[0]?.pitchShift ?? 0) : 0)
21
23
 
22
24
  const [loading, setLoading] = useState(_loading)
25
+ const debounceRef = useRef(null)
26
+
27
+ useEffect(() => {
28
+ if (hasTransfers && !transfers.some((transfer) => parseInt(transfer.pitchShift) === pitchShiftSelected)) {
29
+ setLoading(true)
30
+ } else {
31
+ setLoading(false)
32
+ }
33
+ }, [pitchShiftSelected, transfers, hasTransfers])
23
34
 
24
35
  useEffect(() => {
25
36
  setLoading(_loading)
26
37
 
27
- if (!loading && hasTransfers) {
38
+ if (!_loading && hasTransfers) {
28
39
  setpitchShiftSelected(parseInt(transfers?.[0]?.pitchShift ?? 0))
29
40
  }
30
41
  }, [_loading, hasTransfers, transfers])
31
42
 
43
+ useEffect(() => {
44
+ return () => {
45
+ if (debounceRef.current) clearTimeout(debounceRef.current)
46
+ }
47
+ }, [])
48
+
32
49
  const getAudioUrl = useCallback((pitchShift) => {
33
50
  return hasTransfers ? transfers?.find((transfer) => parseInt(transfer.pitchShift) === pitchShift)?.audioUrl : audioUrl
34
51
  }, [hasTransfers, transfers, audioUrl])
35
52
 
36
53
  const handleChangeTransfer = useCallback((value) => {
37
54
  setpitchShiftSelected(value)
38
- const newAudioUrl = getAudioUrl(value)
39
- const project = projects.find((project) => project.id === projectId)
40
- onChangeTransfer?.(project, {
41
- id,
42
- title,
43
- audioUrl: newAudioUrl,
44
- processTrack: !newAudioUrl,
45
- pitchShift: value,
46
- })
47
- }, [onChangeTransfer, projectId, id, title, transfers])
55
+
56
+ if (debounceRef.current) clearTimeout(debounceRef.current)
57
+ debounceRef.current = setTimeout(() => {
58
+ const newAudioUrl = getAudioUrl(value)
59
+ const project = projects.find((project) => project.id === projectId)
60
+ onChangeTransfer?.(project, {
61
+ id,
62
+ title,
63
+ audioUrl: newAudioUrl,
64
+ processTrack: !newAudioUrl,
65
+ pitchShift: value,
66
+ })
67
+ }, DEBOUNCE_MS)
68
+ }, [onChangeTransfer, projectId, id, title, getAudioUrl, projects])
48
69
 
49
70
  const handleClickTrack = useCallback((e) => {
50
71
  e.stopPropagation()
@@ -100,16 +121,18 @@ const ProjectTrackVoice = ({
100
121
  </Text>
101
122
  </Flex>
102
123
 
124
+ {loading && (
125
+ <Flex align="center" justify="center" pl="2">
126
+ <Spinner />
127
+ </Flex>
128
+ )}
129
+
103
130
  {!hasTransfers && !audioUrl && !loading ? (
104
131
  <Flex align="center" justify="center" p="2">
105
132
  <Button variant="soft" color="gray" size="1">
106
133
  {labels.process || 'Process'}
107
134
  </Button>
108
135
  </Flex>
109
- ) : loading ? (
110
- <Flex align="center" justify="center" p="2">
111
- <Spinner />
112
- </Flex>
113
136
  ) : (
114
137
  <NumberPicker
115
138
  min={min}
@@ -262,7 +262,7 @@ export const WithTrackVoiceStates = {
262
262
  "type": "voice",
263
263
  "tracks": [
264
264
  {
265
- "id": "q8pzli0h38ptcx21q09h2al-0",
265
+ "id": "q8pzli0h38ptcx211133q09h2al-0",
266
266
  "title": "Joyce",
267
267
  "type": "voice",
268
268
  "loading": true,
@@ -273,6 +273,21 @@ export const WithTrackVoiceStates = {
273
273
  "type": "voice",
274
274
  "cover": "https://picsum.photos/101/101",
275
275
  "transfers": [],
276
+ },
277
+ {
278
+ "id": "q8pzli0h38ptcxq09h2al3-0",
279
+ "title": "Derek",
280
+ "type": "voice",
281
+ "cover": "https://picsum.photos/103/103",
282
+ "transfers": [{
283
+ "id": "q8pzli0h38ptcxq09h1122al",
284
+ "pitchShift": "12",
285
+ "audioUrl": "https://d3-stage.moises.ai/v3/download/moises-stage--tasks-us-east1/operations/VOICETRANSFER_A/0b926e1f-52ce-4581-9f76-09545eed1c61/vocals.m4"
286
+ }, {
287
+ "id": "q8pzli0h38ptcxq03339h2al2",
288
+ "pitchShift": "13",
289
+ "audioUrl": "https://d3-stage.moises.ai/v3/download/moises-stage--tasks-us-east1/operations/VOICETRANSFER_A/0a6c2a03-320e-49f2-9ea6-a5ad7bbb6141/vocals.m4a"
290
+ }],
276
291
  }
277
292
  ]
278
293
  }],