Finished websocket implementation

This commit is contained in:
Koper
2023-08-09 19:38:46 +07:00
parent bc4a952938
commit 1aa77040ef
4 changed files with 59 additions and 72 deletions

View File

@@ -3,7 +3,7 @@ import axios from "axios";
const API_URL = process.env.NEXT_PUBLIC_API_URL;
const useCreateTranscript = () => {
const useTranscript = () => {
const [response, setResponse] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
@@ -15,29 +15,31 @@ const useCreateTranscript = () => {
name: "Weekly All-Hands", // Hardcoded for now
};
console.log("Sending POST:", data);
console.debug(
"POST - /v1/transcripts/ - Requesting new transcription creation",
data,
);
axios
.post(url, data)
.then((result) => {
setResponse(result.data);
setLoading(false);
console.log("Response:", result.data);
console.debug("New transcript created:", result.data);
})
.catch((err) => {
setError(err.response || err);
const errorString = err.response || err || "Unknown error";
setError(eerrorString);
setLoading(false);
alert("Error: " + (err.response || err));
console.log("Error occurred:", err.response || err); // Debugging line
console.error("Error creating transcript:", errorString);
});
};
// You can choose when to call createTranscript, e.g., based on some dependencies
useEffect(() => {
createTranscript();
}, []); // Empty dependencies array means this effect will run once on mount
}, []);
return { response, loading, error, createTranscript };
};
export default useCreateTranscript;
export default useTranscript;