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

Changed review stars to blade #29

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you'd like to show product reviews on out-of-stock product pages you need to
Add the stars where you'd like in `resources/views/vendor/rapidez/product/overview.blade.php`:
```blade
@if($product->reviews_score)
<stars :score="{{ $product->reviews_score }}" :count="{{ $product->reviews_count }}"></stars>
<x-rapidez-reviews::stars :score="$product->reviews_score" :count="$product->reviews_count" />
@endif
```

Expand Down Expand Up @@ -54,7 +54,8 @@ And the form to add a review:

Add somewhere in `resources/views/category/partials/listing/item.blade.php`:
```blade
<stars v-if="item.reviews_score" :score="item.reviews_score" :count="item.reviews_count"></stars>
<x-rapidez-reviews::stars v-if="item.reviews_count" v-bind:count="item.reviews_count" v-bind:score="item.reviews_score"/>
royduin marked this conversation as resolved.
Show resolved Hide resolved

```

## Views
Expand Down
4 changes: 0 additions & 4 deletions resources/js/components.js

This file was deleted.

31 changes: 0 additions & 31 deletions resources/js/components/StarInput.vue

This file was deleted.

43 changes: 0 additions & 43 deletions resources/js/components/Stars.vue

This file was deleted.

1 change: 0 additions & 1 deletion resources/js/package.js

This file was deleted.

30 changes: 30 additions & 0 deletions resources/views/components/stars.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@props(['score' => 0, 'count' => null])

<div {{ $attributes->twMerge('flex items-center gap-1') }}>
<div class="relative">
<div class="flex gap-0.5">
@for ($star = 0; $star < 5; $star++)
<x-heroicon-s-star class="size-5 text-muted/50" />
@endfor
</div>
<div
style="width: {{ (int)$score }}%"
v-bind:style="{ width: ({{ $score }} || 0) + '%'}"
class="absolute inset-0 flex gap-0.5 overflow-hidden"
>
@for ($star = 0; $star < 5; $star++)
<x-heroicon-s-star class="size-5 shrink-0 text-yellow-400" />
@endfor
</div>
</div>
@if ($count || $attributes->has('v-bind:count'))
<span
class="text-sm"
@if ($attributes->has('v-bind:count'))
v-text="'(' + ({{ $attributes['v-bind:count'] }} || 0) + ')'"
@endif
>
({{ $count }})
</span>
@endif
royduin marked this conversation as resolved.
Show resolved Hide resolved
</div>
42 changes: 25 additions & 17 deletions resources/views/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@
<div class="flex flex-wrap w-full">
<div class="w-full">
<graphql query='@include('rapidez-reviews::queries.ratingsMetadata')'>
<div v-cloak v-if="data" slot-scope="{ data }">
<div class="mb-2" v-for="(rating, index) in data.productReviewRatingsMetadata.items">
<div v-if="data" v-cloak slot-scope="{ data }">
royduin marked this conversation as resolved.
Show resolved Hide resolved
<div v-for="(rating, index) in data.productReviewRatingsMetadata.items" class="mb-2">
<x-rapidez::label>@{{ rating.name }}</x-rapidez::label>
<star-input v-model="variables.ratings[index]" :rating="rating">
<fieldset class="flex items-center" slot-scope="{ rating, isActive, _renderProxy: starInput }">
<label v-for="ratingValue in rating.values">
<x-heroicon-s-star class="size-5 cursor-pointer" v-bind:class="isActive(ratingValue) ? 'text' : 'text-muted'"/>
<input class="sr-only" type="radio" v-model="starInput.value" :name="'stars' + rating.id" :value="{ id: rating.id, value_id: ratingValue.value_id }" required />
</label>
</fieldset>
</star-input>
<div class="flex items-center gap-0.5">
<label
v-for="ratingValue in rating.values"
class="cursor-pointer text-muted/50 hover:text-yellow-400 [&:has(~label:hover)]:text-yellow-400"
v-bind:class="{
'!text-yellow-400': ratingValue.value <= rating.values.find((ratingValue) => ratingValue.value_id == variables.ratings[index]?.value_id)?.value,
}"
v-bind:title="ratingValue.label"
>
<input
v-model="variables.ratings[index]"
type="radio"
class="sr-only"
v-bind:name="'rating-' + rating.id"
v-bind:value="{ id: rating.id, value_id: ratingValue.value_id }"
required
/>
<x-heroicon-s-star class="size-5 shrink-0 transition" />
</label>
</div>
</div>
</div>
<div v-else class="blur animate-pulse mb-2">
<x-rapidez::label>@lang('Rating')</x-rapidez::label>
<div class="flex">
@for ($i = 0; $i < 5; $i++)
<x-heroicon-s-star class="size-5 cursor-pointer text-muted" />
@endfor
</div>
<div v-else class="mb-2">
<x-rapidez::label>@lang('Rating') *</x-rapidez::label>
<x-rapidez-reviews::stars score="0" />
</div>
</graphql>
<div class="space-y-2">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/reviews.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div itemprop="reviewRating" itemtype="https://schema.org/Rating" itemscope>
<meta itemprop="ratingValue" v-bind:content="review.average_rating" />
<meta itemprop="bestRating" content="100" />
<stars class="mt-1" v-bind:score="review.average_rating"></stars>
<x-rapidez-reviews::stars v-bind:score="review.average_rating" />
</div>
<strong class="block mt-3" itemprop="name">@{{ review.summary }}</strong>
<p class="mt-1 text-sm" itemprop="reviewBody">@{{ review.text }}</p>
Expand All @@ -31,7 +31,7 @@
@{{ new Date(Date.now()).toLocaleDateString() }}
</span>
</div>
<stars class="mt-1" :score="100"></stars>
<x-rapidez-reviews::stars />
<strong class="block mt-3">
@lang('Be the first to write a review')
</strong>
Expand Down
Loading