Ezmary commited on
Commit
9b55c0b
·
verified ·
1 Parent(s): 7daa6bf

Update src/App.tsx

Browse files
Files changed (1) hide show
  1. src/App.tsx +15 -20
src/App.tsx CHANGED
@@ -14,7 +14,7 @@ limitations under the License.
14
  */
15
 
16
  import React, { useEffect, useRef, useState } from "react";
17
- import './App.scss';
18
  import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
19
  import ControlTray from "./components/control-tray/ControlTray";
20
  import { IOSModal } from "./components/ios-modal/IOSModal";
@@ -22,6 +22,7 @@ import { isIOS } from "./lib/platform";
22
  import cn from "classnames";
23
  import { LiveConfig } from "./multimodal-live-types";
24
  import LogoAnimation from "./components/logo-animation/LogoAnimation";
 
25
 
26
  const myCustomInstruction = `
27
  ت1. هویت دستیار:
@@ -121,7 +122,7 @@ const AppInternalLogic: React.FC<{
121
  setIsCamActive: React.Dispatch<React.SetStateAction<boolean>>;
122
  videoRef: React.RefObject<HTMLVideoElement>;
123
  notificationPopoverRef: React.RefObject<HTMLDivElement>;
124
- notificationButtonRef: React.RefObject<HTMLButtonElement>;
125
  isNotificationOpen: boolean;
126
  setIsNotificationOpen: React.Dispatch<React.SetStateAction<boolean>>;
127
  }> = ({
@@ -131,7 +132,7 @@ const AppInternalLogic: React.FC<{
131
  setIsCamActive,
132
  videoRef,
133
  notificationPopoverRef,
134
- notificationButtonRef,
135
  isNotificationOpen,
136
  setIsNotificationOpen
137
  }) => {
@@ -146,26 +147,18 @@ const AppInternalLogic: React.FC<{
146
  return (
147
  <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
148
  <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
149
- {/* *** MODIFIED: ترتیب دکمه‌های هدر عوض شد *** */}
150
  <div className="header-controls">
151
- {/* دکمه بازگشت (حالا سمت چپ) */}
152
  <div className="back-button-container">
153
- <button
154
- id="back-button"
155
- aria-label="Go back"
156
- className="header-button"
157
- onClick={() => alert('Back clicked (implement navigation)')}
158
- >
159
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m15 18-6-6 6-6"></path></svg>
160
- </button>
161
  </div>
162
  {/* دکمه نوتیفیکیشن (حالا سمت راست) */}
163
  <div id="notification-trigger-container">
164
  <button
165
- ref={notificationButtonRef}
166
  id="notification-button"
167
  aria-label="Notifications"
168
- className="header-button"
169
  onClick={(e) => {
170
  e.stopPropagation();
171
  setIsNotificationOpen(!isNotificationOpen);
@@ -235,8 +228,11 @@ function App() {
235
  const [isCamActive, setIsCamActive] = useState(false);
236
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);
237
 
 
 
 
238
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
239
- const notificationButtonRef = useRef<HTMLButtonElement>(null); // این ref هنوز برای دکمه نوتیفیکیشن استفاده می‌شود
240
 
241
  useEffect(() => {
242
  if (isIOS()) {
@@ -250,12 +246,11 @@ function App() {
250
 
251
  useEffect(() => {
252
  const handleClickOutside = (event: MouseEvent) => {
253
- // منطق بستن پاپ‌اور نوتیفیکیشن با کلیک بیرون، همچنان باید روی notificationButtonRef کار کند
254
  if (
255
  isNotificationOpen &&
256
  notificationPopoverRef.current &&
257
  !notificationPopoverRef.current.contains(event.target as Node) &&
258
- notificationButtonRef.current && // اطمینان از اینکه ref دکمه نوتیفیکیشن هنوز معتبر است
259
  !notificationButtonRef.current.contains(event.target as Node)
260
  ) {
261
  setIsNotificationOpen(false);
@@ -265,7 +260,7 @@ function App() {
265
  return () => {
266
  document.removeEventListener("mousedown", handleClickOutside);
267
  };
268
- }, [isNotificationOpen]);
269
 
270
  if (isAllowedOrigin === null) {
271
  return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
@@ -280,7 +275,7 @@ function App() {
280
  setIsCamActive={setIsCamActive}
281
  videoRef={videoRef}
282
  notificationPopoverRef={notificationPopoverRef}
283
- notificationButtonRef={notificationButtonRef} // پاس دادن ref دکمه نوتیفیکیشن
284
  isNotificationOpen={isNotificationOpen}
285
  setIsNotificationOpen={setIsNotificationOpen}
286
  />
 
14
  */
15
 
16
  import React, { useEffect, useRef, useState } from "react";
17
+ import './App.scss'; // استایل‌های اصلی
18
  import { LiveAPIProvider, useLiveAPIContext } from "./contexts/LiveAPIContext";
19
  import ControlTray from "./components/control-tray/ControlTray";
20
  import { IOSModal } from "./components/ios-modal/IOSModal";
 
22
  import cn from "classnames";
23
  import { LiveConfig } from "./multimodal-live-types";
24
  import LogoAnimation from "./components/logo-animation/LogoAnimation";
25
+ import BackButton from "./components/back-button/BackButton"; // <<-- ایمپورت کامپوننت جدید دکمه بازگشت
26
 
27
  const myCustomInstruction = `
28
  ت1. هویت دستیار:
 
122
  setIsCamActive: React.Dispatch<React.SetStateAction<boolean>>;
123
  videoRef: React.RefObject<HTMLVideoElement>;
124
  notificationPopoverRef: React.RefObject<HTMLDivElement>;
125
+ notificationButtonRef: React.RefObject<HTMLButtonElement>; // این ref برای دکمه نوتیفیکیشن است
126
  isNotificationOpen: boolean;
127
  setIsNotificationOpen: React.Dispatch<React.SetStateAction<boolean>>;
128
  }> = ({
 
132
  setIsCamActive,
133
  videoRef,
134
  notificationPopoverRef,
135
+ notificationButtonRef, // دریافت ref
136
  isNotificationOpen,
137
  setIsNotificationOpen
138
  }) => {
 
147
  return (
148
  <div className="w-full flex flex-col items-center justify-center min-h-screen text-foreground antialiased">
149
  <div className="main-wrapper max-w-3xl w-full flex flex-col items-center justify-center h-full relative">
 
150
  <div className="header-controls">
151
+ {/* دکمه بازگشت جدید (حالا سمت چپ) */}
152
  <div className="back-button-container">
153
+ <BackButton /> {/* <<-- استفاده از کامپوننت جدید */}
 
 
 
 
 
 
 
154
  </div>
155
  {/* دکمه نوتیفیکیشن (حالا سمت راست) */}
156
  <div id="notification-trigger-container">
157
  <button
158
+ ref={notificationButtonRef} // ref به این دکمه متصل است
159
  id="notification-button"
160
  aria-label="Notifications"
161
+ className="header-button" // کلاس برای ظاهر مشابه
162
  onClick={(e) => {
163
  e.stopPropagation();
164
  setIsNotificationOpen(!isNotificationOpen);
 
228
  const [isCamActive, setIsCamActive] = useState(false);
229
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);
230
 
231
+ // ref برای دکمه نوتیفیکیشن باید در کامپوننت App تعریف شود
232
+ // چون state مربوط به isNotificationOpen در App مدیریت می‌شود
233
+ const notificationButtonRef = useRef<HTMLButtonElement>(null);
234
  const notificationPopoverRef = useRef<HTMLDivElement>(null);
235
+
236
 
237
  useEffect(() => {
238
  if (isIOS()) {
 
246
 
247
  useEffect(() => {
248
  const handleClickOutside = (event: MouseEvent) => {
 
249
  if (
250
  isNotificationOpen &&
251
  notificationPopoverRef.current &&
252
  !notificationPopoverRef.current.contains(event.target as Node) &&
253
+ notificationButtonRef.current &&
254
  !notificationButtonRef.current.contains(event.target as Node)
255
  ) {
256
  setIsNotificationOpen(false);
 
260
  return () => {
261
  document.removeEventListener("mousedown", handleClickOutside);
262
  };
263
+ }, [isNotificationOpen]); // وابستگی به isNotificationOpen صحیح است
264
 
265
  if (isAllowedOrigin === null) {
266
  return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
 
275
  setIsCamActive={setIsCamActive}
276
  videoRef={videoRef}
277
  notificationPopoverRef={notificationPopoverRef}
278
+ notificationButtonRef={notificationButtonRef} // پاس دادن ref به AppInternalLogic
279
  isNotificationOpen={isNotificationOpen}
280
  setIsNotificationOpen={setIsNotificationOpen}
281
  />