Spaces:
Sleeping
Sleeping
Download frontend/src/hooks/useSession.js from MusoraProductDepartment/jam-tracks: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/MusoraProductDepartment/jam-tracks/resolve/main/frontend/src/hooks/useSession.js
- Command line
-
hf download hf://spaces/MusoraProductDepartment/jam-tracks/frontend/src/hooks/useSession.js
-
curl -L -o useSession.js https://huggingface.co/spaces/MusoraProductDepartment/jam-tracks/resolve/main/frontend/src/hooks/useSession.js
1.42 kB
| import { useState, useCallback } from 'react' | |
| import { | |
| getPresetManifestEntry, | |
| presetToChordsData, | |
| presetToUploadData | |
| } from '../utils/presetManifest' | |
| export function useSession() { | |
| const [sessionId, setSessionId] = useState(null) | |
| const [stems, setStems] = useState([]) | |
| const [detection, setDetection] = useState(null) | |
| const [chordsData, setChordsData] = useState(null) | |
| const [loading, setLoading] = useState(false) | |
| const [error, setError] = useState(null) | |
| const clearError = useCallback(() => { | |
| setError(null) | |
| }, []) | |
| const loadPreset = useCallback(async (presetName) => { | |
| setLoading(true) | |
| setError(null) | |
| try { | |
| const preset = await getPresetManifestEntry(presetName) | |
| if (!preset) { | |
| throw new Error(`Preset '${presetName}' is missing from the manifest.`) | |
| } | |
| const localSessionId = `preset:${presetName}` | |
| const uploadData = presetToUploadData(preset, localSessionId) | |
| setSessionId(localSessionId) | |
| setStems(uploadData.stems) | |
| setDetection(preset.detection) | |
| setChordsData(presetToChordsData(preset)) | |
| return { upload: uploadData, detection: preset.detection } | |
| } catch (err) { | |
| setError(err.message) | |
| return null | |
| } finally { | |
| setLoading(false) | |
| } | |
| }, []) | |
| return { | |
| sessionId, | |
| stems, | |
| detection, | |
| chordsData, | |
| loading, | |
| error, | |
| loadPreset, | |
| clearError | |
| } | |
| } | |