@moises.ai/design-system 4.18.8 → 4.18.10

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.10",
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, 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) {
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
 
@@ -128,19 +111,19 @@ const ProjectTrackVoice = ({
128
111
  )}
129
112
 
130
113
  {!hasTransfers && !audioUrl && !loading ? (
131
- <Flex align="center" justify="center" p="2">
114
+ <Flex align="center" justify="center" pr="2">
132
115
  <Button variant="soft" color="gray" size="1">
133
116
  {labels.process || 'Process'}
134
117
  </Button>
135
118
  </Flex>
136
- ) : (
119
+ ) : hasTransfers ? (
137
120
  <NumberPicker
138
121
  min={min}
139
122
  max={max}
140
123
  value={pitchShiftSelected}
141
124
  onChange={handleChangeTransfer}
142
125
  />
143
- )}
126
+ ) : null}
144
127
  </Flex>
145
128
  </Flex>
146
129
  )