-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.phtml
72 lines (59 loc) · 1.96 KB
/
1.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;
use NeutromeLabs\SsrGraphql\ViewModel\SsrGraphqlViewModel;
/** @var Template $block */
/** @var Escaper $escaper */
/** @var SsrGraphqlViewModel $gql */
$gql = $block->getData('ssrGqlViewModel');
?>
<script>
var currentPage = 1;
var ssrGqlExampleObject = <?= $gql->makeSsrGqlCall(<<<GRAPHQL
query productsQuery(\$currentPage: Int!) {
products (search: "", pageSize: 3, currentPage: \$currentPage) {
items {
sku
}
}
}
GRAPHQL, ['currentPage' => 1]) ?>
console.log('script initialized');
console.log(ssrGqlExampleObject);
let renderData = () => {
document.getElementById('ssrgql_example__current_page').innerHTML = currentPage.toString();
[0, 1, 2].map((i) => {
let cardEl = document.getElementById('ssrgql_example__product_card_' + i);
cardEl.querySelector('[data-role="sku"]').innerHTML = ssrGqlExampleObject.data.products.items[i].sku;
})
}
let handleNext = () => {
currentPage++;
ssrGqlExampleObject.refresh({
currentPage: currentPage
}).then(() => {
console.log('refresh completed');
console.log(ssrGqlExampleObject);
renderData();
})
}
document.addEventListener('DOMContentLoaded', function() {
renderData();
console.log('page load completed');
console.log(ssrGqlExampleObject);
});
</script>
<div>
<div id="ssrgql_example__product_card_0">
<p>Product 1: #<span data-role="sku"></span></p>
</div>
<div id="ssrgql_example__product_card_1">
<p>Product 2: #<span data-role="sku"></span></p>
</div>
<div id="ssrgql_example__product_card_2">
<p>Product 3: #<span data-role="sku"></span></p>
</div>
</div>
<p>Page: <span id="ssrgql_example__current_page"></span></p>
<button onclick="handleNext()">Next</button>