mirror of https://github.com/Duxez/PteroPack.git
Merge pull request #14 from Duxez/game-type-check
#13 checks server type (mc) to make sure pteropack supports it
This commit is contained in:
commit
9d9836eba2
|
|
@ -60,6 +60,10 @@ class ModpackController extends ClientApiController {
|
|||
return $result->getBody()->getContents();
|
||||
}
|
||||
|
||||
public function getInstalledGame(Request $request, $server) {
|
||||
return $server->egg->nest->name;
|
||||
}
|
||||
|
||||
public function description(Request $request, $server, $modpack) {
|
||||
|
||||
$result = $this->http_client->get("mods/$modpack/description");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
import http from "@/api/http";
|
||||
|
||||
export default (uuid: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${uuid}/modpacks/installedgame`)
|
||||
.then((response) => resolve(response.data) )
|
||||
});
|
||||
}
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import ServerContentBlock from "@/components/elements/ServerContentBlock";
|
||||
import ModpackItem from './ModpackItem';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import getModpacks from '@/api/server/modpacks/getModpacks';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import tw from 'twin.macro';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import Fade from '@/components/elements/Fade';
|
||||
import { Modpack } from '@/api/server/modpacks/Modpack';
|
||||
import Pagination from '@/components/elements/Pagination';
|
||||
import { PaginatedResult } from '@/api/http';
|
||||
import GreyRowBox from '@/components/elements/GreyRowBox';
|
||||
import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
||||
import { Dropdown } from '@/components/elements/dropdown';
|
||||
import getInstalledGame from '@/api/server/modpacks/getInstalledGame';
|
||||
import { Button } from '@/components/elements/button/index';
|
||||
import Fade from '@/components/elements/Fade';
|
||||
import GreyRowBox from '@/components/elements/GreyRowBox';
|
||||
import Pagination from '@/components/elements/Pagination';
|
||||
import Select from '@/components/elements/Select';
|
||||
import ModpackItem from './ModpackItem';
|
||||
import { set } from 'date-fns';
|
||||
|
||||
export enum ModloaderType {
|
||||
|
|
@ -36,8 +37,9 @@ export default() => {
|
|||
const [page, setPage] = useState(1);
|
||||
const [modloaderType, setModloaderType] = useState<ModloaderType>(ModloaderType.Any);
|
||||
const [filters, setFilters] = useState<ModpackSearchFilter>({modloaderType: ModloaderType.Any});
|
||||
|
||||
const [isMinecraft, setIsMinecraft] = useState<boolean>(false);
|
||||
const [modpacks, setModpacks] = useState<PaginatedResult<Modpack>>();
|
||||
const [checkedInstalledGame, setCheckedInstalledGame] = useState<boolean>(false);
|
||||
|
||||
const changePage = (newPage: number) => {
|
||||
setPage(newPage);
|
||||
|
|
@ -58,10 +60,20 @@ export default() => {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(!modpacks?.items.length);
|
||||
if(!checkedInstalledGame) {
|
||||
getInstalledGame(uuid)
|
||||
.then((installedGame) => {
|
||||
if(installedGame == 'Minecraft') {
|
||||
setIsMinecraft(true);
|
||||
setLoading(!modpacks?.items.length);
|
||||
changePage(1);
|
||||
} else {
|
||||
setIsMinecraft(false);
|
||||
}
|
||||
|
||||
|
||||
changePage(1);
|
||||
setCheckedInstalledGame(true);
|
||||
});
|
||||
}
|
||||
}, [modloaderType]);
|
||||
|
||||
const updateFilterModloaderType = useCallback(
|
||||
|
|
@ -72,57 +84,75 @@ export default() => {
|
|||
[modloaderType],
|
||||
);
|
||||
|
||||
const showModpacks = () => {
|
||||
setIsMinecraft(true);
|
||||
setLoading(!modpacks?.items.length);
|
||||
changePage(1);
|
||||
}
|
||||
|
||||
return (
|
||||
<ServerContentBlock title="Modpacks">
|
||||
<FlashMessageRender byKey={'modpacks'} css={tw`mb-4`} />
|
||||
{(modpacks == undefined || !modpacks?.items.length) && loading ? (
|
||||
<Spinner size={'large'} centered />
|
||||
{!isMinecraft ? (
|
||||
<TitledGreyBox title="Server isn't a Minecraft server, currently Pteropack only supports Minecraft!">
|
||||
<p css={tw`text-sm`}>
|
||||
You can still install modpacks, but you will have to install them manually.
|
||||
</p>
|
||||
<Button.Danger onClick={showModpacks}>Show modpacks anyways</Button.Danger>
|
||||
</TitledGreyBox>
|
||||
|
||||
) : (
|
||||
<Fade timeout={150}>
|
||||
<div className='grid grid-cols-3 gap-4'>
|
||||
<TitledGreyBox title='Filters' className='col-span-3'>
|
||||
<GreyRowBox>
|
||||
<div className='grid grid-cols-3 gap-4'>
|
||||
<Select defaultValue={modloaderType} onChange={updateFilterModloaderType}>
|
||||
<option value={0}>
|
||||
Any
|
||||
</option>
|
||||
<option value={1}>
|
||||
Forge
|
||||
</option>
|
||||
<option value={2}>
|
||||
Cauldron
|
||||
</option>
|
||||
<option value={3}>
|
||||
LiteLoader
|
||||
</option>
|
||||
<option value={4}>
|
||||
Fabric
|
||||
</option>
|
||||
<option value={5}>
|
||||
Quilt
|
||||
</option>
|
||||
</Select>
|
||||
</div>
|
||||
</GreyRowBox>
|
||||
</TitledGreyBox>
|
||||
<Pagination data={modpacks as PaginatedResult<Modpack>} onPageSelect={changePage} paginationButtonsClassNames='col-span-3'>
|
||||
{({ items }) => (
|
||||
items.length > 0 ? (
|
||||
modpacks?.items.map((modpack, index) => (
|
||||
<ModpackItem
|
||||
key={modpack.id}
|
||||
modpack={modpack}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<p css={tw`text-center text-sm text-neutral-300`}>
|
||||
Couldn't fetch modpacks.
|
||||
</p>
|
||||
))}
|
||||
</Pagination>
|
||||
</div>
|
||||
</Fade>
|
||||
<>
|
||||
{(modpacks == undefined || !modpacks?.items.length) && loading ? (
|
||||
<Spinner size={'large'} centered />
|
||||
) : (
|
||||
<Fade timeout={150}>
|
||||
<div className='grid grid-cols-3 gap-4'>
|
||||
<TitledGreyBox title='Filters' className='col-span-3'>
|
||||
<GreyRowBox>
|
||||
<div className='grid grid-cols-3 gap-4'>
|
||||
<Select defaultValue={modloaderType} onChange={updateFilterModloaderType}>
|
||||
<option value={0}>
|
||||
Any
|
||||
</option>
|
||||
<option value={1}>
|
||||
Forge
|
||||
</option>
|
||||
<option value={2}>
|
||||
Cauldron
|
||||
</option>
|
||||
<option value={3}>
|
||||
LiteLoader
|
||||
</option>
|
||||
<option value={4}>
|
||||
Fabric
|
||||
</option>
|
||||
<option value={5}>
|
||||
Quilt
|
||||
</option>
|
||||
</Select>
|
||||
</div>
|
||||
</GreyRowBox>
|
||||
</TitledGreyBox>
|
||||
<Pagination data={modpacks as PaginatedResult<Modpack>} onPageSelect={changePage} paginationButtonsClassNames='col-span-3'>
|
||||
{({ items }) => (
|
||||
items.length > 0 ? (
|
||||
modpacks?.items.map((modpack, index) => (
|
||||
<ModpackItem
|
||||
key={modpack.id}
|
||||
modpack={modpack}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<p css={tw`text-center text-sm text-neutral-300`}>
|
||||
Couldn't fetch modpacks.
|
||||
</p>
|
||||
))}
|
||||
</Pagination>
|
||||
</div>
|
||||
</Fade>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</ServerContentBlock>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -69,8 +69,9 @@ Route::group([
|
|||
|
||||
Route::group(['prefix' => '/modpacks'], function () {
|
||||
Route::get('/', [Client\Servers\CurseForge\ModpackController::class, 'index']);
|
||||
Route::get('/installedgame', [Client\Servers\CurseForge\ModpackController::class, 'getInstalledGame']);
|
||||
Route::get('/{modpack}', [Client\Servers\CurseForge\ModpackController::class, 'show']);
|
||||
Route::get('/{modpack}/install', [Client\Servers\CurseForge\ModpackController::class, 'install']);
|
||||
Route::get('/{modpack}/install/{file}', [Client\Servers\CurseForge\ModpackController::class, 'install']);
|
||||
Route::get('/{modpack}/description', [Client\Servers\CurseForge\ModpackController::class, 'description']);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue