@moises.ai/design-system 4.18.8 → 4.18.11

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.8",
3
+ "version": "4.18.11",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -53,7 +53,8 @@ const ProjectItem = ({
53
53
 
54
54
  const handleInsertAllTracks = useCallback((e) => {
55
55
  e.stopPropagation()
56
- onInsertAllTracks?.(allTracks)
56
+ const tracksFiltered = allTracks.filter((track) => !track.loading && track.transfers.length > 0)
57
+ onInsertAllTracks?.(tracksFiltered)
57
58
  }, [onInsertAllTracks, allTracks])
58
59
 
59
60
  return (
@@ -100,7 +101,7 @@ const ProjectItem = ({
100
101
 
101
102
  {openedItem === id && (
102
103
  <Flex direction="column">
103
- {allTracks.length === 0 && !loading && (
104
+ {type !== 'voice' && allTracks.length === 0 && !loading && (
104
105
  <Flex direction="row" gap="3" p="5" pt="2" align="center" justify="center">
105
106
  <NoMusicIcon width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
106
107
  <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>{labels.noTracks || 'This file has no tracks'}</Text>
@@ -1,5 +1,5 @@
1
1
  import { Flex, Text, Spinner } from '@radix-ui/themes'
2
- import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'
2
+ import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
3
3
  import { ArrowLeftIcon } from '../../../icons'
4
4
  import { ProjectsListContext } from '../context'
5
5
  import { NumberPicker } from '../../NumberPicker/NumberPicker'
@@ -7,11 +7,7 @@ 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
-
12
- const ProjectTrackVoice = ({
13
- ...props
14
- }) => {
10
+ const ProjectTrackVoice = ({ ...props }) => {
15
11
  const { onClickTrack, onChangeTransfer, projects, labels = {} } = useContext(ProjectsListContext)
16
12
  const { projectId, id, title, cover, transfers, audioUrl, loading: _loading } = props
17
13
 
@@ -19,32 +15,29 @@ const ProjectTrackVoice = ({
19
15
 
20
16
  const max = 24
21
17
  const min = -24
22
- const [pitchShiftSelected, setpitchShiftSelected] = useState(hasTransfers ? parseInt(transfers?.[0]?.pitchShift ?? 0) : 0)
23
-
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])
18
+ const [pitchShiftSelected, setpitchShiftSelected] = useState(null)
34
19
 
35
20
  useEffect(() => {
36
- setLoading(_loading)
37
-
38
- if (!_loading && hasTransfers) {
21
+ if (hasTransfers && pitchShiftSelected === null) {
39
22
  setpitchShiftSelected(parseInt(transfers?.[0]?.pitchShift ?? 0))
40
23
  }
41
- }, [_loading, hasTransfers, transfers])
24
+ }, [hasTransfers, pitchShiftSelected])
25
+
26
+ const loading = useMemo(() => {
27
+ if (
28
+ (!hasTransfers && _loading) ||
29
+ (hasTransfers && pitchShiftSelected === null)
30
+ ) {
31
+ return true
32
+ }
42
33
 
43
- useEffect(() => {
44
- return () => {
45
- if (debounceRef.current) clearTimeout(debounceRef.current)
34
+ if (pitchShiftSelected !== null) {
35
+ const currentTransfer = transfers.find((transfer) => parseInt(transfer.pitchShift) === pitchShiftSelected)
36
+ return currentTransfer?.loading === true || !currentTransfer?.audioUrl
46
37
  }
47
- }, [])
38
+
39
+ return false
40
+ }, [_loading, hasTransfers, pitchShiftSelected, transfers])
48
41
 
49
42
  const getAudioUrl = useCallback((pitchShift) => {
50
43
  return hasTransfers ? transfers?.find((transfer) => parseInt(transfer.pitchShift) === pitchShift)?.audioUrl : audioUrl
@@ -52,20 +45,16 @@ const ProjectTrackVoice = ({
52
45
 
53
46
  const handleChangeTransfer = useCallback((value) => {
54
47
  setpitchShiftSelected(value)
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
+ const newAudioUrl = getAudioUrl(value)
49
+ const project = projects.find((project) => project.id === projectId)
50
+ onChangeTransfer?.(project, {
51
+ id,
52
+ title,
53
+ audioUrl: newAudioUrl,
54
+ processTrack: !newAudioUrl,
55
+ pitchShift: value,
56
+ })
57
+ }, [onChangeTransfer, projectId, id, title, transfers])
69
58
 
70
59
  const handleClickTrack = useCallback((e) => {
71
60
  e.stopPropagation()
@@ -74,18 +63,12 @@ const ProjectTrackVoice = ({
74
63
  return
75
64
  }
76
65
 
77
- const processTrack = (!hasTransfers && !audioUrl)
78
-
79
- if (processTrack) {
80
- setLoading(true)
81
- }
82
-
83
66
  onClickTrack?.({
84
67
  ...props,
85
68
  id,
86
69
  title,
87
70
  audioUrl: hasTransfers || audioUrl ? getAudioUrl(pitchShiftSelected) : null,
88
- processTrack,
71
+ processTrack: !hasTransfers && !audioUrl,
89
72
  })
90
73
  }, [onClickTrack, props, id, title, getAudioUrl, pitchShiftSelected, hasTransfers, loading, audioUrl])
91
74
 
@@ -121,26 +104,34 @@ const ProjectTrackVoice = ({
121
104
  </Text>
122
105
  </Flex>
123
106
 
124
- {loading && (
107
+ {(hasTransfers || audioUrl) && loading && (
125
108
  <Flex align="center" justify="center" pl="2">
126
109
  <Spinner />
127
110
  </Flex>
128
111
  )}
129
112
 
130
- {!hasTransfers && !audioUrl && !loading ? (
131
- <Flex align="center" justify="center" p="2">
132
- <Button variant="soft" color="gray" size="1">
113
+ {!hasTransfers && !audioUrl ? (
114
+ <Flex align="center" justify="center" pr="2" pr="0">
115
+ <Button
116
+ variant="soft"
117
+ color="gray"
118
+ size="1"
119
+ disabled={loading}
120
+ loading={loading}
121
+ onClick={handleClickTrack}
122
+ style={{ minWidth: '63px' }}
123
+ >
133
124
  {labels.process || 'Process'}
134
125
  </Button>
135
126
  </Flex>
136
- ) : (
127
+ ) : hasTransfers ? (
137
128
  <NumberPicker
138
129
  min={min}
139
130
  max={max}
140
131
  value={pitchShiftSelected}
141
132
  onChange={handleChangeTransfer}
142
133
  />
143
- )}
134
+ ) : null}
144
135
  </Flex>
145
136
  </Flex>
146
137
  )
@@ -261,6 +261,13 @@ export const WithTrackVoiceStates = {
261
261
  "duration": 30.72,
262
262
  "type": "voice",
263
263
  "tracks": [
264
+ {
265
+ "id": "q8pzli0h38ptcxq09h2al-0",
266
+ "title": "Ana",
267
+ "type": "voice",
268
+ "cover": "https://picsum.photos/101/101",
269
+ "transfers": [],
270
+ },
264
271
  {
265
272
  "id": "q8pzli0h38ptcx211133q09h2al-0",
266
273
  "title": "Joyce",
@@ -268,11 +275,15 @@ export const WithTrackVoiceStates = {
268
275
  "loading": true,
269
276
  },
270
277
  {
271
- "id": "q8pzli0h38ptcxq09h2al-0",
272
- "title": "Ana",
278
+ "id": "q8pzli0h38ptcx211133q09h2al-0",
279
+ "title": "Carlos",
273
280
  "type": "voice",
274
- "cover": "https://picsum.photos/101/101",
275
- "transfers": [],
281
+ "loading": true,
282
+ "transfers": [{
283
+ "id": "q8pzli0h38ptcxq09h1122al",
284
+ "pitchShift": "12",
285
+ "audioUrl": null
286
+ }],
276
287
  },
277
288
  {
278
289
  "id": "q8pzli0h38ptcxq09h2al3-0",
@@ -288,6 +299,21 @@ export const WithTrackVoiceStates = {
288
299
  "pitchShift": "13",
289
300
  "audioUrl": "https://d3-stage.moises.ai/v3/download/moises-stage--tasks-us-east1/operations/VOICETRANSFER_A/0a6c2a03-320e-49f2-9ea6-a5ad7bbb6141/vocals.m4a"
290
301
  }],
302
+ },
303
+ {
304
+ "id": "q8pzli0h38ptcxq09h2al3-0",
305
+ "title": "Claudia",
306
+ "type": "voice",
307
+ "cover": "https://picsum.photos/105/105",
308
+ "transfers": [{
309
+ "id": "q8pzli0h38ptcxq09h1122al",
310
+ "pitchShift": "1",
311
+ "audioUrl": "https://d3-stage.moises.ai/v3/download/moises-stage--tasks-us-east1/operations/VOICETRANSFER_A/0b926e1f-52ce-4581-9f76-09545eed1c61/vocals.m4"
312
+ }, {
313
+ "id": "q8pzli0h38ptcxq03339h2al2",
314
+ "pitchShift": "2",
315
+ "audioUrl": null
316
+ }],
291
317
  }
292
318
  ]
293
319
  }],