Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template limit slider #239

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions app/Http/Controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ class TemplateController extends Controller
{
public function index(Request $request)
{
$limit = null;
if ($request->offsetExists('limit') && $request->get('limit') > 0) {
$limit = (int)$request->get('limit');
}
$limit = (int)$request->get('limit', 0);
$onlyMy = (bool)$request->get('onlymy', false);

$onlyMy = false;
if ($request->offsetExists('onlymy') && $request->get('onlymy')) {
$onlyMy = true;
}

$templates = Template::limit($limit)
->when(Auth::check(), function ($query) use ($onlyMy) {
$templates = Template::when(Auth::check(), function ($query) use ($onlyMy) {
if ($onlyMy) {
$query->where('creator_id', Auth::id());
} else {
Expand All @@ -37,6 +29,9 @@ public function index(Request $request)
->when(!Auth::check(), function ($query) {
$query->where('publicly_listed', true);
})
->when($limit > 0, function ($query) use ($limit) {
$query->limit($limit);
})
->orderByDesc('created_at')
->get();

Expand Down
9 changes: 6 additions & 3 deletions resources/js/components/pages/welcome/TemplatesSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class="w-full inline-flex flex-nowrap overflow-hidden [mask-image:_linear-gradient(to_right,transparent_0,_black_128px,_black_calc(100%-128px),transparent_100%)]"
>
<ul ref="templates-slider" class="flex justify-center md:justify-start animate-infinite-scroll">
<li v-for="(template, i) in templates" :key="template.id" class="mx-4 w-72 h-auto">
<li v-for="(template, i) in sliderTemplates" :key="template.id" class="mx-4 w-72 h-auto">
<single-template :slug="template.slug" />
</li>
</ul>
Expand All @@ -42,7 +42,10 @@ export default {
computed: {
...mapState({
templates: state => state['open/templates'].content
})
}),
sliderTemplates () {
return this.templates.slice(0, 20)
}
},

watch: {
Expand All @@ -54,7 +57,7 @@ export default {
},

mounted() {
store.dispatch('open/templates/loadAll', {'limit':10})
store.dispatch('open/templates/loadAll', { limit: 20 })
},

methods: {
Expand Down
Loading