Public Access
feat(library): add not the same game button to editions
Part of Gitea #34 slice 1 of 3: one entry per game across platforms. Status, rating and notes are shared, so the detail page reloads after a save.
This commit is contained in:
1 parent
e136a7abc1
commit
25cc5ff2d8
7 files changed
+107
-14
No files matched your search
@@ -1,37 +1,38 @@
|
||||
import {useState} from 'react';
|
||||
import {Link} from 'react-router-dom';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {Layers, Link2Off} from 'lucide-react';
|
||||
import {Layers, Link2Off, Unlink} from 'lucide-react';
|
||||
import {toast} from 'sonner';
|
||||
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Card} from '@/components/ui/card';
|
||||
import GameStatusBadge from './GameStatusBadge.jsx';
|
||||
import FitText from './FitText.jsx';
|
||||
import {unlinkGame} from '../utils/links.js';
|
||||
import {splitGame, unlinkGame} from '../utils/links.js';
|
||||
import {platformLabel} from '../utils/platforms.js';
|
||||
|
||||
/**
|
||||
* The other editions of this game in the own library, and the buttons to ask for a link (everyone) or to unlink
|
||||
* (auditor). Shown on every game: a request must be possible from any game.
|
||||
* The other editions of this game in the own library, and the buttons to ask for a link (everyone), to split the game
|
||||
* off its set (everyone, for the own library) or to unlink (auditor). Shown on every game: a request must be possible
|
||||
* from any game.
|
||||
*/
|
||||
export default function EditionsCard({game, auditor, onRequest, onChanged}) {
|
||||
const {t} = useTranslation();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const unlink = async () => {
|
||||
const run = async (call, doneKey) => {
|
||||
setBusy(true);
|
||||
try {
|
||||
const response = await unlinkGame(game.appid);
|
||||
const response = await call(game.appid);
|
||||
if (response.status === 401) return;
|
||||
if (response.ok) {
|
||||
toast.success(t('LINKS.UNLINKED'));
|
||||
toast.success(t(doneKey));
|
||||
onChanged();
|
||||
} else {
|
||||
toast.error(t('LINKS.ERROR'));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Unlink error:', err);
|
||||
console.error('Edition change error:', err);
|
||||
toast.error(t('INFO.ERROR.NETWORK_FAILURE'));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
@@ -56,14 +57,22 @@ export default function EditionsCard({game, auditor, onRequest, onChanged}) {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="text-muted-foreground">{t('LINKS.SHARED_STATUS')}</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="button" variant="outline" size="sm" onClick={onRequest}>
|
||||
<Layers/>{t(auditor ? 'LINKS.LINK_WITH' : 'LINKS.SAME_AS')}
|
||||
</Button>
|
||||
{game.editions?.length > 0 && (
|
||||
<Button type="button" variant="outline" size="sm" disabled={busy}
|
||||
onClick={() => run(splitGame, 'LINKS.SPLIT_DONE')}>
|
||||
<Unlink/>{t('LINKS.SPLIT')}
|
||||
</Button>
|
||||
)}
|
||||
{auditor && game.linked && (
|
||||
<Button type="button" variant="outline" size="sm" disabled={busy} onClick={unlink}>
|
||||
<Button type="button" variant="outline" size="sm" disabled={busy}
|
||||
onClick={() => run(unlinkGame, 'LINKS.UNLINKED')}>
|
||||
<Link2Off/>{t('LINKS.UNLINK')}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user