diff --git a/src/components/PushReminderDialog.tsx b/src/components/PushReminderDialog.tsx new file mode 100644 index 00000000..b6cf48b6 --- /dev/null +++ b/src/components/PushReminderDialog.tsx @@ -0,0 +1,178 @@ +import { useState, useEffect } from 'react'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogFooter, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Checkbox } from '@/components/ui/checkbox'; +import { Label } from '@/components/ui/label'; +import { GitBranch, Upload, AlertTriangle, X } from 'lucide-react'; +import { useGitStatus } from '@/hooks/useGitStatus'; +import { useNavigate } from 'react-router-dom'; +import { GitDialog } from '@/components/GitDialog'; + +interface PushReminderDialogProps { + projectId: string; + open: boolean; + onOpenChange: (open: boolean) => void; + onDisableReminders: () => void; + onDismiss: () => void; +} + +export function PushReminderDialog({ + projectId, + open, + onOpenChange, + onDisableReminders, + onDismiss, +}: PushReminderDialogProps) { + const [dontShowAgain, setDontShowAgain] = useState(false); + const [isGitDialogOpen, setIsGitDialogOpen] = useState(false); + const { data: gitStatus } = useGitStatus(projectId); + const navigate = useNavigate(); + + // Close the reminder dialog when git dialog opens + useEffect(() => { + if (isGitDialogOpen) { + onOpenChange(false); + onDismiss(); + } + }, [isGitDialogOpen, onOpenChange, onDismiss]); + + if (!gitStatus?.isGitRepo) { + return null; + } + + const hasNoRemote = gitStatus.remotes.length === 0; + const hasCommitsAhead = gitStatus.ahead > 0; + const hasUncommittedChanges = gitStatus.hasUncommittedChanges; + + const handleDismiss = () => { + if (dontShowAgain) { + onDisableReminders(); + } + onDismiss(); + onOpenChange(false); + }; + + const handlePrimaryAction = () => { + if (dontShowAgain) { + onDisableReminders(); + } + + if (hasNoRemote) { + // Close reminder dialog and open git dialog + onOpenChange(false); + setIsGitDialogOpen(true); + } else { + // Close reminder dialog and open git dialog for push + onOpenChange(false); + setIsGitDialogOpen(true); + } + }; + + // Determine dialog content based on git status + let icon = AlertTriangle; + let iconColor = 'text-amber-600 dark:text-amber-500'; + let title = ''; + let description = ''; + let primaryActionLabel = ''; + + if (hasNoRemote) { + icon = GitBranch; + iconColor = 'text-yellow-600 dark:text-yellow-500'; + title = 'No Remote Repository Configured'; + description = 'Your work is only stored locally in your browser. Configure a remote repository to prevent data loss if you clear your browser data.'; + primaryActionLabel = 'Configure Remote'; + } else if (hasCommitsAhead) { + icon = Upload; + iconColor = 'text-blue-600 dark:text-blue-500'; + title = 'Unpushed Commits'; + description = `You have ${gitStatus.ahead} commit${gitStatus.ahead !== 1 ? 's' : ''} that ${gitStatus.ahead !== 1 ? 'haven\'t' : 'hasn\'t'} been pushed to your remote repository. Push your changes to prevent data loss.`; + primaryActionLabel = 'Push Changes'; + } else if (hasUncommittedChanges) { + icon = AlertTriangle; + iconColor = 'text-amber-600 dark:text-amber-500'; + title = 'Uncommitted Changes'; + description = `You have ${gitStatus.changedFiles.length} uncommitted change${gitStatus.changedFiles.length !== 1 ? 's' : ''}. Commit and push your changes to keep your work safe.`; + primaryActionLabel = 'Commit & Push'; + } + + const Icon = icon; + + return ( + <> + + + +
+
+ +
+
+ {title} + + {description} + +
+ +
+
+ +
+ setDontShowAgain(checked === true)} + /> +
+ +

+ You can re-enable push reminders in Settings > Preferences +

+
+
+ + + + + +
+
+ + {/* Git Dialog - opened when user clicks primary action */} + + + ); +} diff --git a/src/components/PushWarningButton.tsx b/src/components/PushWarningButton.tsx new file mode 100644 index 00000000..cbd63cbb --- /dev/null +++ b/src/components/PushWarningButton.tsx @@ -0,0 +1,140 @@ +import { useState } from 'react'; +import { Button } from '@/components/ui/button'; +import { GitDialog } from '@/components/GitDialog'; +import { AlertTriangle, Upload, GitBranch } from 'lucide-react'; +import { cn } from '@/lib/utils'; +import { useGitStatus } from '@/hooks/useGitStatus'; +import { useNavigate } from 'react-router-dom'; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from '@/components/ui/tooltip'; + +interface PushWarningButtonProps { + projectId: string; + className?: string; + variant?: 'icon' | 'full'; +} + +export function PushWarningButton({ + projectId, + className, + variant = 'icon' +}: PushWarningButtonProps) { + const [isGitDialogOpen, setIsGitDialogOpen] = useState(false); + const { data: gitStatus } = useGitStatus(projectId); + const navigate = useNavigate(); + + if (!gitStatus?.isGitRepo) { + return null; + } + + // Determine warning state + const hasNoRemote = gitStatus.remotes.length === 0; + const hasUncommittedChanges = gitStatus.hasUncommittedChanges; + const hasCommitsAhead = gitStatus.ahead > 0; + + // Don't show if everything is synced + if (!hasNoRemote && !hasUncommittedChanges && !hasCommitsAhead) { + return null; + } + + // Determine icon and message + let icon = AlertTriangle; + let message = ''; + let action = ''; + + if (hasNoRemote) { + icon = GitBranch; + message = 'No remote configured'; + action = 'Configure remote to prevent data loss'; + } else if (hasCommitsAhead) { + icon = Upload; + message = `${gitStatus.ahead} commit${gitStatus.ahead !== 1 ? 's' : ''} not pushed`; + action = 'Push to remote'; + } else if (hasUncommittedChanges) { + icon = AlertTriangle; + message = `${gitStatus.changedFiles.length} uncommitted change${gitStatus.changedFiles.length !== 1 ? 's' : ''}`; + action = 'Commit and push your changes'; + } + + const Icon = icon; + + const handleClick = () => { + if (hasNoRemote) { + // If no remote, open git dialog to configure + setIsGitDialogOpen(true); + } else { + // If remote exists, open git dialog for push/commit + setIsGitDialogOpen(true); + } + }; + + if (variant === 'icon') { + return ( + <> + + + + + + +
+

{message}

+

{action}

+
+
+
+
+ + + + ); + } + + // Full button variant + return ( + <> + + + + + ); +} diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 3b65c84b..d1c7ee74 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -52,6 +52,7 @@ interface ChatPaneProps { onNewChat: () => void; onFirstInteraction?: () => void; onLoadingChange?: (isLoading: boolean) => void; + onMessageSent?: () => void; isLoading?: boolean; isBuildLoading?: boolean; consoleError?: ProjectPreviewConsoleError | null; @@ -67,6 +68,7 @@ export const ChatPane = forwardRef(({ onNewChat, onFirstInteraction, onLoadingChange, + onMessageSent, isLoading: externalIsLoading, isBuildLoading: externalIsBuildLoading, consoleError, @@ -478,7 +480,12 @@ export const ChatPane = forwardRef(({ // Send as text parts if we have multiple parts, otherwise send as string for simplicity const messageContent = contentParts.length === 1 ? contentParts[0].text : contentParts; await sendMessage(messageContent, modelToUse); - }, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath]); + + // Notify parent that a message was sent (for push reminder tracking) + if (onMessageSent) { + onMessageSent(); + } + }, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath, onMessageSent]); // Handle textarea focus - show onboarding if not configured const handleTextareaFocus = useCallback(() => { diff --git a/src/hooks/usePushReminder.ts b/src/hooks/usePushReminder.ts new file mode 100644 index 00000000..65ddbca7 --- /dev/null +++ b/src/hooks/usePushReminder.ts @@ -0,0 +1,115 @@ +import { useEffect, useCallback } from 'react'; +import { useLocalStorage } from './useLocalStorage'; +import { useGitStatus } from './useGitStatus'; + +interface PushReminderState { + /** Whether push reminders are enabled */ + enabled: boolean; + /** Number of messages since last push */ + messagesSinceLastPush: number; + /** Timestamp when user last pushed or dismissed a reminder */ + lastInteraction: number; + /** Project ID being tracked */ + currentProjectId: string | null; +} + +const DEFAULT_STATE: PushReminderState = { + enabled: true, + messagesSinceLastPush: 0, + lastInteraction: Date.now(), + currentProjectId: null, +}; + +/** Number of messages before showing push reminder */ +const MESSAGE_THRESHOLD = 5; + +/** Minimum time in ms between showing reminders (5 minutes) */ +const MIN_REMINDER_INTERVAL = 5 * 60 * 1000; + +export function usePushReminder(projectId: string | null) { + const [state, setState] = useLocalStorage( + 'push-reminder-state', + DEFAULT_STATE + ); + + const { data: gitStatus } = useGitStatus(projectId); + + // Reset counter when switching projects + useEffect(() => { + if (projectId && state.currentProjectId !== projectId) { + setState((prev) => ({ + ...prev, + currentProjectId: projectId, + messagesSinceLastPush: 0, + lastInteraction: Date.now(), + })); + } + }, [projectId, state.currentProjectId, setState]); + + // Check if should show reminder + const shouldShowReminder = useCallback(() => { + if (!state.enabled || !projectId || !gitStatus?.isGitRepo) { + return false; + } + + // Don't show if user recently interacted with push reminder + const timeSinceLastInteraction = Date.now() - state.lastInteraction; + if (timeSinceLastInteraction < MIN_REMINDER_INTERVAL) { + return false; + } + + // Show if: + // 1. There are uncommitted changes OR commits ahead of remote + // 2. Enough messages have been sent since last interaction + const hasUnpushedWork = gitStatus.hasUncommittedChanges || gitStatus.ahead > 0; + const enoughMessages = state.messagesSinceLastPush >= MESSAGE_THRESHOLD; + + return hasUnpushedWork && enoughMessages; + }, [state, projectId, gitStatus]); + + // Increment message counter + const incrementMessages = useCallback(() => { + if (!state.enabled || !projectId) return; + + setState((prev) => ({ + ...prev, + messagesSinceLastPush: prev.messagesSinceLastPush + 1, + })); + }, [state.enabled, projectId, setState]); + + // Reset counter (called after push or dismiss) + const resetReminder = useCallback(() => { + setState((prev) => ({ + ...prev, + messagesSinceLastPush: 0, + lastInteraction: Date.now(), + })); + }, [setState]); + + // Enable/disable reminders + const setEnabled = useCallback((enabled: boolean) => { + setState((prev) => ({ + ...prev, + enabled, + messagesSinceLastPush: 0, + lastInteraction: Date.now(), + })); + }, [setState]); + + // Check if there's unpushed work that should trigger warning icon + const hasUnpushedWork = gitStatus?.isGitRepo && ( + gitStatus.hasUncommittedChanges || + gitStatus.ahead > 0 || + gitStatus.remotes.length === 0 + ); + + return { + shouldShowReminder: shouldShowReminder(), + incrementMessages, + resetReminder, + enabled: state.enabled, + setEnabled, + hasUnpushedWork: hasUnpushedWork || false, + gitStatus, + }; +} diff --git a/src/locales/en.json b/src/locales/en.json index 2ff60d9d..bb64f964 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -57,6 +57,8 @@ "temporaryDirectoryDescription": "Filesystem path for temporary files", "sentryDsn": "Sentry DSN", "sentryDsnDescription": "Sentry Data Source Name (DSN) for error reporting. Leave empty to disable Sentry.", + "pushReminders": "Push reminders", + "pushRemindersDescription": "Show periodic reminders to push your code to a remote repository to prevent data loss.", "shareErrorReports": "Share error reports", "shareErrorReportsDescription": "Help improve this app by automatically sending crash and error reports.", "english": "English", diff --git a/src/pages/Preferences.tsx b/src/pages/Preferences.tsx index 39b3a028..2baa688b 100644 --- a/src/pages/Preferences.tsx +++ b/src/pages/Preferences.tsx @@ -8,12 +8,14 @@ import { Label } from "@/components/ui/label"; import { useIsMobile } from "@/hooks/useIsMobile"; import { useNavigate } from "react-router-dom"; import { useAppContext } from "@/hooks/useAppContext"; +import { usePushReminder } from "@/hooks/usePushReminder"; export function Preferences() { const { t } = useTranslation(); const isMobile = useIsMobile(); const navigate = useNavigate(); const { config, updateConfig } = useAppContext(); + const pushReminder = usePushReminder(null); return (
@@ -73,6 +75,26 @@ export function Preferences() {

+
+
+
+ +
+ { + pushReminder.setEnabled(checked); + }} + /> +
+

+ {t('pushRemindersDescription')} +

+
+
diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index 7f7b00ed..bea2b6c3 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -15,11 +15,14 @@ import { useNavigate } from 'react-router-dom'; import { ActionsMenu } from '@/components/ActionsMenu'; import { useIsMobile } from '@/hooks/useIsMobile'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; +import { PushWarningButton } from '@/components/PushWarningButton'; +import { PushReminderDialog } from '@/components/PushReminderDialog'; import { StarButton } from '@/components/StarButton'; import { useBuildProject } from '@/hooks/useBuildProject'; import { useIsProjectPreviewable } from '@/hooks/useIsProjectPreviewable'; import { useConsoleError } from '@/hooks/useConsoleError'; import { useAutoBuild } from '@/hooks/useAutoBuild'; +import { usePushReminder } from '@/hooks/usePushReminder'; export function ProjectView() { const { projectId } = useParams<{ projectId: string }>(); @@ -30,6 +33,7 @@ export function ProjectView() { const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat'); const [isAILoading, setIsAILoading] = useState(false); const [isProjectDetailsOpen, setIsProjectDetailsOpen] = useState(false); + const [isPushReminderOpen, setIsPushReminderOpen] = useState(false); // Use console error state from provider const { consoleError, dismissConsoleError, clearErrors } = useConsoleError(); @@ -43,6 +47,7 @@ export function ProjectView() { const build = useBuildProject(projectId!); const { data: isPreviewable = false } = useIsProjectPreviewable(projectId!); + const pushReminder = usePushReminder(projectId || null); // Enable auto-build for previewable projects useAutoBuild({ @@ -105,6 +110,16 @@ export function ProjectView() { setIsAILoading(loading); }; + // Handle message sent - increment push reminder counter + const handleMessageSent = useCallback(() => { + pushReminder.incrementMessages(); + + // Check if we should show the reminder + if (pushReminder.shouldShowReminder) { + setIsPushReminderOpen(true); + } + }, [pushReminder]); + // Handle first user interaction to enable audio context const handleFirstInteraction = () => { // This will be handled automatically by the useKeepAlive hook @@ -165,6 +180,7 @@ export function ProjectView() {
{project ? ( <> + )} + + {/* Push Reminder Dialog */} + {project && ( + pushReminder.setEnabled(false)} + onDismiss={pushReminder.resetReminder} + /> + )}
); } @@ -374,6 +402,7 @@ export function ProjectView() {
{project ? ( <> + )} + + {/* Push Reminder Dialog */} + {project && ( + pushReminder.setEnabled(false)} + onDismiss={pushReminder.resetReminder} + /> + )}
); }