Spaces:
Running
Running
Update src/App.tsx
Browse files- src/App.tsx +68 -4
src/App.tsx
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
-
// src/App.tsx
|
2 |
-
|
|
|
3 |
import './App.scss';
|
|
|
4 |
import { AppProvider, useAppContext, PersonalityType, PersonalityInstructions } from "./contexts/AppContext";
|
5 |
import ControlTray from "./components/control-tray/ControlTray";
|
6 |
import { IOSModal } from "./components/ios-modal/IOSModal";
|
@@ -8,9 +10,71 @@ import { isIOS } from "./lib/platform";
|
|
8 |
import cn from "classnames";
|
9 |
import Logo from "./components/logo/Logo";
|
10 |
import { LiveConfig } from "./multimodal-live-types";
|
11 |
-
import { CustomModal } from "./components/CustomModal";
|
12 |
|
13 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
const PersonalityMenu: React.FC<{ isOpen: boolean; onClose: () => void; onSelect: (p: PersonalityType) => void; }> = ({ isOpen, onClose, onSelect }) => {
|
15 |
const menuRef = useRef<HTMLDivElement>(null);
|
16 |
const { selectedPersonality } = useAppContext();
|
|
|
1 |
+
// src/App.tsx (نسخه یکپارچه و نهایی)
|
2 |
+
|
3 |
+
import React, { useEffect, useRef, useState, FC } from "react";
|
4 |
import './App.scss';
|
5 |
+
// AppContext را از مسیر درست ایمپورت میکنیم
|
6 |
import { AppProvider, useAppContext, PersonalityType, PersonalityInstructions } from "./contexts/AppContext";
|
7 |
import ControlTray from "./components/control-tray/ControlTray";
|
8 |
import { IOSModal } from "./components/ios-modal/IOSModal";
|
|
|
10 |
import cn from "classnames";
|
11 |
import Logo from "./components/logo/Logo";
|
12 |
import { LiveConfig } from "./multimodal-live-types";
|
|
|
13 |
|
14 |
+
// ===================================================================
|
15 |
+
// START: کامپوننت مودال مستقیماً اینجا تعریف شده است
|
16 |
+
// ===================================================================
|
17 |
+
interface CustomModalProps {
|
18 |
+
isOpen: boolean;
|
19 |
+
onClose: () => void;
|
20 |
+
onSave: (name: string, instructions: string) => void;
|
21 |
+
initialName: string;
|
22 |
+
initialInstructions: string;
|
23 |
+
}
|
24 |
+
|
25 |
+
const CustomModal: FC<CustomModalProps> = ({ isOpen, onClose, onSave, initialName, initialInstructions }) => {
|
26 |
+
const [name, setName] = useState(initialName);
|
27 |
+
const [instructions, setInstructions] = useState(initialInstructions);
|
28 |
+
|
29 |
+
useEffect(() => {
|
30 |
+
if (isOpen) {
|
31 |
+
setName(initialName);
|
32 |
+
setInstructions(initialInstructions);
|
33 |
+
}
|
34 |
+
}, [isOpen, initialName, initialInstructions]);
|
35 |
+
|
36 |
+
if (!isOpen) return null;
|
37 |
+
|
38 |
+
const handleSave = () => {
|
39 |
+
if (name.trim() && instructions.trim()) {
|
40 |
+
onSave(name.trim(), instructions.trim());
|
41 |
+
onClose();
|
42 |
+
} else {
|
43 |
+
alert("لطفا نام و دستورالعملها را وارد کنید.");
|
44 |
+
}
|
45 |
+
};
|
46 |
+
|
47 |
+
return (
|
48 |
+
<div className="modal-overlay" onClick={onClose}>
|
49 |
+
<div className="modal-content" onClick={(e) => e.stopPropagation()}>
|
50 |
+
<div className="modal-header">
|
51 |
+
<h3>ساخت شخصیت اختصاصی</h3>
|
52 |
+
<button className="close-button" onClick={onClose}>×</button>
|
53 |
+
</div>
|
54 |
+
<div className="modal-body">
|
55 |
+
<div className="form-group">
|
56 |
+
<label htmlFor="name">نام شما (برای صدا زدن)</label>
|
57 |
+
<input id="name" type="text" placeholder="مثلا: علی" value={name} onChange={(e) => setName(e.target.value)} />
|
58 |
+
</div>
|
59 |
+
<div className="form-group">
|
60 |
+
<label htmlFor="instructions">دستورالعملهای شخصیت</label>
|
61 |
+
<textarea id="instructions" placeholder="مثلا: خیلی خودمونی و بامزه صحبت کن..." value={instructions} onChange={(e) => setInstructions(e.target.value)} rows={6} />
|
62 |
+
<small>اینجا فقط رفتار و سبک صحبت کردن دستیار را مشخص کنید.</small>
|
63 |
+
</div>
|
64 |
+
</div>
|
65 |
+
<div className="modal-footer">
|
66 |
+
<button className="save-button" onClick={handleSave}>ذخیره و فعالسازی</button>
|
67 |
+
</div>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
);
|
71 |
+
};
|
72 |
+
// ===================================================================
|
73 |
+
// END: تعریف کامپوننت مودال
|
74 |
+
// ===================================================================
|
75 |
+
|
76 |
+
|
77 |
+
// کامپوننت منوی شخصیتها (به صورت یک کامپوننت داخلی ساده)
|
78 |
const PersonalityMenu: React.FC<{ isOpen: boolean; onClose: () => void; onSelect: (p: PersonalityType) => void; }> = ({ isOpen, onClose, onSelect }) => {
|
79 |
const menuRef = useRef<HTMLDivElement>(null);
|
80 |
const { selectedPersonality } = useAppContext();
|