Skip to content

Commit

Permalink
Use gridStore instead of profile and some refactor to code
Browse files Browse the repository at this point in the history
  • Loading branch information
maayarosama committed Dec 16, 2024
1 parent ec10e33 commit ddaea05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export default {
async function _setValidNode(oldNodeId?: number) {
const node = await selectValidNode(
gridStore,
props.getFarm,
_loadedNodes.value,
props.selectedMachines,
Expand Down
28 changes: 8 additions & 20 deletions packages/playground/src/utils/nodeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { z } from "zod";

import { gqlClient, gridProxyClient } from "../clients";
import type { usePagination } from "../hooks";
import { type useGrid, useProfileManager } from "../stores";
import { type useGrid } from "../stores";
import type {
Locations,
NormalizeFarmFiltersOptions,
Expand Down Expand Up @@ -324,33 +324,21 @@ export function isNodeValid(
}

export async function selectValidNode(
gridStore: ReturnType<typeof useGrid>,
getFarm: GetFarmFn,
nodes: NodeInfo[],
selectedMachines: SelectedMachine[],
filters: FilterOptions,
oldSelectedNodeId?: number,
nodesLock?: AwaitLock,
): Promise<NodeInfo | void> {
let locked = true;
if (nodesLock && !nodesLock.acquired) {
locked = false;
await nodesLock.acquireAsync();
}
const profileManager = useProfileManager();
let node;
node = nodes.find(n => {
return n.rentedByTwinId === profileManager?.profile?.twinId;
});
const locked = true;

if (node && isNodeValid(getFarm, node, selectedMachines, filters)) {
if (nodesLock && !locked) {
release(nodesLock);
}
return node;
}

if (oldSelectedNodeId) {
node = nodes.find(n => n.nodeId === oldSelectedNodeId);
const rentedNode = nodes.find(n => {
return n.rentedByTwinId === gridStore.grid.twinId;
});
if (oldSelectedNodeId || rentedNode) {
const node = rentedNode || nodes.find(n => n.nodeId === oldSelectedNodeId);

if (node && isNodeValid(getFarm, node, selectedMachines, filters)) {
if (nodesLock && !locked) {
Expand Down

0 comments on commit ddaea05

Please sign in to comment.