@@ -26,6 +26,8 @@ class BrowseWorkshopPage extends Page implements HasTable
2626 use BlockAccessInConflict;
2727 use InteractsWithTable;
2828
29+ protected ?array $ installedModIds = null ;
30+
2931 protected static string |\BackedEnum |null $ navigationIcon = 'tabler-world-search ' ;
3032
3133 protected static ?string $ slug = 'workshop/browse ' ;
@@ -64,6 +66,24 @@ public function getTitle(): string
6466 return 'Browse Arma Reforger Workshop ' ;
6567 }
6668
69+ protected function getInstalledModIds (): array
70+ {
71+ if ($ this ->installedModIds === null ) {
72+ /** @var Server $server */
73+ $ server = Filament::getTenant ();
74+ /** @var DaemonFileRepository $fileRepository */
75+ $ fileRepository = app (DaemonFileRepository::class);
76+
77+ $ installedMods = ArmaReforgerWorkshop::getInstalledMods ($ server , $ fileRepository );
78+ $ this ->installedModIds = array_map (
79+ fn (array $ mod ) => strtoupper ($ mod ['modId ' ]),
80+ $ installedMods
81+ );
82+ }
83+
84+ return $ this ->installedModIds ;
85+ }
86+
6787 /**
6888 * @throws Exception
6989 */
@@ -129,14 +149,7 @@ public function table(Table $table): Table
129149 ->label ('Add to Server ' )
130150 ->icon ('tabler-plus ' )
131151 ->color ('success ' )
132- ->visible (function (array $ record ) {
133- /** @var Server $server */
134- $ server = Filament::getTenant ();
135- /** @var DaemonFileRepository $fileRepository */
136- $ fileRepository = app (DaemonFileRepository::class);
137-
138- return !ArmaReforgerWorkshop::isModInstalled ($ server , $ fileRepository , $ record ['modId ' ]);
139- })
152+ ->visible (fn (array $ record ) => !in_array (strtoupper ($ record ['modId ' ]), $ this ->getInstalledModIds (), true ))
140153 ->requiresConfirmation ()
141154 ->modalHeading (fn (array $ record ) => "Add \"{$ record ['name ' ]}\"" )
142155 ->modalDescription (fn (array $ record ) => "This will add \"{$ record ['name ' ]}\" by {$ record ['author ' ]} to your server's mod list. " )
@@ -181,14 +194,7 @@ public function table(Table $table): Table
181194 ->icon ('tabler-check ' )
182195 ->color ('gray ' )
183196 ->disabled ()
184- ->visible (function (array $ record ) {
185- /** @var Server $server */
186- $ server = Filament::getTenant ();
187- /** @var DaemonFileRepository $fileRepository */
188- $ fileRepository = app (DaemonFileRepository::class);
189-
190- return ArmaReforgerWorkshop::isModInstalled ($ server , $ fileRepository , $ record ['modId ' ]);
191- }),
197+ ->visible (fn (array $ record ) => in_array (strtoupper ($ record ['modId ' ]), $ this ->getInstalledModIds (), true )),
192198 ]);
193199 }
194200
0 commit comments