Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GL-17: Автоматическая блокировка загрузки и сборки проекта, если запрещено обновление #15

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/screens/Profile/ui/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const ProfilePage = ({ params }: { params: { name: string } }) => {
</Section>

<Section title="Загрузка клиента" subtitle="Необходимо для генерации клиента Minecraft">
<DownloadClientHub key="DownloadClientHub" profileName={params.name} />
<DownloadClientHub key="DownloadClientHub" profile={profile} />
</Section>
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/shared/api/contracts/profiles/ProfileBaseEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ProfileExtendedBaseEntity = {
iconBase64: string;
description: string;
arguments: string;
hasUpdate: boolean;
files: ProfileFileBaseEntity[];
whiteListFiles: ProfileFileBaseEntity[];
};
Expand Down
9 changes: 5 additions & 4 deletions src/widgets/client-hub/lib/useConnectionHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { useEffect, useState } from "react";
import { HubConnection, HubConnectionBuilder } from "@microsoft/signalr";
import { getStorageAccessToken } from "@/shared/services";
import { useToast } from "@/shared/ui/use-toast";
import { ProfileExtendedBaseEntity } from "@/shared/api/contracts";

interface ConnectionHubProps {
profileName: string;
profile?: ProfileExtendedBaseEntity;
isLoading?: boolean;
}

const CONNECTION_URL = (token: string) =>
`${process.env.NEXT_PUBLIC_BASE_URL}/ws/profiles/restore?access_token=${token}`;

export const useConnectionHub = (props: ConnectionHubProps) => {
const { profileName, isLoading } = props;
const { profile, isLoading } = props;

const { toast } = useToast();
const accessToken = getStorageAccessToken();
Expand Down Expand Up @@ -70,7 +71,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => {
const onDownloadDistributive = () => {
setIsRestoring(true);
connectionHub
?.invoke("Restore", profileName)
?.invoke("Restore", profile?.profileName)
.then(() => {
toast({
title: "Успешно",
Expand All @@ -92,7 +93,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => {
const onBuildDistributive = () => {
setIsRestoring(true);
connectionHub
?.invoke("Build", profileName)
?.invoke("Build", profile?.profileName)
.then(() => {
toast({
title: "Успешно",
Expand Down
15 changes: 12 additions & 3 deletions src/widgets/client-hub/ui/DownloadClientHub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Button } from "@/shared/ui/button";
import { Progress } from "@/shared/ui/progress";

import { useConnectionHub } from "../lib/useConnectionHub";
import { ProfileExtendedBaseEntity } from "@/shared/api/contracts";

interface DownloadClientHubProps {
profileName: string;
profile: ProfileExtendedBaseEntity;
isLoading?: boolean;
}

Expand All @@ -23,7 +24,11 @@ export function DownloadClientHub(props: DownloadClientHubProps) {
<p className="text-sm text-gray-700">Необходимо загрузить клиент</p>
</div>
<div className="flex flex-col gap-y-1 w-[32rem]">
<Button className="w-fit" onClick={onDownloadDistributive} disabled={isDisable}>
<Button
className="w-fit"
onClick={onDownloadDistributive}
disabled={isDisable || !props.profile || !props.profile.hasUpdate}
>
Загрузить
</Button>
</div>
Expand All @@ -34,7 +39,11 @@ export function DownloadClientHub(props: DownloadClientHubProps) {
<p className="text-sm text-gray-700">Необходимо собрать профиль</p>
</div>
<div className="flex flex-col gap-y-1 w-[32rem]">
<Button className="w-fit" onClick={onBuildDistributive} disabled={isDisable}>
<Button
className="w-fit"
onClick={onBuildDistributive}
disabled={isDisable || !props.profile || !props.profile.hasUpdate}
>
Собрать
</Button>
</div>
Expand Down
Loading