mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-21 16:00:49 +00:00
25 lines
814 B
Go
25 lines
814 B
Go
import { storeToRefs } from 'pinia';
|
|
import { onActivated, onDeactivated } from 'vue';
|
|
import GlobalStore from '@/store/modules/global';
|
|
import { bindSearchReset, type SearchFields } from '@/utils/search-reset';
|
|
|
|
interface SearchResetOptions {
|
|
scope?: () => string | number | undefined;
|
|
onRevisit: () => unknown;
|
|
}
|
|
|
|
export const useSearchReset = (fields: SearchFields, options: SearchResetOptions) => {
|
|
const { currentNode } = storeToRefs(GlobalStore());
|
|
const reset = bindSearchReset(options.scope ? [currentNode, options.scope] : [currentNode], fields);
|
|
let deactivated = false;
|
|
onDeactivated(() => {
|
|
deactivated = true;
|
|
});
|
|
onActivated(() => {
|
|
if (!deactivated) return;
|
|
deactivated = false;
|
|
reset();
|
|
return options.onRevisit();
|
|
});
|
|
};
|