Skip to content

Commit ecc8443

Browse files
committed
I never sleep, 'cause sleep is the cousin of death
1 parent e92516a commit ecc8443

File tree

3 files changed

+183
-6
lines changed

3 files changed

+183
-6
lines changed

src/components/button.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
//for footer navigation
2-
3-
interface props {
4-
children: string
1+
import { ReactNode } from 'react'
2+
type ButtonProps = {
3+
children: ReactNode
54
type: 'primary' | 'landing'
65
submit?: boolean
76
}
87

9-
const Button = ({ children, type, submit }: props) => {
8+
const Button: React.FunctionComponent<ButtonProps> = ({
9+
children,
10+
type,
11+
submit,
12+
}) => {
1013
const buttonVariant = {
1114
primary:
1215
'duration-200 bg-primary-green hover:bg-dark-green font-bold py-3 px-8 rounded-full overflow-clip',
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// All credit goes to https://github.com/davidhu2000/react-spinners
2+
// This is copied from the react-spinners package directly
3+
4+
import { CSSProperties, DetailedHTMLProps, HTMLAttributes } from 'react'
5+
6+
interface CommonProps
7+
extends DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
8+
color?: string
9+
loading?: boolean
10+
cssOverride?: CSSProperties
11+
speedMultiplier?: number
12+
}
13+
export type LengthType = number | string
14+
export interface LoaderSizeMarginProps extends CommonProps {
15+
size?: LengthType
16+
margin?: LengthType
17+
}
18+
19+
export function cssValue(value: number | string): string {
20+
const lengthWithunit = parseLengthAndUnit(value)
21+
22+
return `${lengthWithunit.value}${lengthWithunit.unit}`
23+
}
24+
25+
export const createAnimation = (
26+
loaderName: string,
27+
frames: string,
28+
suffix: string,
29+
): string => {
30+
const animationName = `react-spinners-${loaderName}-${suffix}`
31+
32+
if (typeof window == 'undefined' || !window.document) {
33+
return animationName
34+
}
35+
36+
const styleEl = document.createElement('style')
37+
document.head.appendChild(styleEl)
38+
const styleSheet = styleEl.sheet
39+
40+
const keyFrames = `
41+
@keyframes ${animationName} {
42+
${frames}
43+
}
44+
`
45+
46+
if (styleSheet) {
47+
styleSheet.insertRule(keyFrames, 0)
48+
}
49+
50+
return animationName
51+
}
52+
const cssUnit: { [unit: string]: boolean } = {
53+
cm: true,
54+
mm: true,
55+
in: true,
56+
px: true,
57+
pt: true,
58+
pc: true,
59+
em: true,
60+
ex: true,
61+
ch: true,
62+
rem: true,
63+
vw: true,
64+
vh: true,
65+
vmin: true,
66+
vmax: true,
67+
'%': true,
68+
}
69+
interface LengthObject {
70+
value: number
71+
unit: string
72+
}
73+
export function parseLengthAndUnit(size: number | string): LengthObject {
74+
if (typeof size === 'number') {
75+
return {
76+
value: size,
77+
unit: 'px',
78+
}
79+
}
80+
let value: number
81+
const valueString: string = (size.match(/^[0-9.]*/) || '').toString()
82+
if (valueString.includes('.')) {
83+
value = parseFloat(valueString)
84+
} else {
85+
value = parseInt(valueString, 10)
86+
}
87+
88+
const unit: string = (size.match(/[^0-9]*$/) || '').toString()
89+
90+
if (cssUnit[unit]) {
91+
return {
92+
value,
93+
unit,
94+
}
95+
}
96+
97+
console.warn(
98+
`React Spinners: ${size} is not a valid css value. Defaulting to ${value}px.`,
99+
)
100+
101+
return {
102+
value,
103+
unit: 'px',
104+
}
105+
}
106+
107+
const sync = createAnimation(
108+
'SyncLoader',
109+
`33% {transform: translateY(10px)}
110+
66% {transform: translateY(-10px)}
111+
100% {transform: translateY(0)}`,
112+
'sync',
113+
)
114+
115+
function SyncLoader({
116+
loading = true,
117+
color = '#000000',
118+
speedMultiplier = 1,
119+
cssOverride = {},
120+
size = 15,
121+
margin = 2,
122+
...additionalprops
123+
}: LoaderSizeMarginProps): JSX.Element | null {
124+
const wrapper: React.CSSProperties = {
125+
display: 'inherit',
126+
...cssOverride,
127+
}
128+
129+
const style = (i: number): React.CSSProperties => {
130+
return {
131+
backgroundColor: color,
132+
width: cssValue(size),
133+
height: cssValue(size),
134+
margin: cssValue(margin),
135+
borderRadius: '100%',
136+
display: 'inline-block',
137+
animation: `${sync} ${0.6 / speedMultiplier}s ${
138+
i * 0.07
139+
}s infinite ease-in-out`,
140+
animationFillMode: 'both',
141+
}
142+
}
143+
144+
if (!loading) {
145+
return null
146+
}
147+
148+
return (
149+
<span style={wrapper} {...additionalprops}>
150+
<span style={style(1)} />
151+
<span style={style(2)} />
152+
<span style={style(3)} />
153+
</span>
154+
)
155+
}
156+
157+
export default SyncLoader

src/pages/upload/upload.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Button from '../../components/button'
66
import DropdownKey, { Key } from './upload-dropdown-keys'
77
import { Tag, TagsAutoComplete } from './upload-tags-autocomplete'
88

9+
import { useNavigate } from 'react-router-dom'
10+
import RotateLoader from '../../components/loader/rotate-loader'
911
import { UploadInput } from './upload-input'
1012

1113
type UploadModalProps = {
@@ -36,6 +38,8 @@ export default function UploadModal({
3638
const [key, setKey] = useState<Key['name']>('C')
3739
const [keyScale, setKeyScale] = useState<'major' | 'minor'>('major')
3840

41+
const navigate = useNavigate()
42+
3943
const {
4044
register,
4145
handleSubmit,
@@ -62,13 +66,15 @@ export default function UploadModal({
6266
setImage(null)
6367
setImagePreview('')
6468
setAudio(null)
69+
navigate('/artist-dashboard')
6570
}
6671

6772
function openModal() {
6873
setIsUpload(true)
6974
}
7075

7176
const onSubmit = handleSubmit(async (data) => {
77+
setLoading(true)
7278
await uploadSample({
7379
name: data.title,
7480
bpm: data.bpm,
@@ -78,6 +84,10 @@ export default function UploadModal({
7884
audioFile: audio,
7985
coverFile: image,
8086
tagIds: selectedTags?.map((tag) => tag.id) || [],
87+
}).then((res) => {
88+
console.log(res)
89+
setLoading(false)
90+
closeModal()
8191
})
8292
})
8393

@@ -303,7 +313,14 @@ export default function UploadModal({
303313
Cancel
304314
</button>
305315
<Button type="primary" submit>
306-
Upload
316+
{loading && (
317+
<RotateLoader
318+
margin="1px"
319+
size="10px"
320+
color="#FAF9F6"
321+
/>
322+
)}
323+
{!loading && 'Upload'}
307324
</Button>
308325
</div>
309326
</div>

0 commit comments

Comments
 (0)