<?php
const BASE_URL = "https://swapshop.littlesong.place";
$GLOBALS['db'] = new PDO("sqlite:database.db");
-$event = $_GET['event'];
-$name = $_GET['name'];
+$event = $_GET['event'] ?? NULL;
+$name = $_GET['name'] ?? NULL;
+$count = $_GET['count'] ?? NULL;
function event_url($e) {
return "?event=$e";
$peeps = get_peeps($event);
$shareable_link = BASE_URL.event_url($event);
+
+// Background JSON check whether more users have joined
+if (isset($event) && isset($count)) {
+ // Check of more users have joined
+ header('Content-type: application/json');
+ if (count($peeps) != $count) {
+ echo '{"reload": true}';
+ }
+ else {
+ echo '{"reload": false}';
+ }
+ exit;
+}
+
?>
<!DOCTYPE html>
<html>
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <?php if (isset($event)): ?>
+ <script>
+ async function reloadIfChanged() {
+ const response = await fetch("/?event=<?= $event ?>&count=<?= count($peeps) ?>");
+ const result = await response.json();
+ if (result.reload) location.reload();
+ else setTimeout(reloadIfChanged, 10000);
+ }
+ </script>
+ <?php endif ?>
</head>
-<?php if (isset($name)): # Periodically reload after join ?>
-<body onload="setTimeout('location.reload()', 10000)">
+<?php if (isset($event)): # Periodically reload event page when changed ?>
+<body onload="setTimeout('reloadIfChanged()', 10000)">
<?php else: ?>
<body>
<?php endif ?>