Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions web/app/(main-layout)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import PlatformAssistantProvider from "@/components/providers/platform-assistant
import RemoteModuleProvider from "@/components/providers/remote-module-provider";
import WrappedHeroUIProvider from "@/components/providers/wrapped-hero-ui-provider";
import { Analytics } from "@vercel/analytics/next";
import { ReactFlowProvider } from "@xyflow/react";
import "material-icons/iconfont/material-icons.css";
import type { Metadata } from "next";
import { Suspense } from "react";
Expand All @@ -33,18 +32,16 @@ export default function RootLayout({
<EditorContextProvider>
<CapacitorProvider>
<InterModuleCommunicationProvider>
<ReactFlowProvider>
<DndProvider>
<RemoteModuleProvider isPreventingCSS={true}>
<Toaster />
<Nav>
<PlatformAssistantProvider>
{children}
</PlatformAssistantProvider>
</Nav>
</RemoteModuleProvider>
</DndProvider>
</ReactFlowProvider>
<DndProvider>
<RemoteModuleProvider isPreventingCSS={true}>
<Toaster />
<Nav>
<PlatformAssistantProvider>
{children}
</PlatformAssistantProvider>
</Nav>
</RemoteModuleProvider>
</DndProvider>
</InterModuleCommunicationProvider>
</CapacitorProvider>
</EditorContextProvider>
Expand Down
4 changes: 2 additions & 2 deletions web/components/explorer/app/app-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ function DraggableAppPreviewCard({ ext }: { ext: ExtensionApp }) {
isShowCompatibleChip={false}
isShowContextMenu={false}
isDisableButtonPress={!isDragFinished}
onPress={(ext) => {
onPress={async (ext) => {
const config: AppViewConfig = {
app: ext.config.id,
viewId: `${ext.config.id}-${v4()}`,
recommendedHeight: ext.config.recommendedHeight,
recommendedWidth: ext.config.recommendedWidth,
};
createAppViewInCanvasView(config);
await createAppViewInCanvasView(config);
console.log("Is Landscape:", isLandscape);
if (!isLandscape) {
editorContext?.setEditorStates((prev) => ({
Expand Down
3 changes: 2 additions & 1 deletion web/components/modals/sharing-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function SharingModal({
const params = useSearchParams();
// Use the 'app' query parameter to load specific extension app upon loading page
const app = params.get("app");
const workflow = params.get("workflow");

const tabItems: TabItem[] = [
{
Expand Down Expand Up @@ -139,7 +140,7 @@ export default function SharingModal({
Share your workspace via this URL
</p>

<p className="font-bold break-all">{`${window.location.origin}?app=${app}${shareInfo?.inviteCode ? `&inviteCode=${shareInfo.inviteCode}` : ""}`}</p>
<p className="font-bold break-all">{`${window.location.origin}?${app ? `app=${app}` : workflow ? `workflow=${workflow}` : ""}${shareInfo?.inviteCode ? `&inviteCode=${shareInfo.inviteCode}` : ""}`}</p>
<Button
color="primary"
onPress={() => {
Expand Down
9 changes: 5 additions & 4 deletions web/components/providers/dnd-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "@dnd-kit/core";
import { addToast } from "@heroui/react";
import { IMCMessageTypeEnum, ViewModel } from "@pulse-editor/shared-utils";
import { Node as ReactFlowNode, useReactFlow } from "@xyflow/react";
import { Node as ReactFlowNode } from "@xyflow/react";
import { ReactNode, useContext, useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { v4 } from "uuid";
Expand Down Expand Up @@ -58,7 +58,6 @@ export default function DndProvider({
});
const { isLandscape } = useScreenSize();
const { createAppViewInCanvasView } = useTabViewManager();
const { updateNodeData } = useReactFlow();

const [mounted, setMounted] = useState(false);

Expand Down Expand Up @@ -93,7 +92,7 @@ export default function DndProvider({
recommendedHeight: app.config.recommendedHeight,
recommendedWidth: app.config.recommendedWidth,
};
createAppViewInCanvasView(config);
await createAppViewInCanvasView(config);
} catch (error) {
addToast({
title: "Failed to open app",
Expand All @@ -112,10 +111,12 @@ export default function DndProvider({
recommendedWidth: app.config.recommendedWidth,
};

const { viewId, node, paramName } = over.data.current as {
const { viewId, node, paramName, updateNodeData } = over.data
.current as {
viewId: string;
node: ReactFlowNode<AppNodeData>;
paramName: string;
updateNodeData: (id: string, data: Partial<AppNodeData>) => void;
};

updateNodeData(viewId, {
Expand Down
7 changes: 6 additions & 1 deletion web/components/views/canvas/canvas-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ReactFlow,
Edge as ReactFlowEdge,
Node as ReactFlowNode,
ReactFlowProvider,
reconnectEdge,
useReactFlow,
useViewport,
Expand Down Expand Up @@ -377,6 +378,10 @@ export const MemoizedCanvasView = memo(
config: CanvasViewConfig;
isActive: boolean;
tabName: string;
}) => <CanvasView config={config} isActive={isActive} tabName={tabName} />,
}) => (
<ReactFlowProvider>
<CanvasView config={config} isActive={isActive} tabName={tabName} />
</ReactFlowProvider>
),
);
MemoizedCanvasView.displayName = "MemoizedCanvasView";
3 changes: 3 additions & 0 deletions web/components/views/canvas/nodes/app-node/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,15 @@ function DroppableInputHandle({
node: ReactFlowNode<AppNodeData>;
editorContext: EditorContextType | undefined;
}) {
const { updateNodeData } = useReactFlow();

const { setNodeRef, isOver } = useDroppable({
id: `node-handle-input-${node.id}-${paramName}`,
data: {
viewId: node.id,
node,
paramName,
updateNodeData,
},
});

Expand Down
2 changes: 0 additions & 2 deletions web/components/views/view-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function ViewArea() {
selectTab,
closeTabView,
createAppTabView,
createAppViewInCanvasView,
activeTabView,
} = useTabViewManager();

Expand Down Expand Up @@ -76,7 +75,6 @@ export default function ViewArea() {
} else {
setIsShowTabs(true);
}
console.log("Tab views changed:", tabViews);
}, [tabViews]);

return (
Expand Down
19 changes: 19 additions & 0 deletions web/lib/hooks/use-tab-view-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EditorContext } from "@/components/providers/editor-context-provider";
import { IMCContext } from "@/components/providers/imc-provider";
import { addToast } from "@heroui/react";
import { ViewModeEnum } from "@pulse-editor/shared-utils";
import { useRouter } from "next/navigation";
import { useContext, useEffect, useState } from "react";
import { v4 } from "uuid";
import {
Expand All @@ -15,6 +16,8 @@ export function useTabViewManager() {
const editorContext = useContext(EditorContext);
const imcContext = useContext(IMCContext);

const router = useRouter();

const [tabViews, setTabViews] = useState<TabView[]>(
editorContext?.editorStates.tabViews ?? [],
);
Expand Down Expand Up @@ -54,6 +57,7 @@ export function useTabViewManager() {
};
}) ?? [];

// Update local states when editor context changes
useEffect(() => {
if (!editorContext) {
throw new Error("Editor context is not available");
Expand All @@ -70,6 +74,21 @@ export function useTabViewManager() {
editorContext?.editorStates.tabIndex,
]);

// Pend workflow or app param when tab index changes
useEffect(() => {
if (activeTabView) {
if (activeTabView.type === ViewModeEnum.App) {
const appConfig = activeTabView.config as AppViewConfig;
router.push(`/?app=${appConfig.app}`);
} else if (activeTabView.type === ViewModeEnum.Canvas) {
const canvasConfig = activeTabView.config as CanvasViewConfig;
router.push(`/?workflow=${canvasConfig.viewId}`);
}
} else {
router.push(`/`);
}
}, [activeTabView]);

function selectTab(newIndex: number) {
if (!editorContext) {
throw new Error("Editor context is not available");
Expand Down