Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Routes, Route, useSearchParams, useNavigate } from "react-router-dom";
import Navbar from "./components/Navbar";
import tour from "./components/Tour";
import useAppStore from "./store/store";
import { shallow } from "zustand/shallow";
import LearnContent from "./components/Content";
import PlaygroundSidebar from "./components/PlaygroundSidebar";
import "./styles/App.css";
Expand All @@ -23,7 +24,7 @@ const App = () => {
useAppStore((state) => ({
isAIConfigOpen: state.isAIConfigOpen,
setAIConfigOpen: state.setAIConfigOpen,
}));
}), shallow);
const backgroundColor = useAppStore((state) => state.backgroundColor);
const textColor = useAppStore((state) => state.textColor);
const [loading, setLoading] = useState(true);
Expand Down
5 changes: 3 additions & 2 deletions src/components/AIChatPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState, useMemo } from "react";
import ReactMarkdown from "react-markdown";
import useAppStore from "../store/store";
import { shallow } from "zustand/shallow";
import { sendMessage, stopMessage } from "../ai-assistant/chatRelay";

export const AIChatPanel = () => {
Expand All @@ -13,7 +14,7 @@ export const AIChatPanel = () => {
editorTemplateMark: state.editorValue,
editorModelCto: state.editorModelCto,
editorAgreementData: state.editorAgreementData,
}));
}), shallow);

const { chatState, resetChat, aiConfig, setAIConfig, setAIConfigOpen, setAIChatOpen, textColor, backgroundColor } = useAppStore((state) => ({
chatState: state.chatState,
Expand All @@ -24,7 +25,7 @@ export const AIChatPanel = () => {
setAIChatOpen: state.setAIChatOpen,
textColor: state.textColor,
backgroundColor: state.backgroundColor
}));
}), shallow);

const latestMessageRef = useRef<HTMLDivElement>(null);

Expand Down
3 changes: 2 additions & 1 deletion src/components/AIConfigPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect, useMemo, useCallback } from 'react';
import { AIConfig, AIConfigPopupProps, KeyProtectionLevel } from '../types/components/AIAssistant.types';
import { useDebounce } from 'use-debounce';
import useAppStore from '../store/store';
import { shallow } from 'zustand/shallow';
import {
isWebAuthnPRFSupported,
encryptAndStoreApiKey,
Expand All @@ -15,7 +16,7 @@ const AIConfigPopup = ({ isOpen, onClose }: AIConfigPopupProps) => {
backgroundColor: state.backgroundColor,
keyProtectionLevel: state.keyProtectionLevel,
setKeyProtectionLevel: state.setKeyProtectionLevel,
}));
}), shallow);

const theme = useMemo(() => {
const isDarkMode = backgroundColor !== '#ffffff';
Expand Down
3 changes: 2 additions & 1 deletion src/components/CodeSelectionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef, useCallback } from 'react';
import { sendMessage } from '../ai-assistant/chatRelay';
import { CodeSelectionMenuProps } from '../types/components/AIAssistant.types';
import useAppStore from '../store/store';
import { shallow } from 'zustand/shallow';
import ReactMarkdown from "react-markdown";
import * as monaco from 'monaco-editor';

Expand Down Expand Up @@ -48,7 +49,7 @@ const CodeSelectionMenu: React.FC<CodeSelectionMenuProps> = ({
editorTemplateMark: state.editorValue,
editorModelCto: state.editorModelCto,
editorAgreementData: state.editorAgreementData,
}));
}), shallow);

const handleExplain = async () => {
if (!aiConfig) {
Expand Down
15 changes: 14 additions & 1 deletion src/components/PlaygroundSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FiTerminal, FiShare2, FiSettings } from "react-icons/fi";
import { FaCirclePlay } from "react-icons/fa6";
import { IoChatbubbleEllipsesOutline } from "react-icons/io5";
import useAppStore from "../store/store";
import { shallow } from "zustand/shallow";
import { message, Tooltip } from "antd";
import FullScreenModal from "./FullScreenModal";
import SettingsModal from "./SettingsModal";
Expand Down Expand Up @@ -34,7 +35,7 @@ const PlaygroundSidebar = () => {
setAIChatOpen: state.setAIChatOpen,
generateShareableLink: state.generateShareableLink,
setSettingsOpen: state.setSettingsOpen,
}));
}), shallow);

const handleShare = async () => {
try {
Expand Down Expand Up @@ -163,6 +164,12 @@ const PlaygroundSidebar = () => {
aria-label={title}
tabIndex={0}
onClick={onClick}
onKeyDown={(e) => {
if (onClick && (e.key === 'Enter' || e.key === ' ')) {
e.preventDefault();
onClick();
}
}}
className={`group playground-sidebar-nav-item ${
active ? 'playground-sidebar-nav-item-active' : 'playground-sidebar-nav-item-inactive'
} tour-${title.toLowerCase().replace(' ', '-')}`}
Expand All @@ -188,6 +195,12 @@ const PlaygroundSidebar = () => {
aria-label={title}
tabIndex={0}
onClick={onClick}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick();
}
}}
className={`group playground-sidebar-nav-bottom-item tour-${title.toLowerCase().replace(' ', '-')}`}
>
<Icon size={18} />
Expand Down
3 changes: 2 additions & 1 deletion src/components/ProblemPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo, useCallback } from 'react';
import useAppStore from '../store/store';
import { shallow } from 'zustand/shallow';
import { navigateToLine, EditorSource } from '../utils/editorNavigation';
import '../styles/components/ProblemPanel.css';

Expand All @@ -18,7 +19,7 @@ const ProblemPanel: React.FC = () => {
error: state.error,
backgroundColor: state.backgroundColor,
textColor: state.textColor
}));
}), shallow);

const parseError = (errorMessage: string) => {
const errors: Omit<ProblemItem, 'id' | 'timestamp'>[] = [];
Expand Down
11 changes: 8 additions & 3 deletions src/editors/ConcertoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMonaco } from "@monaco-editor/react";
import { lazy, Suspense, useCallback, useEffect, useMemo, MutableRefObject } from "react";
import { lazy, Suspense, useCallback, useEffect, useMemo, useRef, MutableRefObject } from "react";
import * as monaco from "monaco-editor";
import useAppStore from "../store/store";
import { shallow } from "zustand/shallow";
import { useCodeSelection } from "../components/CodeSelectionMenu";
import { registerAutocompletion } from "../ai-assistant/autocompletion";
import { registerEditor, unregisterEditor } from "../utils/editorNavigation";
Expand Down Expand Up @@ -124,12 +125,13 @@ export default function ConcertoEditor({
}: ConcertoEditorProps) {
const { handleSelection, MenuComponent } = useCodeSelection("concerto");
const monacoInstance = useMonaco();
const localEditorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
const { error, backgroundColor, aiConfig, showLineNumbers } = useAppStore((state) => ({
error: state.error,
backgroundColor: state.backgroundColor,
aiConfig: state.aiConfig,
showLineNumbers: state.showLineNumbers,
}));
}), shallow);
const ctoErr = error?.startsWith("c:") ? error : undefined;

const themeName = useMemo(
Expand Down Expand Up @@ -165,6 +167,7 @@ export default function ConcertoEditor({
}), [aiConfig?.enableInlineSuggestions, showLineNumbers]);

const handleEditorDidMount = (editor: monaco.editor.IStandaloneCodeEditor) => {
localEditorRef.current = editor;
if (editorRef) {
editorRef.current = editor;
}
Expand All @@ -190,7 +193,9 @@ export default function ConcertoEditor({
useEffect(() => {
if (!monacoInstance) return;

const model = monacoInstance.editor.getModels()?.[0];
const editor = localEditorRef.current;
if (!editor) return;
const model = editor.getModel();
if (!model) return;

if (ctoErr) {
Expand Down
3 changes: 2 additions & 1 deletion src/editors/JSONEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { lazy, Suspense, useMemo, useCallback, useEffect } from "react";
import * as monaco from "monaco-editor";
import useAppStore from "../store/store";
import { shallow } from "zustand/shallow";
import { useCodeSelection } from "../components/CodeSelectionMenu";
import { registerAutocompletion } from "../ai-assistant/autocompletion";
import { registerEditor, unregisterEditor } from "../utils/editorNavigation";
Expand All @@ -24,7 +25,7 @@ export default function JSONEditor({
backgroundColor: state.backgroundColor,
aiConfig: state.aiConfig,
showLineNumbers: state.showLineNumbers,
}));
}), shallow);

const themeName = useMemo(
() => (backgroundColor ? "darkTheme" : "lightTheme"),
Expand Down
3 changes: 2 additions & 1 deletion src/editors/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { lazy, Suspense, useMemo, useCallback, useEffect, MutableRefObject } from "react";
import useAppStore from "../store/store";
import { shallow } from "zustand/shallow";
import { useMonaco } from "@monaco-editor/react";
import { useCodeSelection } from "../components/CodeSelectionMenu";
import type { editor } from "monaco-editor";
Expand Down Expand Up @@ -28,7 +29,7 @@ export default function MarkdownEditor({
textColor: state.textColor,
aiConfig: state.aiConfig,
showLineNumbers: state.showLineNumbers,
}));
}), shallow);
const monaco = useMonaco();

const themeName = useMemo(
Expand Down