I decided to implement websockets for this, since I would be using it anyway.
So I created 2 new events, ImportChunkCompleted and ImportCompleted that I broadcast
class PromotionLinesImport
{
public function registerEvents(): array
{
$events = $this->parentRegisterEvents();
$events[AfterSheet::class] = function (AfterSheet $event) {
$rows = cache("imports:{$this->uuid}:rows", 0);
$rows += $this->imported_rows;
cache()->put("imports:{$this->uuid}:rows", $rows, now()->addHours(2));
event(new ImportChunkCompleted($this->importer, get_class($this), $this->uuid, $rows));
};
$events[AfterImport::class] = fn(AfterImport $event) => event(new ImportCompleted($this->importer, get_class($this), $this->uuid));
return $events;
}
}
Now, it shows to the user the number of rows each chunk has imported and closes the modal when it is completed.