Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit c164f9b

Browse files
committed
fix for sounds, added EIP
1 parent e901a28 commit c164f9b

9 files changed

Lines changed: 59 additions & 123 deletions

File tree

src/frontend/components/modals/FileBrowserModal.tsx

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,6 @@ import DocumentView from './DocumentView';
2828
import { Button } from '../ui/button';
2929
import { useAppNavigate } from '@/lib/navigation';
3030

31-
// Import placeholder images
32-
import placeholder1 from '../../assets/placeholders/placeholder (1).png';
33-
import placeholder7 from '../../assets/placeholders/placeholder (7).png';
34-
import placeholder8 from '../../assets/placeholders/placeholder (8).png';
35-
import placeholder9 from '../../assets/placeholders/placeholder (9).png';
36-
import placeholder10 from '../../assets/placeholders/placeholder (10).png';
37-
import placeholder11 from '../../assets/placeholders/placeholder (11).png';
38-
import placeholder12 from '../../assets/placeholders/placeholder (12).png';
39-
import placeholder13 from '../../assets/placeholders/placeholder (13).png';
40-
import placeholder14 from '../../assets/placeholders/placeholder (14).png';
41-
import placeholder15 from '../../assets/placeholders/placeholder (15).png';
42-
import placeholder16 from '../../assets/placeholders/placeholder (16).png';
43-
import placeholder17 from '../../assets/placeholders/placeholder (17).png';
44-
import placeholder18 from '../../assets/placeholders/placeholder (18).png';
45-
import placeholder19 from '../../assets/placeholders/placeholder (19).png';
46-
import placeholder20 from '../../assets/placeholders/placeholder (20).png';
47-
import placeholder21 from '../../assets/placeholders/placeholder (21).png';
48-
49-
// Pool placeholder images once rather than for each component
50-
const placeholderImages = [
51-
placeholder1, placeholder7, placeholder8, placeholder9, placeholder10,
52-
placeholder11, placeholder12, placeholder13, placeholder14, placeholder15,
53-
placeholder16, placeholder17, placeholder18, placeholder19, placeholder20,
54-
placeholder21
55-
];
56-
5731
// Moved to outside component to prevent recreation
5832
const fileTypeTags = ['pdf', 'word', 'txt', 'powerpoint', 'epub'];
5933

@@ -200,19 +174,17 @@ const UserSkeleton = memo(() => (
200174
));
201175
UserSkeleton.displayName = 'UserSkeleton';
202176

203-
// Get document placeholder - optimized to be more efficient
204-
const getDocumentPlaceholder = (docId: string) => {
205-
// Use the document ID to generate a consistent index
206-
const charSum = docId.split('').reduce((sum, char) => sum + char.charCodeAt(0), 0);
207-
const index = charSum % placeholderImages.length;
208-
return placeholderImages[index];
209-
};
210-
211177
// Function to render thumbnail from color:text format
212178
const renderThumbnail = (thumbnailData: string, title: string) => {
213179
// Parse the thumbnail format "color:text"
214180
const [color, text] = thumbnailData.split(':');
215181

182+
if (thumbnailData.startsWith('https://')) {
183+
return (
184+
<img src={thumbnailData} alt={title} className="w-full h-full object-cover" />
185+
);
186+
}
187+
216188
return (
217189
<div
218190
style={{ backgroundColor: color }}
@@ -288,12 +260,6 @@ const DocumentItem = memo(({ document, selectedTags, handleTagClick, navigateToD
288260
bookmarkResults.some(bookmark => bookmark.id === document.id),
289261
[document.id, bookmarkResults]
290262
);
291-
292-
// Memoize expensive parts
293-
const documentPlaceholder = useMemo(() =>
294-
getDocumentPlaceholder(document.id),
295-
[document.id]
296-
);
297263

298264
const formattedDate = useMemo(() =>
299265
formatDate(displayDoc.uploadDate),

src/frontend/components/modals/ReadingSpeedTestModal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { Modal } from '../ui/modal';
1919
import { toast } from '@/lib/utils/toast';
2020
import { useReadingSpeed, type ReadingTestResult } from '@/lib/contexts/ReadingSpeedContext';
21+
import { playSound } from '@/lib/utils/sound';
2122

2223
interface ReadingSpeedTestModalProps {
2324
isOpen: boolean;
@@ -202,11 +203,7 @@ const ReadingSpeedTestModal: React.FC<ReadingSpeedTestModalProps> = ({ isOpen, o
202203

203204
setTestState('results');
204205
setIsLoading(false);
205-
206-
toast.success("Test di velocità di lettura completato!", {
207-
description: `La tua velocità di lettura: ${finalWpm} PPM con ${accuracy}% di comprensione`,
208-
icon: <CheckCircleIcon size={16} />,
209-
});
206+
playSound();
210207
}, [startTime, endTime, selectedTopic, questionsAnswered, questions, updateReadingSpeed]);
211208

212209
// Cleanup on unmount

src/frontend/components/modals/SearchModal.tsx

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,6 @@ import { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider, TooltipConten
3030
import DocumentView from './DocumentView';
3131
import { useAppNavigate } from '@/lib/navigation';
3232

33-
// Import placeholder images
34-
import placeholder1 from '../../assets/placeholders/placeholder (1).png';
35-
import placeholder7 from '../../assets/placeholders/placeholder (7).png';
36-
import placeholder8 from '../../assets/placeholders/placeholder (8).png';
37-
import placeholder9 from '../../assets/placeholders/placeholder (9).png';
38-
import placeholder10 from '../../assets/placeholders/placeholder (10).png';
39-
import placeholder11 from '../../assets/placeholders/placeholder (11).png';
40-
import placeholder12 from '../../assets/placeholders/placeholder (12).png';
41-
import placeholder13 from '../../assets/placeholders/placeholder (13).png';
42-
import placeholder14 from '../../assets/placeholders/placeholder (14).png';
43-
import placeholder15 from '../../assets/placeholders/placeholder (15).png';
44-
import placeholder16 from '../../assets/placeholders/placeholder (16).png';
45-
import placeholder17 from '../../assets/placeholders/placeholder (17).png';
46-
import placeholder18 from '../../assets/placeholders/placeholder (18).png';
47-
import placeholder19 from '../../assets/placeholders/placeholder (19).png';
48-
import placeholder20 from '../../assets/placeholders/placeholder (20).png';
49-
import placeholder21 from '../../assets/placeholders/placeholder (21).png';
50-
51-
// Pool placeholder images once rather than for each component
52-
const placeholderImages = [
53-
placeholder1, placeholder7, placeholder8, placeholder9, placeholder10,
54-
placeholder11, placeholder12, placeholder13, placeholder14, placeholder15,
55-
placeholder16, placeholder17, placeholder18, placeholder19, placeholder20,
56-
placeholder21
57-
];
58-
5933
// Moved to outside component to prevent recreation
6034
const fileTypeTags = ['pdf', 'word', 'txt', 'powerpoint', 'epub'];
6135

@@ -219,19 +193,17 @@ const UserSkeleton = memo(() => (
219193
));
220194
UserSkeleton.displayName = 'UserSkeleton';
221195

222-
// Get document placeholder - optimized to be more efficient
223-
const getDocumentPlaceholder = (docId: string) => {
224-
// Use the document ID to generate a consistent index
225-
const charSum = docId.split('').reduce((sum, char) => sum + char.charCodeAt(0), 0);
226-
const index = charSum % placeholderImages.length;
227-
return placeholderImages[index];
228-
};
229-
230196
// Function to render thumbnail from color:text format
231197
const renderThumbnail = (thumbnailData: string, title: string) => {
232198
// Parse the thumbnail format "color:text"
233199
const [color, text] = thumbnailData.split(':');
234200

201+
if (thumbnailData.startsWith('https://')) {
202+
return (
203+
<img src={thumbnailData} alt={title} className="w-full h-full object-cover" />
204+
);
205+
}
206+
235207
return (
236208
<div
237209
style={{ backgroundColor: color }}
@@ -285,12 +257,6 @@ const DocumentItem = memo(({ document, selectedTags, handleTagClick, navigateToD
285257
bookmarkResults.some(bookmark => bookmark.id === document.id),
286258
[document.id, bookmarkResults]
287259
);
288-
289-
// Memoize expensive parts
290-
const documentPlaceholder = useMemo(() =>
291-
getDocumentPlaceholder(document.id),
292-
[document.id]
293-
);
294260

295261
const formattedDate = useMemo(() =>
296262
formatDate(displayDoc.uploadDate),
@@ -591,7 +557,7 @@ const UserItem = memo(({
591557
</div>
592558
<Button variant="outline" size="sm" className="gap-2 hover-primary-effect cursor-pointer" onClick={() => navigateToUserProfile(user.username)}>
593559
<User size={14} />
594-
View Profile
560+
Visualizza Profilo
595561
</Button>
596562
</div>
597563

src/frontend/components/pages/Document.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ const Document = () => {
152152
const renderThumbnail = useCallback((thumbnailData: string) => {
153153
const [color, text] = thumbnailData.split(':');
154154

155+
if (thumbnailData.startsWith('https://')) {
156+
return (
157+
<img src={thumbnailData} className="w-full h-full object-cover" />
158+
);
159+
}
160+
155161
return (
156162
<div
157163
style={{ backgroundColor: color }}
@@ -322,29 +328,8 @@ const Document = () => {
322328
if (readingSpeed.isFirstTestCompleted && !readingSpeed.hasInteractedWithTimerAfterFirstTest) {
323329
markTimerInteractionAfterFirstTest();
324330
}
325-
326-
if (duration) {
327-
toast.success("Durata timer impostata", {
328-
description: `Timer di lettura impostato a ${duration} minuti`,
329-
icon: <TimerIcon size={16} />,
330-
});
331-
} else {
332-
toast.success("Timer disabilitato", {
333-
description: "Il documento si aprirà senza timer",
334-
icon: <TimerIcon size={16} />,
335-
});
336-
}
337331
}, [readingSpeed.isFirstTestCompleted, readingSpeed.hasInteractedWithTimerAfterFirstTest, markTimerInteractionAfterFirstTest]);
338332

339-
// Handle timer duration change from ReadingTimer component
340-
const handleTimerDurationChange = useCallback((newDurationMinutes: number) => {
341-
setSelectedTimerDuration(newDurationMinutes);
342-
toast.success("Durata timer aggiornata", {
343-
description: `Timer di lettura aggiornato a ${newDurationMinutes} minuti`,
344-
icon: <TimerIcon size={16} />,
345-
});
346-
}, []);
347-
348333
// Handle document opening with timer
349334
const handleOpenDocument = useCallback(() => {
350335
if (selectedTimerDuration) {

src/frontend/components/pages/Home.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ const Home = () => {
191191
// Parse the thumbnail format "color:text"
192192
const [color, text] = thumbnailData.split(':');
193193

194+
if (thumbnailData.startsWith('https://')) {
195+
return (
196+
<img src={thumbnailData} alt={title} className="w-full h-full object-cover" />
197+
);
198+
}
199+
194200
return (
195201
<div
196202
style={{ backgroundColor: color }}

src/frontend/components/pages/Profile.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import EditProfileModal from '../modals/EditProfileModal';
4848
import UploadDocumentModal from '../modals/UploadDocumentModal';
4949
import { Switch } from '../ui/switch';
5050
import { Separator } from '../ui/separator';
51+
import { playSound } from '@/lib/utils/sound';
5152

5253
const Profile = () => {
5354
const appNavigate = useAppNavigate();
@@ -176,6 +177,12 @@ const Profile = () => {
176177
const renderThumbnail = useCallback((thumbnailData: string, title: string) => {
177178
const [color, text] = thumbnailData.split(':');
178179

180+
if (thumbnailData.startsWith('https://')) {
181+
return (
182+
<img src={thumbnailData} className="w-full h-full object-cover" />
183+
);
184+
}
185+
179186
return (
180187
<div
181188
style={{ backgroundColor: color }}
@@ -404,11 +411,6 @@ const Profile = () => {
404411

405412
// Add the new document to the beginning of the user documents list
406413
setUserDocuments(prev => [newDocument, ...prev]);
407-
408-
toast.success("Documento caricato con successo", {
409-
description: `"${documentData.title}" è stato caricato nella tua collezione`,
410-
icon: <FileTextIcon size={16} />,
411-
});
412414
}, [currentUser]);
413415

414416
// Scroll to section top functions

src/frontend/components/pages/UserProfile.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ const UserProfile = () => {
127127
const renderThumbnail = useCallback((thumbnailData: string, title: string) => {
128128
const [color, text] = thumbnailData.split(':');
129129

130+
if (thumbnailData.startsWith('https://')) {
131+
return (
132+
<img src={thumbnailData} className="w-full h-full object-cover" />
133+
);
134+
}
135+
130136
return (
131137
<div
132138
style={{ backgroundColor: color }}

src/frontend/components/ui/ReadingTimer.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ const ReadingTimer: React.FC<ReadingTimerProps> = ({
175175

176176
// Start the timer immediately
177177
intervalRef.current = createTimerInterval();
178-
179-
toast.success("Timer riavviato!", {
180-
description: `Timer ripristinato a ${initialDuration} minuti e avviato`,
181-
icon: <RotateCcwIcon size={16} />
182-
});
178+
playSound();
183179
}, [initialDuration, createTimerInterval]);
184180

185181
// Clean up interval on unmount

src/frontend/lib/mocking/mockedData.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class MockDataStore {
9999
'Gilgamesh: Il Primo Eroe Epico del Mondo',
100100
'Il Principe di Machiavelli: Politica di Potere Ieri e Oggi',
101101
'Don Chisciotte: Cervantes e la Nascita del Romanzo Moderno',
102-
'Beowulf: L\'Epica Inglese più Antica'
102+
'Beowulf: L\'Epica Inglese più Antica',
103+
'Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions'
103104
];
104105

105106
const documentDescriptions = [
@@ -114,7 +115,8 @@ class MockDataStore {
114115
'Analizzando l\'Epopea di Gilgamesh come la prima opera di grande letteratura sopravvissuta.',
115116
'Esaminando il controverso trattato politico di Niccolò Machiavelli sul potere e il governo.',
116117
'Uno studio approfondito del romanzo rivoluzionario di Miguel de Cervantes e il suo posto nella tradizione letteraria europea.',
117-
'Un\'analisi approfondita del poema epico eroico inglese antico Beowulf e il suo significato culturale.'
118+
'Un\'analisi approfondita del poema epico eroico inglese antico Beowulf e il suo significato culturale.',
119+
'This is a book about enterprise integration using messaging. It does not document any particular technology or product. Rather, it is designed for developers and integrators using a variety of messaging products and technologies, such as ActiveMQ, IBM MQ, JMS, and others.'
118120
];
119121

120122
const tagsPool = [
@@ -129,23 +131,33 @@ class MockDataStore {
129131
['mesopotamia', 'epico', 'poesia', 'antico'],
130132
['machiavelli', 'politica', 'rinascimento'],
131133
['spagnolo', 'letteratura', 'rinascimento', 'cervantes'],
132-
['medievale', 'inglese-antico', 'epico', 'poesia']
134+
['medievale', 'inglese-antico', 'epico', 'poesia'],
135+
['java', 'enterprise', 'integration', 'messaging', 'jms', 'activemq', 'ibm', 'mq']
133136
];
134137

135138
const fileTypes: ('pdf' | 'word' | 'powerpoint' | 'txt' | 'epub')[] = [
136139
'pdf', 'epub', 'pdf', 'pdf', 'epub', 'pdf',
137-
'pdf', 'epub', 'pdf', 'pdf', 'epub', 'pdf'
140+
'pdf', 'epub', 'pdf', 'pdf', 'epub', 'pdf',
141+
'pdf'
138142
];
139143

140-
for (let i = 0; i < 12; i++) {
144+
for (let i = 0; i < 13; i++) {
141145
const userIndex = i % this.users.length;
142146
const author = this.users[userIndex];
147+
148+
let thumbnail;
149+
150+
if (i === 12) {
151+
thumbnail = 'https://atom7.xyz/share/u/PIQppbz2.png';
152+
} else {
153+
thumbnail = `${faker.color.rgb({ format: 'hex', casing: 'lower' })}:${encodeURIComponent(documentTitles[i].split(':')[0])}`;
154+
}
143155

144156
// Create the file first
145157
const file: MockFile = {
146158
id: faker.string.uuid(),
147159
author: author,
148-
thumbnail: `${faker.color.rgb({ format: 'hex', casing: 'lower' })}:${encodeURIComponent(documentTitles[i].split(':')[0])}`,
160+
thumbnail: thumbnail,
149161
type: fileTypes[i],
150162
size: `${faker.number.float({ min: 1, max: 15, fractionDigits: 1 })} MB`,
151163
viewCount: i === 3 ? 15000 : faker.number.int({ min: 500, max: 5000 }),

0 commit comments

Comments
 (0)