-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add progression status to dashboard
- Loading branch information
Showing
10 changed files
with
331 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Popover, Card, Stack, Group, Progress, Text } from '@mantine/core' | ||
import { useDisclosure } from '@mantine/hooks'; | ||
import { Resolution } from '@prisma/client'; | ||
|
||
import { useDeviceSize } from '~/hooks/use-device-size'; | ||
import { BREAKPOINT_MOBILE_LARGE, BREAKPOINT_DESKTOP_MEDIUM, BREAKPOINT_DESKTOP_LARGE } from '~/lib/constants' | ||
import { gradient } from '~/lib/utils' | ||
import type { ModVersionWithProgression } from '~/types'; | ||
|
||
export function ProgressionItem({ modVersion }: { modVersion: ModVersionWithProgression }) { | ||
const [opened, { close, open }] = useDisclosure(false); | ||
const [windowWidth, _] = useDeviceSize(); | ||
|
||
return ( | ||
<Popover width={200} position="bottom" withArrow shadow="md" opened={opened}> | ||
<Popover.Target> | ||
<Card | ||
onMouseEnter={open} | ||
onMouseLeave={close} | ||
withBorder | ||
shadow="0" | ||
className="dashboard-mod-progress" | ||
style={{ '--dashboard-mod-progress-count': windowWidth <= BREAKPOINT_MOBILE_LARGE | ||
? 1 | ||
: windowWidth <= BREAKPOINT_DESKTOP_MEDIUM | ||
? 2 | ||
: windowWidth <= BREAKPOINT_DESKTOP_LARGE | ||
? 3 | ||
: 4 }} | ||
> | ||
<Stack gap="0"> | ||
<Group justify="space-between"> | ||
<Text size="sm" fw={700}>{modVersion.mod.name}</Text> | ||
<Text size="xs" c="dimmed">{modVersion.version} — {modVersion.mcVersion}</Text> | ||
</Group> | ||
<Stack gap="sm"> | ||
{(Object.keys(modVersion.textures.done) as Resolution[]) | ||
.map((res, i) => ( | ||
<Stack key={i} gap="0"> | ||
<Text size="xs" c="dimmed"> | ||
Textures {res}: {modVersion.textures.done[res]} / {modVersion.textures.todo} | ||
{modVersion.textures.todo === modVersion.linkedTextures ? '' : `(linked: ${modVersion.linkedTextures})`} | ||
</Text> | ||
|
||
<Progress.Root size="xl" color={gradient.to}> | ||
<Progress.Section value={(modVersion.textures.done[res] / modVersion.textures.todo) * 100}> | ||
<Progress.Label>{(modVersion.textures.done[res] / modVersion.textures.todo * 100).toFixed(2)} %</Progress.Label> | ||
</Progress.Section> | ||
</Progress.Root> | ||
</Stack> | ||
)) | ||
} | ||
</Stack> | ||
</Stack> | ||
</Card> | ||
</Popover.Target> | ||
<Popover.Dropdown style={{ pointerEvents: 'none' }}> | ||
<Text size="sm">Per Asset folder</Text> | ||
<Stack mt="sm" gap="xs"> | ||
{modVersion.resources.map((resource, index) => { | ||
return ( | ||
<div key={index}> | ||
<Stack justify="space-between" gap="0"> | ||
<Text size="sm">{resource.assetFolder}</Text> | ||
|
||
{(Object.keys(resource.textures.done) as Resolution[]) | ||
.map((res, i) => ( | ||
<Stack key={i} gap="0"> | ||
<Text size="xs" c="dimmed" key={i}> | ||
{res}: {resource.textures.done[res]}/{resource.textures.todo} | ||
{resource.textures.todo === resource.linkedTextures ? '' : `(${resource.linkedTextures})`} | ||
</Text> | ||
|
||
<Progress.Root size="xl" color={gradient.to}> | ||
<Progress.Section value={(resource.textures.done[res] / resource.textures.todo) * 100}> | ||
<Progress.Label>{(resource.textures.done[res] / resource.textures.todo * 100).toFixed(2)} %</Progress.Label> | ||
</Progress.Section> | ||
</Progress.Root> | ||
</Stack> | ||
))} | ||
|
||
</Stack> | ||
</div> | ||
) | ||
})} | ||
</Stack> | ||
</Popover.Dropdown> | ||
</Popover> | ||
) | ||
} |
78 changes: 78 additions & 0 deletions
78
src/components/dashboard/progression/progression-panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { Resolution } from '@prisma/client'; | ||
|
||
import { Button, Card, Group, Progress, Text, Stack } from '@mantine/core'; | ||
import { useState } from 'react'; | ||
import { TbReload } from 'react-icons/tb'; | ||
|
||
import { useEffectOnce } from '~/hooks/use-effect-once'; | ||
import { EMPTY_PROGRESSION, gradient } from '~/lib/utils'; | ||
import { getModsVersionsProgression } from '~/server/data/mods-version'; | ||
import { getGlobalProgression } from '~/server/data/texture'; | ||
import type { ModVersionWithProgression, Progression } from '~/types'; | ||
|
||
import { ProgressionItem } from './progression-item'; | ||
|
||
export function ProgressionPanel() { | ||
const [resources, setResources] = useState<ModVersionWithProgression[]>([]); | ||
const [globalProgress, setGlobalProgress] = useState<Progression>(EMPTY_PROGRESSION); | ||
|
||
useEffectOnce(() => { | ||
setResources([]); | ||
setGlobalProgress(EMPTY_PROGRESSION); | ||
reload(); | ||
}); | ||
|
||
const reload = () => { | ||
getModsVersionsProgression() | ||
.then((res) => { | ||
setResources(res.sort((a, b) => a.mod.name.localeCompare(b.mod.name))); | ||
}); | ||
getGlobalProgression() | ||
.then(setGlobalProgress) | ||
} | ||
|
||
return ( | ||
<Card | ||
shadow="sm" | ||
padding="md" | ||
radius="md" | ||
withBorder | ||
> | ||
<Group justify="space-between" align="flex-start"> | ||
<Text size="md" fw={700}>Pack Progression</Text> | ||
<Button | ||
variant='gradient' | ||
gradient={gradient} | ||
className="navbar-icon-fix" | ||
onClick={() => reload()} | ||
> | ||
<TbReload /> | ||
</Button> | ||
</Group> | ||
|
||
<Stack gap="0" mt="md"> | ||
<Text size="sm" fw={700}>Global Progression</Text> | ||
{(Object.keys(globalProgress.textures.done) as Resolution[]) | ||
.map((res, i) => ( | ||
<Stack key={i} gap="0"> | ||
<Text size="xs" c="dimmed"> | ||
Textures {res}: {globalProgress.textures.done[res]} / {globalProgress.textures.todo} | ||
{globalProgress.textures.todo === globalProgress.linkedTextures ? '' : `(linked: ${globalProgress.linkedTextures})`} | ||
</Text> | ||
|
||
<Progress.Root size="xl" color={gradient.to}> | ||
<Progress.Section value={(globalProgress.textures.done[res] / globalProgress.textures.todo) * 100}> | ||
<Progress.Label>{(globalProgress.textures.done[res] / globalProgress.textures.todo * 100).toFixed(2)} %</Progress.Label> | ||
</Progress.Section> | ||
</Progress.Root> | ||
</Stack> | ||
)) | ||
} | ||
</Stack> | ||
|
||
<Group gap="md" mt="md"> | ||
{resources.map((modVersion, index) => <ProgressionItem key={index} modVersion={modVersion} />)} | ||
</Group> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use server'; | ||
|
||
import type { Resource } from '@prisma/client'; | ||
|
||
import { db } from '~/lib/db'; | ||
|
Oops, something went wrong.