Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback on perform, without replacing perform #355

Open
osszoi opened this issue Mar 1, 2024 · 0 comments
Open

Callback on perform, without replacing perform #355

osszoi opened this issue Mar 1, 2024 · 0 comments

Comments

@osszoi
Copy link

osszoi commented Mar 1, 2024

Hi, I'm trying to implement kbar as a search through the app bar. The thing is I have many sections and I'd like to load items from section only when needed, I have this code that loads at start all Programs:

export const useCommandActions = () => {
  const navigate = useNavigate();

  const programs = createAction({
    name: 'Programas',
    // shortcut: ['p'],
    icon: <School />,
    section: 'Secciones'
  });

  const [actions, setActions] = useState([
    programs,
    createAction({
      name: 'Lista de programas',
      icon: <List />,
      section: 'Navegación',
      // shortcut: ['l'],
      parent: programs.id,
      perform: () => navigate(PATHS.ProgramsList)
    })
  ]);

  useEffect(() => {
    API.Program.getList({ page: 0, size: 9999 }).then((response) => {
      setActions((prev) => [
        ...prev,
        ...response.content.map(({ id, name, description, byCalendar }) =>
          createAction({
            name,
            subtitle: description,
            icon: !!byCalendar && <CalendarMonth />,
            keywords: `${name} ${id}`,
            section: 'Programas',
            perform: () => {
              navigate(PATHS.ProgramView.replace(':programId', id));
            },
            parent: programs.id
          })
        )
      ]);
    });
  }, []);

  useRegisterActions(actions, [actions]);
};

I'd like to load them ONLY when programs action is opened, but if I add perform to it I can load them but then I don't know how to go to the childs as it automatically do when I don't pass perform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant