Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

600 B
Raw Blame
import type { UserClient } from "~~/lib/api/user";

export function itemsTable(api: UserClient) {
  const { data: items, refresh } = useAsyncData(
    "items",
    async () => {
      const { data } = await api.items.getAll({
        page: 1,
        pageSize: 5,
        orderBy: "createdAt",
        orderDirection: "desc",
      });
      return data.items;
    },
    {
      deep: true,
    }
  );

  onServerEvent(ServerEvent.EntityMutation, () => {
    console.log("entity mutation");
    refresh();
  });

  return computed(() => {
    return {
      items: items.value || [],
    };
  });
}