IKHSAN
EN Read in EnglishID

homeio

Publik

Fork dari doctor-io/homeio

Branch
main
Commit terakhir
958d74616 Oktober 2026

StoreActionsContext.tsx

Buka raw
"use client";

/**
 * Single shared instance of useStoreActions for the entire desktop shell.
 *
 * Problem solved: AppStore, AppGrid (controller), AppConfiguratorPanel all called
 * useStoreActions() independently, creating 3-4 separate React state instances.
 * This meant:
 *   - Progress banner in the grid never showed for App Store installs/uninstalls
 *   - App didn't appear as "updating" in the grid during App Store operations
 *   - operationsByApp was not shared → no coordination between windows
 *
 * Solution: Wrap the desktop shell content in <StoreActionsProvider> once.
 * All child components call useSharedStoreActions() to get the same instance.
 */

import { createContext, useContext, type ReactNode } from "react";
import { useStoreActions, type StoreActionsHandle } from "./useStoreActions";

const StoreActionsContext = createContext<StoreActionsHandle | null>(null);

export function StoreActionsProvider({ children }: { children: ReactNode }) {
  const actions = useStoreActions();
  return (
    <StoreActionsContext.Provider value={actions}>
      {children}
    </StoreActionsContext.Provider>
  );
}

export function useSharedStoreActions(): StoreActionsHandle {
  const ctx = useContext(StoreActionsContext);
  const fallbackActions = useStoreActions();
  return ctx ?? fallbackActions;
}
byte
1.324
baris
36
Jenis
tsx
Commit terakhir
16 Oktober 2026