Remove reliance on localstorage for pendingScheduleDeepLink when scheduling a recipe (#5290)

This commit is contained in:
Zane
2025-10-21 12:01:58 -07:00
committed by GitHub
parent c89e852fae
commit 3e4488275b
6 changed files with 30 additions and 35 deletions
@@ -7,6 +7,7 @@ import { Check, Save, Calendar, X, Play } from 'lucide-react';
import { ExtensionConfig } from '../ConfigContext'; import { ExtensionConfig } from '../ConfigContext';
import { ScheduleFromRecipeModal } from '../schedule/ScheduleFromRecipeModal'; import { ScheduleFromRecipeModal } from '../schedule/ScheduleFromRecipeModal';
import { Button } from '../ui/button'; import { Button } from '../ui/button';
import { useNavigation } from '../../hooks/useNavigation';
import { RecipeFormFields } from './shared/RecipeFormFields'; import { RecipeFormFields } from './shared/RecipeFormFields';
import { RecipeFormData } from './shared/recipeFormSchema'; import { RecipeFormData } from './shared/recipeFormSchema';
@@ -28,6 +29,7 @@ export default function CreateEditRecipeModal({
isCreateMode = false, isCreateMode = false,
recipeId, recipeId,
}: CreateEditRecipeModalProps) { }: CreateEditRecipeModalProps) {
const setView = useNavigation();
const getInitialValues = React.useCallback((): RecipeFormData => { const getInitialValues = React.useCallback((): RecipeFormData => {
if (recipe) { if (recipe) {
return { return {
@@ -452,18 +454,9 @@ export default function CreateEditRecipeModal({
onClose={() => setIsScheduleModalOpen(false)} onClose={() => setIsScheduleModalOpen(false)}
recipe={getCurrentRecipe()} recipe={getCurrentRecipe()}
onCreateSchedule={(deepLink) => { onCreateSchedule={(deepLink) => {
// Open the schedules view with the deep link pre-filled // Navigate to schedules view with the deep link in state
window.electron.createChatWindow( setView('schedules', { pendingScheduleDeepLink: deepLink });
undefined, setIsScheduleModalOpen(false);
undefined,
undefined,
undefined,
undefined,
'schedules',
undefined
);
// Store the deep link in localStorage for the schedules view to pick up
localStorage.setItem('pendingScheduleDeepLink', deepLink);
}} }}
/> />
</div> </div>
@@ -13,8 +13,10 @@ import ImportRecipeForm, { ImportRecipeButton } from './ImportRecipeForm';
import CreateEditRecipeModal from './CreateEditRecipeModal'; import CreateEditRecipeModal from './CreateEditRecipeModal';
import { generateDeepLink, Recipe } from '../../recipe'; import { generateDeepLink, Recipe } from '../../recipe';
import { ScheduleFromRecipeModal } from '../schedule/ScheduleFromRecipeModal'; import { ScheduleFromRecipeModal } from '../schedule/ScheduleFromRecipeModal';
import { useNavigation } from '../../hooks/useNavigation';
export default function RecipesView() { export default function RecipesView() {
const setView = useNavigation();
const [savedRecipes, setSavedRecipes] = useState<RecipeManifestResponse[]>([]); const [savedRecipes, setSavedRecipes] = useState<RecipeManifestResponse[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [showSkeleton, setShowSkeleton] = useState(true); const [showSkeleton, setShowSkeleton] = useState(true);
@@ -160,11 +162,8 @@ export default function RecipesView() {
}; };
const handleCreateScheduleFromRecipe = async (deepLink: string) => { const handleCreateScheduleFromRecipe = async (deepLink: string) => {
// Store the deeplink for the schedule modal to pick up // Navigate to schedules view with the deep link in state
localStorage.setItem('pendingScheduleDeepLink', deepLink); setView('schedules', { pendingScheduleDeepLink: deepLink });
// Navigate to schedules view and open create modal
window.location.hash = '#/schedules';
setShowScheduleModal(false); setShowScheduleModal(false);
setSelectedRecipeForSchedule(null); setSelectedRecipeForSchedule(null);
@@ -31,6 +31,7 @@ interface CreateScheduleModalProps {
onSubmit: (payload: NewSchedulePayload) => Promise<void>; onSubmit: (payload: NewSchedulePayload) => Promise<void>;
isLoadingExternally: boolean; isLoadingExternally: boolean;
apiErrorExternally: string | null; apiErrorExternally: string | null;
initialDeepLink?: string | null;
} }
// Interface for clean extension in YAML // Interface for clean extension in YAML
@@ -272,6 +273,7 @@ export const CreateScheduleModal: React.FC<CreateScheduleModalProps> = ({
onSubmit, onSubmit,
isLoadingExternally, isLoadingExternally,
apiErrorExternally, apiErrorExternally,
initialDeepLink,
}) => { }) => {
const [scheduleId, setScheduleId] = useState<string>(''); const [scheduleId, setScheduleId] = useState<string>('');
const [sourceType, setSourceType] = useState<SourceType>('file'); const [sourceType, setSourceType] = useState<SourceType>('file');
@@ -331,16 +333,12 @@ export const CreateScheduleModal: React.FC<CreateScheduleModalProps> = ({
); );
useEffect(() => { useEffect(() => {
// Check for pending deep link when modal opens // Check for initial deep link from props when modal opens
if (isOpen) { if (isOpen && initialDeepLink) {
const pendingDeepLink = localStorage.getItem('pendingScheduleDeepLink'); setSourceType('deeplink');
if (pendingDeepLink) { handleDeepLinkChange(initialDeepLink);
localStorage.removeItem('pendingScheduleDeepLink');
setSourceType('deeplink');
handleDeepLinkChange(pendingDeepLink);
}
} }
}, [isOpen, handleDeepLinkChange]); }, [isOpen, initialDeepLink, handleDeepLinkChange]);
const resetForm = () => { const resetForm = () => {
setScheduleId(''); setScheduleId('');
@@ -1,4 +1,5 @@
import React, { useState, useEffect, useCallback, useMemo } from 'react'; import React, { useState, useEffect, useCallback, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { import {
listSchedules, listSchedules,
createSchedule, createSchedule,
@@ -22,6 +23,7 @@ import { toastError, toastSuccess } from '../../toasts';
import cronstrue from 'cronstrue'; import cronstrue from 'cronstrue';
import { formatToLocalDateWithTimezone } from '../../utils/date'; import { formatToLocalDateWithTimezone } from '../../utils/date';
import { MainPanelLayout } from '../Layout/MainPanelLayout'; import { MainPanelLayout } from '../Layout/MainPanelLayout';
import { ViewOptions } from '../../utils/navigationUtils';
interface SchedulesViewProps { interface SchedulesViewProps {
onClose?: () => void; onClose?: () => void;
@@ -210,6 +212,7 @@ const ScheduleCard = React.memo<{
ScheduleCard.displayName = 'ScheduleCard'; ScheduleCard.displayName = 'ScheduleCard';
const SchedulesView: React.FC<SchedulesViewProps> = ({ onClose: _onClose }) => { const SchedulesView: React.FC<SchedulesViewProps> = ({ onClose: _onClose }) => {
const location = useLocation();
const [schedules, setSchedules] = useState<ScheduledJob[]>([]); const [schedules, setSchedules] = useState<ScheduledJob[]>([]);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
@@ -219,6 +222,7 @@ const SchedulesView: React.FC<SchedulesViewProps> = ({ onClose: _onClose }) => {
const [isEditModalOpen, setIsEditModalOpen] = useState(false); const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const [editingSchedule, setEditingSchedule] = useState<ScheduledJob | null>(null); const [editingSchedule, setEditingSchedule] = useState<ScheduledJob | null>(null);
const [isRefreshing, setIsRefreshing] = useState(false); const [isRefreshing, setIsRefreshing] = useState(false);
const [pendingDeepLink, setPendingDeepLink] = useState<string | null>(null);
// Individual loading states for each action to prevent double-clicks // Individual loading states for each action to prevent double-clicks
const [pausingScheduleIds, setPausingScheduleIds] = useState<Set<string>>(new Set()); const [pausingScheduleIds, setPausingScheduleIds] = useState<Set<string>>(new Set());
@@ -257,15 +261,16 @@ const SchedulesView: React.FC<SchedulesViewProps> = ({ onClose: _onClose }) => {
if (viewingScheduleId === null) { if (viewingScheduleId === null) {
fetchSchedules(); fetchSchedules();
// Check for pending deep link from recipe editor // Check for pending deep link from navigation state
const pendingDeepLink = localStorage.getItem('pendingScheduleDeepLink'); const locationState = location.state as ViewOptions | null;
if (pendingDeepLink) { if (locationState?.pendingScheduleDeepLink) {
localStorage.removeItem('pendingScheduleDeepLink'); setPendingDeepLink(locationState.pendingScheduleDeepLink);
setIsCreateModalOpen(true); setIsCreateModalOpen(true);
// The CreateScheduleModal will handle the deep link // Clear the state after reading it
window.history.replaceState({}, document.title);
} }
} }
}, [viewingScheduleId, fetchSchedules]); }, [viewingScheduleId, fetchSchedules, location.state]);
// Optimized periodic refresh - only refresh if not actively doing something // Optimized periodic refresh - only refresh if not actively doing something
useEffect(() => { useEffect(() => {
@@ -320,6 +325,7 @@ const SchedulesView: React.FC<SchedulesViewProps> = ({ onClose: _onClose }) => {
const handleCloseCreateModal = () => { const handleCloseCreateModal = () => {
setIsCreateModalOpen(false); setIsCreateModalOpen(false);
setSubmitApiError(null); setSubmitApiError(null);
setPendingDeepLink(null);
}; };
const handleOpenEditModal = (schedule: ScheduledJob) => { const handleOpenEditModal = (schedule: ScheduledJob) => {
@@ -648,6 +654,7 @@ const SchedulesView: React.FC<SchedulesViewProps> = ({ onClose: _onClose }) => {
onSubmit={handleCreateScheduleSubmit} onSubmit={handleCreateScheduleSubmit}
isLoadingExternally={isSubmitting} isLoadingExternally={isSubmitting}
apiErrorExternally={submitApiError} apiErrorExternally={submitApiError}
initialDeepLink={pendingDeepLink}
/> />
<EditScheduleModal <EditScheduleModal
isOpen={isEditModalOpen} isOpen={isEditModalOpen}
-3
View File
@@ -991,8 +991,6 @@ ipcMain.on('react-ready', () => {
log.info('No pending deep link to process'); log.info('No pending deep link to process');
} }
// We don't need to handle pending deep links here anymore
// since we're handling them in the window creation flow
log.info('React ready - window is prepared for deep links'); log.info('React ready - window is prepared for deep links');
}); });
@@ -1937,7 +1935,6 @@ async function appMain() {
// Log the recipe for debugging // Log the recipe for debugging
console.log('Creating chat window with recipe:', recipe); console.log('Creating chat window with recipe:', recipe);
// Pass recipe as part of viewOptions when viewType is recipeEditor
createChat( createChat(
app, app,
query, query,
+1
View File
@@ -35,6 +35,7 @@ export type ViewOptions = {
resetChat?: boolean; resetChat?: boolean;
shareToken?: string; shareToken?: string;
resumeSessionId?: string; resumeSessionId?: string;
pendingScheduleDeepLink?: string;
}; };
export const createNavigationHandler = (navigate: NavigateFunction) => { export const createNavigationHandler = (navigate: NavigateFunction) => {