saving prompt configs works

This commit is contained in:
Kyle Corbitt
2023-06-23 12:18:09 -07:00
parent a31c112745
commit ca78406ad1
13 changed files with 291 additions and 61 deletions

View File

@@ -1,4 +1,5 @@
import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";
import { api } from "~/utils/api";
export const useExperiment = () => {
@@ -10,3 +11,37 @@ export const useExperiment = () => {
return experiment;
};
export function useHandledAsyncCallback<T extends (...args: any[]) => Promise<any>>(
callback: T,
deps: React.DependencyList
) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<Error | null>(null);
const wrappedCallback = useCallback((...args: Parameters<T>) => {
setLoading(true);
setError(null);
callback(...args)
.catch((error) => {
setError(error as Error);
console.error(error);
})
.finally(() => {
setLoading(false);
});
}, deps);
return [wrappedCallback, loading, error] as const;
}
// Have to do this ugly thing to convince Next not to try to access `navigator`
// on the server side at build time, when it isn't defined.
export const useModifierKeyLabel = () => {
const [label, setLabel] = useState("");
useEffect(() => {
setLabel(navigator?.platform?.startsWith("Mac") ? "⌘" : "Ctrl");
}, []);
return label;
};