Drarig29 / brackets-manager.js

A simple library to manage tournament brackets (round-robin, single elimination, double elimination).
https://drarig29.github.io/brackets-docs
MIT License
245 stars 38 forks source link

I have some problem using the libraries #183

Closed Vadilonga closed 11 months ago

Vadilonga commented 11 months ago

Hi, I'm trying the library for the first time and I followed the documentation in github and also on stackblitz.

I dunno why the create stage doesn't work on my code. I'm using Angular 16. This is my code:

import { BracketsManager } from 'brackets-manager';
import { dataset16, dataset2, dataset32, dataset4, dataset8 } from './datasets';
import { Dataset } from './interfaces/dataset.interface';
import { InMemoryDatabase } from 'brackets-memory-db'

const TOURNAMENT_ID = 15;

async function process(dataset: Dataset) {
  const storage = new InMemoryDatabase();
  const manager = new BracketsManager(storage);

  storage.setData({
    participant: dataset.roster.map((player) => ({
      ...player,
      tournament_id: TOURNAMENT_ID,
    })),
    stage: [],
    group: [],
    round: [],
    match: [],
    match_game: [],
  });

  console.log(storage);

  const stage = await manager.create.stage({
    tournamentId: TOURNAMENT_ID,
    name: 'test stage',
    type: dataset.type,
    seeding: dataset.roster.map(item=>item.name),
  });

  console.log("stage", stage);
  const data = await manager.get.stageData(stage.id);
  console.log("data", data);
  const match = await storage.select('match');
  console.log("match", match);
  const stages = data.stage;
  const matches = data.match;
  const matchGames = data.match_game;
  const participants = data.participant;

}

export function testDataset(){
  return process(dataset8);
}

At the moment the console log of stage has this value:

{
id: [], name: "Test stage", number: 1, 
setting : {consolationFinal: false, matchesChildCount: 0, size: 8},
tournament_id: 15, type: "single_elimination"
}

But inside data console log, stage is an array with one element that is an empty array.

I also share my dataset:

export let dataset8: Dataset = {
  title: '8 competitor tournament',
  type: 'single_elimination',
  roster: [
    { id: 7, name: 'Seed 1' },
    { id: 55, name: 'Seed 2' },
    { id: 53, name: 'Seed 3' },
    { id: 523, name: 'Seed 4' },
    { id: 123, name: 'Seed 5' },
    { id: 353, name: 'Seed 6' },
    { id: 354, name: 'Seed 7' },
    { id: 355, name: 'Seed 8' },
  ],
};

I dunno what is wrong with the code

Drarig29 commented 11 months ago

Can you double check you use the latest version of each package? The stackblitz demo is for sure outdated, and it may be related.

Your above example works as expected in the browser console in https://drarig29.github.io/brackets-docs/getting-started/. You can get manager and storage like this:

const manager = window.bracketsManager
const storage = manager.storage
Vadilonga commented 11 months ago

I checked the versions of the file:

        "brackets-manager": "^1.6.4",
        "brackets-memory-db": "^1.0.4",
        "brackets-model": "^1.5.0",
        "brackets-viewer": "^1.6.2",

Can the problem be I'm using the InMemoryDataset instead the "brackets-json-db"? It seems that the manager cannot write to the db.

Vadilonga commented 11 months ago

Ok, I did another test, I created an empty app and works properly, I have to check back my current application.

Vadilonga commented 11 months ago

If anyone has already tried to integrate this library with fuse we will be very happy to hear your solutions!

Vadilonga commented 11 months ago

I cleaned the node modules, removed the previously added dependencies to try to integrate the brackets-json-db library and now everything is working as expected. I couldn't say for sure what the problem might have been. Thx for the support <3