Repository: sunflower-farmers/sunflower-farmers
File: src/features/game/events/landExpansion/placeBuilding.ts (TypeScript)

Code before:
        }
      }

      // Greenhouse
      if (action.name === "Greenhouse" && !isSecondBuilding) {
        const { greenhouse } = stateCopy;
        Object.values(greenhouse.pots).forEach((pot) => {
          if (pot.plant && existingBuilding.removedAt) {
            const existingProgress =
              existingBuilding.removedAt - pot.plant.plantedAt;
            pot.plant.plantedAt = createdAt - existingProgress;
          }
        });
      }

      // Henhouse & Barn
      if (
        (action.name === "Hen House" || action.name === "Barn") &&
        !isSecondBuilding
      ) {
        const buildingKey = action.name === "Hen House" ? "henHouse" : "barn";
        const { animals } = stateCopy[buildingKey];

        Object.values(animals).forEach((animal) => {
          if (existingBuilding.removedAt) {
            const timeOffset = existingBuilding.removedAt - animal.asleepAt;
            animal.asleepAt = animal.asleepAt + timeOffset;
            animal.awakeAt = animal.awakeAt + timeOffset;
            animal.lovedAt = animal.lovedAt + timeOffset;
          }
        });
      }

      if (action.name === "Crafting Box" && !isSecondBuilding) {
        const { craftingBox } = stateCopy;
        if (existingBuilding.removedAt && craftingBox.item) {
          const timeOffset = existingBuilding.removedAt - craftingBox.startedAt;
          craftingBox.startedAt = createdAt - timeOffset;
          const { seconds: recipeTime } = craftingBox.item.collectible
            ? getBoostedCraftingTime({
                game: stateCopy,
                time: RECIPES[craftingBox.item.collectible]?.time ?? 0,
              })
            : { seconds: 0 };
          craftingBox.readyAt = craftingBox.startedAt + recipeTime;
        }
      }

      delete existingBuilding.removedAt;

      return stateCopy;

Review comment (suggestion):

BE changed the timeOffset but forgot to apply on the FE
```suggestion
            const timeOffset = createdAt - existingBuilding.removedAt;
```

Code after:
        }
      }

      // Greenhouse
      if (action.name === "Greenhouse" && !isSecondBuilding) {
        const { greenhouse } = stateCopy;
        Object.values(greenhouse.pots).forEach((pot) => {
          if (pot.plant && existingBuilding.removedAt) {
            const existingProgress =
              existingBuilding.removedAt - pot.plant.plantedAt;
            pot.plant.plantedAt = createdAt - existingProgress;
          }
        });
      }

      // Henhouse & Barn
      if (
        (action.name === "Hen House" || action.name === "Barn") &&
        !isSecondBuilding
      ) {
        const buildingKey = action.name === "Hen House" ? "henHouse" : "barn";
        const { animals } = stateCopy[buildingKey];

        Object.values(animals).forEach((animal) => {
          if (existingBuilding.removedAt) {
            const timeOffset = createdAt - existingBuilding.removedAt;
            animal.asleepAt = animal.asleepAt + timeOffset;
            animal.awakeAt = animal.awakeAt + timeOffset;
            animal.lovedAt = animal.lovedAt + timeOffset;
          }
        });
      }

      if (action.name === "Crafting Box" && !isSecondBuilding) {
        const { craftingBox } = stateCopy;
        if (existingBuilding.removedAt && craftingBox.item) {
          const timeOffset = existingBuilding.removedAt - craftingBox.startedAt;
          craftingBox.startedAt = createdAt - timeOffset;
          const { seconds: recipeTime } = craftingBox.item.collectible
            ? getBoostedCraftingTime({
                game: stateCopy,
                time: RECIPES[craftingBox.item.collectible]?.time ?? 0,
              })
            : { seconds: 0 };
          craftingBox.readyAt = craftingBox.startedAt + recipeTime;
        }
      }

      delete existingBuilding.removedAt;

      return stateCopy;