From ebc725296a4467ff5aea8296ad97a5f81c25c548 Mon Sep 17 00:00:00 2001 From: Graphictoria Date: Tue, 5 Jul 2022 23:45:02 -0400 Subject: [PATCH] Some more shop stuff. --- web/app/Helpers/ValidationHelper.php | 25 ++++++ .../Http/Controllers/Api/ShopController.php | 41 ++++++++++ web/resources/js/components/Shop.js | 78 ++++++++++++++----- web/resources/sass/Graphictoria.scss | 23 +++--- web/routes/api.php | 8 +- 5 files changed, 144 insertions(+), 31 deletions(-) create mode 100644 web/app/Helpers/ValidationHelper.php create mode 100644 web/app/Http/Controllers/Api/ShopController.php diff --git a/web/app/Helpers/ValidationHelper.php b/web/app/Helpers/ValidationHelper.php new file mode 100644 index 0000000..c4c29a2 --- /dev/null +++ b/web/app/Helpers/ValidationHelper.php @@ -0,0 +1,25 @@ + [] + ]; + + foreach($validator->errors()->all() as $error) { + array_push($errorModel['errors'], ['code' => 400, 'message' => $error]); + } + + return $errorModel; + } +} diff --git a/web/app/Http/Controllers/Api/ShopController.php b/web/app/Http/Controllers/Api/ShopController.php new file mode 100644 index 0000000..43903fd --- /dev/null +++ b/web/app/Http/Controllers/Api/ShopController.php @@ -0,0 +1,41 @@ +all(), [ + 'assetTypeId' => ['required', 'regex:/^\\d(,?\\d)*$/i'], + 'gearGenreId' => ['regex:/^\\d(,?\\d)*$/i'] + ]); + + if($validator->fails()) { + return ShopController::generateValidatorError($validator); + } + + $valid = $validator->valid(); + + if($valid['assetTypeId'] != '19' && isset($valid['gearGenreId'])) { + $validator->errors()->add('gearGenreId', 'gearGenreId can only be used with typeId 19.'); + return ShopController::generateValidatorError($validator); + } + + return response([ + 'data' => [], + 'next_cursor' => null, + 'prev_cursor' => null + ]); + } +} diff --git a/web/resources/js/components/Shop.js b/web/resources/js/components/Shop.js index aa46ea1..08deddd 100644 --- a/web/resources/js/components/Shop.js +++ b/web/resources/js/components/Shop.js @@ -199,7 +199,9 @@ class Shop extends Component { super(props); this.state = { selectedCategoryId: -1, - pageLoading: true + pageItems: [], + pageLoaded: true, + error: false }; this.navigateCategory = this.navigateCategory.bind(this); @@ -233,9 +235,34 @@ class Shop extends Component { } navigateCategory(categoryId, data) { - this.setState({selectedCategoryId: categoryId}); + this.setState({selectedCategoryId: categoryId, pageLoaded: false}); - console.log(data); + let url = buildGenericApiUrl('api', 'catalog/v1/list-json'); + let paramIterator = 0; + Object.keys(data).filter(key => { + if (key == 'label') + return false; + return true; + }).map(key => { + url += ((paramIterator++ == 0 ? '?' : '&') + `${key}=${data[key]}`); + }); + + axios.get(url) + .then(res => { + const items = res.data; + + this.nextCursor = items.next_cursor; + this.setState({ pageItems: items.data, pageLoaded: true, error: false }); + }).catch(err => { + const data = err.response; + + let errorMessage = 'An error occurred while processing your request.'; + if(data.errors) + errorMessage = data.errors[0].message; + + this.setState({ pageItems: [], pageLoaded: true, error: errorMessage }); + this.inputBox.current.focus(); + }); } render() { @@ -260,36 +287,51 @@ class Shop extends Component {
{ - this.state.pageLoading ? + this.state.error ? +
{this.state.error}
+ : + null + } + { + !this.state.pageLoaded ?
: null } -
- - - -
-

Test hat

-

Free

-
-
-
-
+ { + (this.state.pageItems.length == 0 && !this.state.error) ? +

Nothing found.

+ : +
+ { + this.state.pageItems.map(({}, index) => { + + + +
+

Test hat

+

Free

+
+
+
+ }) + } +
+ }
diff --git a/web/resources/sass/Graphictoria.scss b/web/resources/sass/Graphictoria.scss index cb3bb6d..4577c27 100644 --- a/web/resources/sass/Graphictoria.scss +++ b/web/resources/sass/Graphictoria.scss @@ -52,21 +52,20 @@ img.twemoji { padding: 0; flex: 0 0 auto; - width: math.div(100%, 3); + + @media (max-width: 576px) { + flex: 0 0 auto; + width: math.div(100%, 2); + } + + @media (min-width: 576px) { + flex: 0 0 auto; + width: math.div(100%, 4); + } @media (min-width: 768px) { flex: 0 0 auto; - width: math.div(100%, 5); - } - - @media (min-width: 992px) { - flex: 0 0 auto; - width: math.div(100%, 7); - } - - @media (min-width: 1400px) { - flex: 0 0 auto; - width: math.div(100%, 8); + width: 144px; } } diff --git a/web/routes/api.php b/web/routes/api.php index 9d58dda..b2d94ac 100644 --- a/web/routes/api.php +++ b/web/routes/api.php @@ -6,11 +6,17 @@ Route::middleware('auth')->group(function () { Route::group(['as' => 'feed.', 'prefix' => 'feed'], function() { Route::group(['as' => 'v1.', 'prefix' => 'v1'], function() { Route::get('/list-json', 'FeedController@listjson')->name('list'); - Route::post('/share ', 'FeedController@share')->name('share')->middleware('throttle:3,2'); + Route::post('/share', 'FeedController@share')->name('share')->middleware('throttle:3,2'); }); }); }); +Route::group(['as' => 'catalog.', 'prefix' => 'catalog'], function() { + Route::group(['as' => 'v1.', 'prefix' => 'v1'], function() { + Route::get('/list-json', 'ShopController@listjson')->name('list'); + }); + }); + Route::fallback(function () { return response('404 not found.', 404) ->header('Content-Type', 'text/plain');