chore: cluster logic
This commit is contained in:
parent
ed0da96040
commit
b47aa875de
4 changed files with 48 additions and 17 deletions
|
|
@ -258,7 +258,7 @@ function ClusterInformation({
|
|||
</Option>
|
||||
|
||||
<Option header="Loader">
|
||||
<Dropdown className="w-full" defaultSelectedKey="vanilla">
|
||||
<Dropdown defaultSelectedKey="vanilla">
|
||||
<Dropdown.Item>
|
||||
<div className="flex flex-row">
|
||||
<LoaderIcon className="size-5" loader="vanilla" />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { Model } from '@/bindings.gen';
|
||||
import type { ClusterModel } from '@/bindings.gen';
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import DefaultInstancePhoto from '@/assets/images/default_instance_cover.jpg';
|
||||
import LoaderIcon from '@/components/launcher/LoaderIcon';
|
||||
import ScrollableContainer from '@/components/ScrollableContainer';
|
||||
import SettingsRow from '@/components/SettingsRow';
|
||||
|
|
@ -7,6 +8,7 @@ import { bindings } from '@/main';
|
|||
import { useCommand } from '@onelauncher/common';
|
||||
import { Button, Show, TextField } from '@onelauncher/common/components';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { dataDir } from '@tauri-apps/api/path';
|
||||
import { Edit02Icon, FolderIcon, ImagePlusIcon, Share07Icon, Tool02Icon, Trash01Icon } from '@untitled-theme/icons-react';
|
||||
import { useState } from 'react';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
|
@ -25,6 +27,22 @@ function RouteComponent() {
|
|||
// dumbass fix ik
|
||||
const cluster = useCommand('getClusterById', () => bindings.core.getClusterById(Number(id.toString()) as unknown as bigint));
|
||||
|
||||
const editing = useCommand('updateClusterById', () => bindings.core.updateClusterById(Number(id.toString()) as unknown as bigint, {
|
||||
icon_url: newCover,
|
||||
name: newName,
|
||||
}), {
|
||||
enabled: false,
|
||||
subscribed: false,
|
||||
});
|
||||
|
||||
function handleEditMode() {
|
||||
if (edit)
|
||||
editing.refetch();
|
||||
cluster.refetch();
|
||||
|
||||
setEdit(!edit);
|
||||
}
|
||||
|
||||
return (
|
||||
<Sidebar.Page>
|
||||
<h1>Overview</h1>
|
||||
|
|
@ -49,7 +67,7 @@ function RouteComponent() {
|
|||
isDisabled={false}
|
||||
/>
|
||||
)}
|
||||
description="burada path var işte yersen"
|
||||
description="asdsad"
|
||||
disabled={false}
|
||||
icon={<FolderIcon />}
|
||||
title="Cluster Folder"
|
||||
|
|
@ -58,7 +76,7 @@ function RouteComponent() {
|
|||
<SettingsRow.Header>Cluster Actions</SettingsRow.Header>
|
||||
<SettingsRow
|
||||
children={(
|
||||
<Button color="secondary" onClick={() => setEdit(!edit)}>{edit ? 'Save' : 'Edit'}</Button>
|
||||
<Button color="secondary" onClick={handleEditMode}>{edit ? 'Save' : 'Edit'}</Button>
|
||||
)}
|
||||
description="Edit the cluster name and cover image."
|
||||
icon={<Edit02Icon />}
|
||||
|
|
@ -95,7 +113,7 @@ function RouteComponent() {
|
|||
}
|
||||
|
||||
interface BannerProps {
|
||||
cluster: Model | null | undefined;
|
||||
cluster: ClusterModel | null | undefined;
|
||||
editMode: boolean;
|
||||
newName: string;
|
||||
setNewName: Dispatch<SetStateAction<string>>;
|
||||
|
|
@ -149,14 +167,14 @@ function Banner({
|
|||
<Show when={editMode}>
|
||||
<div
|
||||
className="absolute z-1 h-full w-full flex items-center justify-center bg-black/50 opacity-50 hover:opacity-100"
|
||||
// onClick={launchFilePicker}
|
||||
// onClick={launchFilePicker}
|
||||
>
|
||||
<ImagePlusIcon className="h-12 w-12" />
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
{/* <ClusterCover class="h-full w-full object-cover" cluster={props.cluster} override={props.newCover()} /> */}
|
||||
<img src="https://github.com/emirsassan.png" />
|
||||
<img src={cluster?.icon_url || DefaultInstancePhoto} />
|
||||
</div>
|
||||
|
||||
<div className="w-full flex flex-col justify-between gap-y-.5 overflow-hidden text-fg-primary">
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import type { Model } from '@/bindings.gen';
|
||||
import type { ClusterModel } from '@/bindings.gen';
|
||||
import DefaultBanner from '@/assets/images/default_banner.png';
|
||||
import DefaultInstancePhoto from '@/assets/images/default_instance_cover.jpg';
|
||||
import { NewClusterCreate } from '@/components/launcher/cluster/ClusterCreation';
|
||||
import Modal from '@/components/overlay/Modal';
|
||||
import useRecentCluster from '@/hooks/useCluster';
|
||||
import { bindings } from '@/main';
|
||||
import { upperFirst } from '@/utils';
|
||||
|
|
@ -115,7 +114,7 @@ function Banner() {
|
|||
}
|
||||
|
||||
interface ClusterGroupProps {
|
||||
clusters: Array<Model> | undefined;
|
||||
clusters: Array<ClusterModel> | undefined;
|
||||
isFetching?: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +149,7 @@ function ClusterCard({
|
|||
name,
|
||||
mc_loader,
|
||||
mc_version,
|
||||
}: Model) {
|
||||
}: ClusterModel) {
|
||||
const launch = useCommand('launchCluster', () => bindings.core.launchCluster(id, null), {
|
||||
enabled: false,
|
||||
subscribed: false,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use interpulse::api::minecraft::Version;
|
||||
use onelauncher_entity::{clusters, icon::Icon, loader::GameLoader, prelude::entity};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use serde::Serialize;
|
||||
use tauri::{AppHandle, Runtime};
|
||||
|
||||
use crate::{api::{self, cluster::dao::ClusterId}, error::LauncherResult, store::{credentials::MinecraftCredentials, Core}};
|
||||
use crate::{api::{self, cluster::dao::ClusterId}, error::{LauncherError, LauncherResult}, store::{credentials::MinecraftCredentials, Core}};
|
||||
|
||||
use onelauncher_entity::prelude::model::*;
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ pub trait TauriLauncherApi {
|
|||
async fn launch_cluster(id: ClusterId, uuid: Option<uuid::Uuid>) -> LauncherResult<()>;
|
||||
|
||||
#[taurpc(alias = "updateClusterById")]
|
||||
async fn update_cluster_by_id(id: ClusterId, request: Cluster) -> LauncherResult<()>;
|
||||
async fn update_cluster_by_id(id: ClusterId, request: ClusterUpdate) -> LauncherResult<()>;
|
||||
|
||||
|
||||
// Setting Profiles
|
||||
|
|
@ -75,6 +76,12 @@ pub struct CreateCluster {
|
|||
icon: Option<Icon>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, specta::Type, Clone)]
|
||||
pub struct ClusterUpdate {
|
||||
name: Option<String>,
|
||||
icon_url: Option<Icon>,
|
||||
}
|
||||
|
||||
|
||||
#[taurpc::ipc_type]
|
||||
pub struct TauriLauncherApiImpl;
|
||||
|
|
@ -120,14 +127,21 @@ impl TauriLauncherApi for TauriLauncherApiImpl {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_cluster_by_id(id: ClusterId, request: clusters::ActiveModel) -> LauncherResult<()> {
|
||||
let updated_cluster = api::cluster::dao::update_cluster_by_id(id, |mut active_model| async move {
|
||||
active_model.updated_at = Set(chrono::Utc::now().naive_utc());
|
||||
async fn update_cluster_by_id(self, id: ClusterId, request: ClusterUpdate) -> LauncherResult<()> {
|
||||
api::cluster::dao::update_cluster_by_id(id, |mut active_model: ClusterPartial| async move {
|
||||
if let Some(name) = request.name {
|
||||
active_model.name = Set(name)
|
||||
}
|
||||
|
||||
// ok i know this is so wrong but im not a rust guy
|
||||
if let icon_url = request.icon_url {
|
||||
active_model.icon_url = Set(icon_url)
|
||||
}
|
||||
|
||||
Ok(active_model)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|e| LauncherError::from(e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue