Skip to content

Commit a110d86

Browse files
chore: remove all edit/delete/rename functionality from profile page game list
1 parent 6173f2f commit a110d86

1 file changed

Lines changed: 0 additions & 204 deletions

File tree

src/components/Profile/GameList.tsx

Lines changed: 0 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ import React, { useState, useEffect, useContext } from 'react'
44
import { AuthContext } from 'src/contexts'
55
import { MaiaGameListEntry } from 'src/types'
66
import { streamLichessGames, fetchMaiaGameList } from 'src/api'
7-
import { FavoriteModal } from 'src/components/Common/FavoriteModal'
8-
import {
9-
addFavoriteGame,
10-
removeFavoriteGame,
11-
getFavoritesAsWebGames,
12-
} from 'src/lib/favorites'
137

148
interface GameData {
159
game_id: string
@@ -53,20 +47,10 @@ export const GameList = ({
5347
favorites: {},
5448
})
5549

56-
const [favoriteGames, setFavoriteGames] = useState<MaiaGameListEntry[]>([])
57-
const [favoritedGameIds, setFavoritedGameIds] = useState<Set<string>>(
58-
new Set(),
59-
)
6050
const [currentPage, setCurrentPage] = useState(1)
6151
const [totalPages, setTotalPages] = useState(1)
6252
const [loading, setLoading] = useState(false)
6353

64-
// Modal state for favoriting
65-
const [favoriteModal, setFavoriteModal] = useState<{
66-
isOpen: boolean
67-
game: MaiaGameListEntry | null
68-
}>({ isOpen: false, game: null })
69-
7054
const [fetchedCache, setFetchedCache] = useState<{
7155
[key: string]: { [page: number]: boolean }
7256
}>({
@@ -91,20 +75,6 @@ export const GameList = ({
9175
favorites: 1,
9276
})
9377

94-
// Update custom analyses and favorites when component mounts
95-
useEffect(() => {
96-
// Load favorites (supports both sync and async implementations)
97-
Promise.resolve(getFavoritesAsWebGames())
98-
.then((favorites) => {
99-
setFavoriteGames(favorites)
100-
setFavoritedGameIds(new Set(favorites.map((f) => f.id)))
101-
})
102-
.catch(() => {
103-
setFavoriteGames([])
104-
setFavoritedGameIds(new Set())
105-
})
106-
}, [])
107-
10878
useEffect(() => {
10979
const targetUser = lichessId || user?.lichessId
11080
if (targetUser && showLichess && !fetchedCache.lichess[1]) {
@@ -212,14 +182,6 @@ export const GameList = ({
212182
},
213183
}))
214184

215-
// Update favoritedGameIds from the actual games data
216-
const favoritedIds = new Set(
217-
parsedGames
218-
.filter((game: any) => game.is_favorited)
219-
.map((game: any) => game.id),
220-
)
221-
setFavoritedGameIds((prev) => new Set([...prev, ...favoritedIds]))
222-
223185
setLoading(false)
224186
})
225187
.catch(() => {
@@ -298,104 +260,6 @@ export const GameList = ({
298260
setSelected(newTab)
299261
}
300262

301-
const handleFavoriteGame = (game: MaiaGameListEntry) => {
302-
setFavoriteModal({ isOpen: true, game })
303-
}
304-
305-
const handleSaveFavorite = async (customName: string) => {
306-
if (favoriteModal.game) {
307-
await addFavoriteGame(favoriteModal.game, customName)
308-
const updatedFavorites = await getFavoritesAsWebGames()
309-
setFavoriteGames(updatedFavorites)
310-
setFavoritedGameIds(new Set(updatedFavorites.map((f) => f.id)))
311-
312-
// Clear favorites cache to force re-fetch
313-
setFetchedCache((prev) => ({
314-
...prev,
315-
favorites: {},
316-
}))
317-
setGamesByPage((prev) => ({
318-
...prev,
319-
favorites: {},
320-
}))
321-
322-
// Also clear current section cache to show updated favorite status
323-
if (selected !== 'favorites') {
324-
const currentSection = selected === 'hb' ? hbSubsection : selected
325-
setFetchedCache((prev) => ({
326-
...prev,
327-
[currentSection]: {},
328-
}))
329-
setGamesByPage((prev) => ({
330-
...prev,
331-
[currentSection]: {},
332-
}))
333-
}
334-
}
335-
}
336-
337-
const handleRemoveFavorite = async () => {
338-
if (favoriteModal.game) {
339-
await removeFavoriteGame(favoriteModal.game.id, favoriteModal.game.type)
340-
const updatedFavorites = await getFavoritesAsWebGames()
341-
setFavoriteGames(updatedFavorites)
342-
setFavoritedGameIds(new Set(updatedFavorites.map((f) => f.id)))
343-
344-
// Clear favorites cache to force re-fetch
345-
setFetchedCache((prev) => ({
346-
...prev,
347-
favorites: {},
348-
}))
349-
setGamesByPage((prev) => ({
350-
...prev,
351-
favorites: {},
352-
}))
353-
354-
// Also clear current section cache to show updated favorite status
355-
if (selected !== 'favorites') {
356-
const currentSection = selected === 'hb' ? hbSubsection : selected
357-
setFetchedCache((prev) => ({
358-
...prev,
359-
[currentSection]: {},
360-
}))
361-
setGamesByPage((prev) => ({
362-
...prev,
363-
[currentSection]: {},
364-
}))
365-
}
366-
}
367-
}
368-
369-
const handleDirectUnfavorite = async (game: MaiaGameListEntry) => {
370-
await removeFavoriteGame(game.id, game.type)
371-
const updatedFavorites = await getFavoritesAsWebGames()
372-
setFavoriteGames(updatedFavorites)
373-
setFavoritedGameIds(new Set(updatedFavorites.map((f) => f.id)))
374-
375-
// Clear favorites cache to force re-fetch
376-
setFetchedCache((prev) => ({
377-
...prev,
378-
favorites: {},
379-
}))
380-
setGamesByPage((prev) => ({
381-
...prev,
382-
favorites: {},
383-
}))
384-
385-
// Also clear current section cache to show updated favorite status
386-
if (selected !== 'favorites') {
387-
const currentSection = selected === 'hb' ? hbSubsection : selected
388-
setFetchedCache((prev) => ({
389-
...prev,
390-
[currentSection]: {},
391-
}))
392-
setGamesByPage((prev) => ({
393-
...prev,
394-
[currentSection]: {},
395-
}))
396-
}
397-
}
398-
399263
const getCurrentGames = () => {
400264
if (selected === 'play') {
401265
return gamesByPage.play[currentPage] || []
@@ -410,26 +274,6 @@ export const GameList = ({
410274
return []
411275
}
412276

413-
const getModalCurrentName = () => {
414-
if (!favoriteModal.game) return ''
415-
416-
// If we're in the favorites section, the label is already the custom name
417-
if (selected === 'favorites') {
418-
return favoriteModal.game.label
419-
}
420-
421-
// For other sections, check if the game is favorited and get its custom name
422-
const favorite = favoriteGames.find(
423-
(fav) => fav.id === favoriteModal.game!.id,
424-
)
425-
if (favorite) {
426-
return favorite.label // In AnalysisWebGame, the label contains the custom name
427-
}
428-
429-
// Otherwise, use the game's label
430-
return favoriteModal.game.label
431-
}
432-
433277
return (
434278
<div className="flex w-full flex-col overflow-hidden rounded-md border border-glassBorder bg-glass md:w-[600px]">
435279
<div className="flex flex-row items-center justify-start gap-4 px-2 py-2 md:px-4">
@@ -535,7 +379,6 @@ export const GameList = ({
535379
) : (
536380
<>
537381
{getCurrentGames().map((game, index) => {
538-
const isFavorited = (game as any).is_favorited || false
539382
const displayName = game.label // This now contains the custom name if favorited
540383
return (
541384
<div
@@ -573,42 +416,6 @@ export const GameList = ({
573416
)}
574417
</div>
575418
<div className="flex items-center gap-2">
576-
{selected === 'favorites' && (
577-
<button
578-
onClick={(e) => {
579-
e.stopPropagation()
580-
handleFavoriteGame(game)
581-
}}
582-
className="flex items-center justify-center text-white/60 transition-colors duration-200 hover:text-white/90"
583-
title="Edit favourite"
584-
>
585-
<span className="material-symbols-outlined !text-xs">
586-
edit
587-
</span>
588-
</button>
589-
)}
590-
{selected !== 'favorites' && (
591-
<button
592-
onClick={(e) => {
593-
e.stopPropagation()
594-
handleFavoriteGame(game)
595-
}}
596-
className={`flex items-center justify-center transition-colors duration-200 ${
597-
isFavorited
598-
? 'text-yellow-400 hover:text-yellow-300'
599-
: 'text-white/60 hover:text-white/90'
600-
}`}
601-
title={
602-
isFavorited ? 'Edit favourite' : 'Add to favourites'
603-
}
604-
>
605-
<span
606-
className={`material-symbols-outlined !text-xs ${isFavorited ? 'material-symbols-filled' : ''}`}
607-
>
608-
star
609-
</span>
610-
</button>
611-
)}
612419
<p className="whitespace-nowrap text-sm text-white/70">
613420
{game.result.replace('1/2', '½').replace('1/2', '½')}
614421
</p>
@@ -667,17 +474,6 @@ export const GameList = ({
667474
</button>
668475
</div>
669476
)}
670-
<FavoriteModal
671-
isOpen={favoriteModal.isOpen}
672-
currentName={getModalCurrentName()}
673-
onClose={() => setFavoriteModal({ isOpen: false, game: null })}
674-
onSave={handleSaveFavorite}
675-
onRemove={
676-
favoriteModal.game && favoritedGameIds.has(favoriteModal.game.id)
677-
? handleRemoveFavorite
678-
: undefined
679-
}
680-
/>
681477
</div>
682478
)
683479
}

0 commit comments

Comments
 (0)