Skip to content

Commit 00b4f61

Browse files
committed
Optimistic mode for Item store logic
1 parent cc5114c commit 00b4f61

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

app/Application.php

+11
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ public static function getApp($appid)
151151
return $app;
152152
}
153153

154+
155+
/**
156+
* @param $appName
157+
* @return mixed|null
158+
* @throws GuzzleException
159+
*/
160+
public static function findApp($appName)
161+
{
162+
return self::where('name', $appName)->first()->appid;
163+
}
164+
154165
/**
155166
* @param $appid
156167
* @return mixed|null

app/Http/Controllers/ItemController.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ public function edit(int $id): View
207207
*/
208208
public static function storelogic(Request $request, $id = null): Item
209209
{
210+
if ($request->input('optimistic')) {
211+
$request->merge(['app' => Application::findApp($request->input('title'))]);
212+
$request->merge((array)json_decode(ItemController::appload($request)));
213+
214+
# FIXME: I need to fix some param naming here to make it work
215+
$request->merge([
216+
/* 'pinned' => 1,*/
217+
/* 'tags' => [0],*/
218+
'icon' => $request->input('iconview'),
219+
'appdescription' => $request->input('description'),
220+
]);
221+
}
222+
210223
$application = Application::single($request->input('appid'));
211224
$validatedData = $request->validate([
212225
'title' => 'required|max:255',
@@ -366,7 +379,7 @@ public function restore(int $id): RedirectResponse
366379
*
367380
* @throws GuzzleException
368381
*/
369-
public function appload(Request $request): ?string
382+
public static function appload(Request $request): ?string
370383
{
371384
$output = [];
372385
$appid = $request->input('app');

0 commit comments

Comments
 (0)