-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
137 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { enableIndex, getIndexByName } from '@/core/repositories/index_'; | ||
import { defineHandler } from '@/lib/next/handler'; | ||
import { notFound } from 'next/navigation'; | ||
import { z } from 'zod'; | ||
|
||
export const POST = defineHandler({ | ||
auth: 'admin', | ||
params: z.object({ | ||
name: z.string(), | ||
}), | ||
}, async ({ params }) => { | ||
const index = await getIndexByName(params.name); | ||
if (!index) { | ||
notFound(); | ||
} | ||
await enableIndex(index.id); | ||
}); | ||
|
||
export const dynamic = 'force-dynamic'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
export function useOperation<T extends any[], R> (operation: (...args: T) => Promise<R>) { | ||
const [operating, setOperating] = useState(false); | ||
const [result, setResult] = useState<R>(); | ||
const [error, setError] = useState<unknown>(); | ||
|
||
const operationRef = useRef(operation); | ||
useEffect(() => { | ||
operationRef.current = operation; | ||
}); | ||
|
||
const operatingRef = useRef(operating); | ||
operatingRef.current = operating; | ||
|
||
const operate = (...args: T) => { | ||
if (operatingRef.current) { | ||
return Promise.reject<R>('Operation is running'); | ||
} | ||
setOperating(true); | ||
setResult(undefined); | ||
setError(undefined); | ||
return operationRef.current(...args) | ||
.then(result => { | ||
setResult(result); | ||
return result; | ||
}, error => { | ||
setError(error); | ||
return Promise.reject(error); | ||
}) | ||
.finally(() => { | ||
setOperating(false); | ||
}); | ||
}; | ||
|
||
return { | ||
operate, | ||
operating, | ||
error, | ||
result, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters