mirror of
https://github.com/wassname/talk.git
synced 2026-08-04 13:23:35 +08:00
[CORL-294] Moderate a single story + quick search (#2286)
* feat: allow passing a `storyID` to `Query.moderationQueues` * feat: moderate by story * feat: implement search story combobox * feat: add translations * fix: tests * fix: duplicate id * fix: rename file * chore: add more comments * fix: add missing translation * review: use query parameter "q" instead of url path * chore: move placeholder logic inside, maybe this makes it clearer :-D
This commit is contained in:
@@ -1 +1,3 @@
|
||||
export { default as useEffectAfterMount } from "./useEffectAfterMount";
|
||||
export { default as usePrevious } from "./usePrevious";
|
||||
export { default as useEffectWhenChanged } from "./useEffectWhenChanged";
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import equals from "shallow-equals";
|
||||
|
||||
import useEffectAfterMount from "./useEffectAfterMount";
|
||||
import usePrevious from "./usePrevious";
|
||||
|
||||
/**
|
||||
* useEffectWhenChanged is a react hook that will run effects
|
||||
* when value changed.
|
||||
*/
|
||||
export default function useEffectWhenChanged(
|
||||
callback: () => void,
|
||||
deps: ReadonlyArray<any>
|
||||
) {
|
||||
const previous = usePrevious(deps);
|
||||
// We use `useEffectAfterMount` to make sure `previous` has an assigned value.
|
||||
useEffectAfterMount(() => {
|
||||
if (!equals(deps, previous)) {
|
||||
callback();
|
||||
}
|
||||
}, deps);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
/**
|
||||
* usePrevious is a react hook that will return the
|
||||
* previous value.
|
||||
*/
|
||||
export default function usePrevious<T>(value: T): T {
|
||||
const ref = useRef<T>();
|
||||
useEffect(() => {
|
||||
ref.current = value;
|
||||
});
|
||||
return ref.current as T;
|
||||
}
|
||||
Reference in New Issue
Block a user