Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat: sidepanel Guide Me view with focused step layout

Luis Ortizf4e59421f9c3
diff --git a/src/ui/sidepanel/App.tsx b/src/ui/sidepanel/App.tsx
index 10176bc..f43c124 100644
--- a/src/ui/sidepanel/App.tsx
+++ b/src/ui/sidepanel/App.tsx
@@ -1,6 +1,9 @@
import { Search, Settings, Video } from 'lucide-react';
import { useCallback, useEffect, useState } from 'react';
+import { browser } from '#imports';
import { CaptureState } from '@/core/capture/machine';
+import type { GuideMeSession } from '@/core/guideme/session';
+import { SESSION_KEY } from '@/core/guideme/session';
import { createTab, focusWindow, getActiveTab, getExtensionURL, queryTabs, updateTab } from '@/lib/browser-api';
import { logger } from '@/lib/logger';
import { sendMessage } from '@/lib/messaging';
@@ -9,6 +12,7 @@ import { Button } from '@/ui/components/ui/button';
import { Input } from '@/ui/components/ui/input';
import SettingsView from '@/ui/shared/SettingsView';
import GuideEditor from './GuideEditor';
+import GuideMeView from './GuideMeView';
import LibraryView from './LibraryView';
import RecordingView from './RecordingView';
@@ -16,7 +20,9 @@ type View =
| { name: 'library' }
| { name: 'editor'; guideId: string }
| { name: 'recording'; guideId: string }
- | { name: 'settings' };
+ | { name: 'settings' }
+ | { name: 'guideme'; guideId: string }
+ | { name: 'guideme-done'; guideId: string };
function MascotIcon({ size = 44 }: { size?: number }) {
return (
@@ -81,6 +87,15 @@ export default function App() {
return disconnect;
}, []);
+ useEffect(() => {
+ browser.storage.local.get([SESSION_KEY]).then((data: Record<string, unknown>) => {
+ const session = data[SESSION_KEY] as GuideMeSession | null;
+ if (session?.active) {
+ setView({ name: 'guideme', guideId: session.guideId });
+ }
+ });
+ }, []);
+
const handleStartRecording = useCallback(async () => {
const tab = await getActiveTab();
const url = tab?.url || '';
@@ -122,8 +137,31 @@ export default function App() {
return <RecordingView guideId={view.guideId} onStop={handleStopRecording} />;
}
+ if (view.name === 'guideme') {
+ return (
+ <GuideMeView
+ guideId={view.guideId}
+ onExit={() => {
+ sendMessage('guideMeCancel', undefined).catch(() => {});
+ setView({ name: 'library' });
+ }}
+ onComplete={(id) => setView({ name: 'guideme-done', guideId: id })}
+ />
+ );
+ }
+
+ if (view.name === 'guideme-done') {
+ return <p className="p-8 text-center text-foreground font-semibold">Completed! (placeholder)</p>;
+ }
+
if (view.name === 'editor') {
- return <GuideEditor guideId={view.guideId} onBack={() => setView({ name: 'library' })} />;
+ return (
+ <GuideEditor
+ guideId={view.guideId}
+ onBack={() => setView({ name: 'library' })}
+ onGuideMe={(id) => setView({ name: 'guideme', guideId: id })}
+ />
+ );
}
if (view.name === 'settings') {
diff --git a/src/ui/sidepanel/GuideEditor.tsx b/src/ui/sidepanel/GuideEditor.tsx
index 11cdd93..9d54595 100644
--- a/src/ui/sidepanel/GuideEditor.tsx
+++ b/src/ui/sidepanel/GuideEditor.tsx
@@ -21,6 +21,7 @@ import StepCard from './StepCard';
interface GuideEditorProps {
guideId: string;
onBack: () => void;
+ onGuideMe?: (guideId: string) => void;
}
interface GuideData {
@@ -29,7 +30,7 @@ interface GuideData {
screenshots: Map<string, Screenshot>;
}
-export default function GuideEditor({ guideId, onBack }: GuideEditorProps) {
+export default function GuideEditor({ guideId, onBack, onGuideMe }: GuideEditorProps) {
const [data, setData] = useState<GuideData | null>(null);
const [loading, setLoading] = useState(true);
const [notFound, setNotFound] = useState(false);
@@ -157,7 +158,7 @@ export default function GuideEditor({ guideId, onBack }: GuideEditorProps) {
<button
onClick={async () => {
await sendMessage('startGuideMe', { guideId });
- window.close();
+ onGuideMe?.(guideId);
}}
disabled={!data.steps.some((s) => s.elementMeta)}
className="shrink-0 p-1.5 rounded-md transition-colors text-warm hover:text-accent hover:bg-secondary disabled:opacity-30 disabled:cursor-not-allowed"
diff --git a/src/ui/sidepanel/GuideMeView.tsx b/src/ui/sidepanel/GuideMeView.tsx
new file mode 100644
index 0000000..8003481
--- /dev/null
+++ b/src/ui/sidepanel/GuideMeView.tsx
@@ -0,0 +1,237 @@
+import { ArrowLeft, Check, ChevronLeft, ChevronRight, Globe } from 'lucide-react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
+import { browser } from '#imports';
+import type { GuideMeSession } from '@/core/guideme/session';
+import { SESSION_KEY } from '@/core/guideme/session';
+import { getGuide } from '@/core/guides/service';
+import type { Guide, Screenshot, Step } from '@/core/guides/types';
+import { extractDomain } from '@/lib/utils';
+
+interface GuideMeViewProps {
+ guideId: string;
+ onExit: () => void;
+ onComplete: (guideId: string) => void;
+}
+
+interface GuideData {
+ guide: Guide;
+ steps: Step[];
+ screenshots: Map<string, Screenshot>;
+}
+
+export default function GuideMeView({ guideId, onExit, onComplete }: GuideMeViewProps) {
+ const [data, setData] = useState<GuideData | null>(null);
+ const [loading, setLoading] = useState(true);
+ const [activeStepIndex, setActiveStepIndex] = useState(0);
+ const [viewedStepIndex, setViewedStepIndex] = useState(0);
+ const objectUrlsRef = useRef<Map<string, string>>(new Map());
+
+ const loadGuide = useCallback(async () => {
+ const result = await getGuide(guideId);
+ if (!result) {
+ setLoading(false);
+ return;
+ }
+ setData(result);
+ setLoading(false);
+ }, [guideId]);
+
+ useEffect(() => {
+ loadGuide();
+ }, [loadGuide]);
+
+ useEffect(() => {
+ const handler = (changes: Record<string, { newValue?: unknown }>) => {
+ if (!changes[SESSION_KEY]) return;
+ const session = changes[SESSION_KEY].newValue as GuideMeSession | null;
+ if (!session) return;
+ if (!session.active) {
+ onComplete(guideId);
+ return;
+ }
+ setActiveStepIndex(session.activeStepIndex);
+ setViewedStepIndex(session.activeStepIndex);
+ };
+
+ browser.storage.local.onChanged.addListener(handler);
+ return () => browser.storage.local.onChanged.removeListener(handler);
+ }, [guideId, onComplete]);
+
+ useEffect(() => {
+ browser.storage.local.get([SESSION_KEY]).then((result: Record<string, unknown>) => {
+ const session = result[SESSION_KEY] as GuideMeSession | null;
+ if (session?.active) {
+ setActiveStepIndex(session.activeStepIndex);
+ setViewedStepIndex(session.activeStepIndex);
+ }
+ });
+ }, []);
+
+ const getObjectUrl = useCallback((stepId: string, blob: Blob) => {
+ const existing = objectUrlsRef.current.get(stepId);
+ if (existing) return existing;
+ const url = URL.createObjectURL(blob);
+ objectUrlsRef.current.set(stepId, url);
+ return url;
+ }, []);
+
+ useEffect(() => {
+ const urls = objectUrlsRef.current;
+ return () => {
+ for (const url of urls.values()) URL.revokeObjectURL(url);
+ urls.clear();
+ };
+ }, []);
+
+ const viewedStep = data?.steps[viewedStepIndex] ?? null;
+ const viewedScreenshot = viewedStep ? data?.screenshots.get(viewedStep.id) : undefined;
+
+ const highlightStyle = useMemo(() => {
+ if (!viewedStep?.elementMeta?.rect || !viewedScreenshot?.bounds) return null;
+ const rect = viewedStep.elementMeta.rect;
+ const bounds = viewedScreenshot.bounds;
+ const ratio = viewedStep.elementMeta.devicePixelRatio || 1;
+
+ const imgW = bounds.width;
+ const imgH = bounds.height;
+ if (!imgW || !imgH) return null;
+
+ const left = ((rect.x * ratio - bounds.x) / imgW) * 100;
+ const top = ((rect.y * ratio - bounds.y) / imgH) * 100;
+ const width = ((rect.width * ratio) / imgW) * 100;
+ const height = ((rect.height * ratio) / imgH) * 100;
+
+ return {
+ left: `${left}%`,
+ top: `${top}%`,
+ width: `${width}%`,
+ height: `${height}%`,
+ };
+ }, [viewedStep, viewedScreenshot]);
+
+ if (loading) return <p className="text-sm text-warm p-4">Loading...</p>;
+ if (!data) return <p className="text-sm text-warm p-4">Guide not found</p>;
+
+ const totalSteps = data.steps.length;
+
+ return (
+ <div className="min-h-screen bg-card flex flex-col">
+ <div className="px-4 pt-3 pb-2 flex items-center gap-2">
+ <button onClick={onExit} className="shrink-0 p-1 rounded text-warm hover:text-foreground">
+ <ArrowLeft size={18} />
+ </button>
+ <span className="flex-1 text-sm font-semibold text-foreground truncate">{data.guide.title}</span>
+ <span className="shrink-0 flex items-center gap-1.5 text-[11px] font-medium px-2 py-0.5 rounded-full bg-emerald-100 text-emerald-700">
+ <span className="w-1.5 h-1.5 rounded-full bg-emerald-500" />
+ Live
+ </span>
+ </div>
+
+ <div className="px-4 pb-3 flex gap-1">
+ {data.steps.map((step, idx) => (
+ <div
+ key={step.id}
+ className={`flex-1 h-[3px] rounded-[1.5px] ${
+ idx < activeStepIndex ? 'bg-[#059669]' : idx === activeStepIndex ? 'bg-amber' : 'bg-border'
+ }`}
+ />
+ ))}
+ </div>
+
+ <div className="px-4 pb-3">
+ <div className="bg-white rounded-2xl border border-border shadow-sm overflow-hidden">
+ <div className="p-4 pb-3">
+ <span className="inline-flex items-center gap-1.5 text-[11px] font-semibold bg-secondary text-amber-800 px-2.5 py-1 rounded-full mb-2.5">
+ <span className="w-5 h-5 rounded-full bg-amber text-white flex items-center justify-center text-[10px] font-bold">
+ {viewedStepIndex + 1}
+ </span>
+ Step {viewedStepIndex + 1} of {totalSteps}
+ </span>
+ <p className="text-[15px] font-semibold text-foreground leading-snug">
+ {viewedStep?.description || 'No description'}
+ </p>
+ {viewedStep?.url && (
+ <span className="flex items-center gap-1 text-[11px] text-muted-foreground mt-1.5">
+ <Globe size={11} />
+ {extractDomain(viewedStep.url)}
+ </span>
+ )}
+ </div>
+
+ {viewedScreenshot && (
+ <div className="relative mx-4 mb-3 rounded-lg overflow-hidden border border-border">
+ <img
+ src={getObjectUrl(viewedStep!.id, viewedScreenshot.blob)}
+ alt={`Step ${viewedStepIndex + 1}`}
+ className="w-full block"
+ />
+ {highlightStyle && (
+ <div className="absolute border-2 border-amber rounded-sm pointer-events-none" style={highlightStyle} />
+ )}
+ </div>
+ )}
+
+ <div className="flex items-center justify-between px-4 pb-3">
+ <button
+ onClick={() => setViewedStepIndex((i) => Math.max(0, i - 1))}
+ disabled={viewedStepIndex === 0}
+ className="flex items-center gap-1 text-xs font-medium text-warm hover:text-foreground disabled:opacity-30 disabled:cursor-not-allowed"
+ >
+ <ChevronLeft size={14} />
+ Prev
+ </button>
+ <button
+ onClick={() => setViewedStepIndex((i) => Math.min(totalSteps - 1, i + 1))}
+ disabled={viewedStepIndex === totalSteps - 1}
+ className="flex items-center gap-1 text-xs font-medium text-warm hover:text-foreground disabled:opacity-30 disabled:cursor-not-allowed"
+ >
+ Next
+ <ChevronRight size={14} />
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <div className="flex-1 px-4 pb-4 overflow-y-auto">
+ {data.steps.map((step, idx) => {
+ const isDone = idx < activeStepIndex;
+ const isActive = idx === activeStepIndex;
+ return (
+ <button
+ key={step.id}
+ onClick={() => setViewedStepIndex(idx)}
+ className={`w-full flex items-start gap-2.5 py-2 px-2 rounded-lg text-left transition-colors ${
+ viewedStepIndex === idx ? 'bg-secondary' : 'hover:bg-secondary/50'
+ }`}
+ >
+ {isDone ? (
+ <span className="shrink-0 w-5 h-5 rounded-full bg-[#059669] flex items-center justify-center mt-0.5">
+ <Check size={12} className="text-white" strokeWidth={3} />
+ </span>
+ ) : isActive ? (
+ <span className="shrink-0 w-5 h-5 rounded-full bg-amber flex items-center justify-center text-[10px] font-bold text-white mt-0.5">
+ {idx + 1}
+ </span>
+ ) : (
+ <span className="shrink-0 w-5 h-5 rounded-full border-2 border-border flex items-center justify-center text-[10px] font-medium text-muted-foreground mt-0.5">
+ {idx + 1}
+ </span>
+ )}
+ <span
+ className={`text-[13px] leading-snug ${
+ isDone
+ ? 'text-muted-foreground'
+ : isActive
+ ? 'font-semibold text-foreground'
+ : 'text-muted-foreground/60'
+ }`}
+ >
+ {step.description}
+ </span>
+ </button>
+ );
+ })}
+ </div>
+ </div>
+ );
+}