@moises.ai/design-system 4.18.5 → 4.18.7

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.5",
3
+ "version": "4.18.7",
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,11 +7,13 @@ 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
  }) => {
13
- const { onClickTrack } = useContext(ProjectsListContext)
14
- const { projectId, id, title, cover, transfers, audioUrl, onChangeTransfer, loading: _loading } = props
15
+ const { onClickTrack, onChangeTransfer, projects, labels = {} } = useContext(ProjectsListContext)
16
+ const { projectId, id, title, cover, transfers, audioUrl, loading: _loading } = props
15
17
 
16
18
  const hasTransfers = useMemo(() => transfers && transfers.length > 0, [transfers])
17
19
 
@@ -20,30 +22,42 @@ 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)
23
26
 
24
27
  useEffect(() => {
25
28
  setLoading(_loading)
26
29
 
27
- if (!loading && hasTransfers) {
30
+ if (!_loading && hasTransfers) {
28
31
  setpitchShiftSelected(parseInt(transfers?.[0]?.pitchShift ?? 0))
29
32
  }
30
33
  }, [_loading, hasTransfers, transfers])
31
34
 
35
+ useEffect(() => {
36
+ return () => {
37
+ if (debounceRef.current) clearTimeout(debounceRef.current)
38
+ }
39
+ }, [])
40
+
32
41
  const getAudioUrl = useCallback((pitchShift) => {
33
42
  return hasTransfers ? transfers?.find((transfer) => parseInt(transfer.pitchShift) === pitchShift)?.audioUrl : audioUrl
34
43
  }, [hasTransfers, transfers, audioUrl])
35
44
 
36
45
  const handleChangeTransfer = useCallback((value) => {
37
46
  setpitchShiftSelected(value)
38
- const newAudioUrl = getAudioUrl(value)
39
- onChangeTransfer?.(projectId, {
40
- id,
41
- title,
42
- audioUrl: newAudioUrl,
43
- processTrack: !newAudioUrl,
44
- pitchShift: value,
45
- })
46
- }, [onChangeTransfer, projectId, id, title, transfers])
47
+
48
+ if (debounceRef.current) clearTimeout(debounceRef.current)
49
+ debounceRef.current = setTimeout(() => {
50
+ const newAudioUrl = getAudioUrl(value)
51
+ const project = projects.find((project) => project.id === projectId)
52
+ onChangeTransfer?.(project, {
53
+ id,
54
+ title,
55
+ audioUrl: newAudioUrl,
56
+ processTrack: !newAudioUrl,
57
+ pitchShift: value,
58
+ })
59
+ }, DEBOUNCE_MS)
60
+ }, [onChangeTransfer, projectId, id, title, getAudioUrl, projects])
47
61
 
48
62
  const handleClickTrack = useCallback((e) => {
49
63
  e.stopPropagation()
@@ -99,16 +113,18 @@ const ProjectTrackVoice = ({
99
113
  </Text>
100
114
  </Flex>
101
115
 
116
+ {loading && (
117
+ <Flex align="center" justify="center" pl="2">
118
+ <Spinner />
119
+ </Flex>
120
+ )}
121
+
102
122
  {!hasTransfers && !audioUrl && !loading ? (
103
123
  <Flex align="center" justify="center" p="2">
104
124
  <Button variant="soft" color="gray" size="1">
105
- Process
125
+ {labels.process || 'Process'}
106
126
  </Button>
107
127
  </Flex>
108
- ) : loading ? (
109
- <Flex align="center" justify="center" p="2">
110
- <Spinner />
111
- </Flex>
112
128
  ) : (
113
129
  <NumberPicker
114
130
  min={min}
@@ -11,6 +11,7 @@ export const ProjectsList = ({
11
11
  onClickTrack,
12
12
  onInsertAllTracks,
13
13
  onProjectClick,
14
+ onChangeTransfer,
14
15
  labels = {}
15
16
  }) => {
16
17
  const [openedItem, setOpenedItem] = useState(null)
@@ -22,8 +23,10 @@ export const ProjectsList = ({
22
23
  onClickTrack,
23
24
  onInsertAllTracks,
24
25
  onProjectClick,
26
+ onChangeTransfer,
25
27
  openedItem,
26
28
  setOpenedItem,
29
+ labels,
27
30
  }}
28
31
  >
29
32
  <Flex direction="column" width="100%">
@@ -222,8 +222,8 @@ export const WithTrackVoice = {
222
222
  onInsertAllTracks: (tracks) => {
223
223
  console.log('insert-all-tracks', tracks)
224
224
  },
225
- onChangeTransfer: (projectId, track) => {
226
- console.log('change-transfer', projectId, track)
225
+ onChangeTransfer: (project, track) => {
226
+ console.log('change-transfer', project, track)
227
227
  },
228
228
  },
229
229
  render: (args) => {
@@ -234,6 +234,7 @@ export const WithTrackVoice = {
234
234
  onClickTrack={args.onClickTrack}
235
235
  onInsertAllTracks={args.onInsertAllTracks}
236
236
  onProjectClick={args.onProjectClick}
237
+ onChangeTransfer={args.onChangeTransfer}
237
238
  >
238
239
  {({ projectId, tracks }) =>
239
240
  tracks.map((track) => (
@@ -241,7 +242,6 @@ export const WithTrackVoice = {
241
242
  projectId={projectId}
242
243
  key={track.id}
243
244
  {...track}
244
- onChangeTransfer={args.onChangeTransfer}
245
245
  />
246
246
  ))
247
247
  }
@@ -286,8 +286,8 @@ export const WithTrackVoiceStates = {
286
286
  onInsertAllTracks: (tracks) => {
287
287
  console.log('insert-all-tracks', tracks)
288
288
  },
289
- onChangeTransfer: (projectId, track) => {
290
- console.log('change-transfer', projectId, track)
289
+ onChangeTransfer: (project, track) => {
290
+ console.log('change-transfer', project, track)
291
291
  },
292
292
  },
293
293
  render: (args) => {
@@ -298,6 +298,7 @@ export const WithTrackVoiceStates = {
298
298
  onClickTrack={args.onClickTrack}
299
299
  onInsertAllTracks={args.onInsertAllTracks}
300
300
  onProjectClick={args.onProjectClick}
301
+ onChangeTransfer={args.onChangeTransfer}
301
302
  >
302
303
  {({ projectId, tracks }) =>
303
304
  tracks.map((track) => (
@@ -305,7 +306,6 @@ export const WithTrackVoiceStates = {
305
306
  projectId={projectId}
306
307
  key={track.id}
307
308
  {...track}
308
- onChangeTransfer={args.onChangeTransfer}
309
309
  />
310
310
  ))
311
311
  }
@@ -5,6 +5,8 @@ export const ProjectsListContext = createContext({
5
5
  onClickTrack: null,
6
6
  onInsertAllTracks: null,
7
7
  onProjectClick: null,
8
+ onChangeTransfer: null,
8
9
  openedItem: null,
9
10
  setOpenedItem: () => { },
11
+ labels: {},
10
12
  })