Skip to content

Add Axum activity feed example #2

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

Merged
merged 6 commits into from
Jul 29, 2025
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
96 changes: 96 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ axum = { version = "0.8.4", default-features = false, optional = true, features
"tokio",
"json",
] }
chrono = { version = "0.4.41", default-features = false, features = ["clock"] }
rocket = { version = "0.5.1", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = [
"derive",
Expand Down
102 changes: 102 additions & 0 deletions examples/activity-feed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!doctype html>
<html lang="en">
<head>
<title>Datastar SDK Activity Feed Demo</title>
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
<script
type="module"
src="https://cdn.jsdelivr.net/gh/starfederation/datastar@main/bundles/datastar.js"
></script>
</head>
<body class="bg-white dark:bg-gray-900 text-lg max-w-xl mx-auto my-16">
<div
class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 rounded-lg px-6 py-8 ring shadow-xl ring-gray-900/5 space-y-2"
>
<div class="flex justify-between items-center">
<h1 class="text-gray-900 dark:text-white text-3xl font-semibold">Datastar SDK Activity Feed Demo</h1>
<img src="https://data-star.dev/static/images/rocket-64x64.png" alt="Rocket" width="64" height="64" />
</div>
<p class="mt-2">SSE events will be streamed from the backend to the frontend.</p>
<div class="space-x-2">
<input
id="events"
data-signals-events="200"
data-bind-events
type="number"
step="100"
min="0"
class="w-36 rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-sky-500 focus:outline focus:outline-sky-500 dark:disabled:border-gray-700 dark:disabled:bg-gray-800/20"
/>
<label for="events"> Number of events </label>
</div>
<div class="space-x-2">
<input
id="interval"
data-signals-interval="10"
data-bind-interval
type="number"
step="10"
min="0"
class="w-36 rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-sky-500 focus:outline focus:outline-sky-500 dark:disabled:border-gray-700 dark:disabled:bg-gray-800/20"
/>
<label for="interval"> Interval in milliseconds </label>
</div>
<button
id="start-button"
data-on-click="@post(&#39;/event/generate&#39;)"
data-signals-generating="false"
data-attr-disabled="$generating"
data-class="{
'bg-gray-500 text-gray-300 cursor-wait': $generating,
'bg-sky-500 text-white cursor-pointer hover:bg-sky-700 hover:text-gray-100': !$generating,
}"
class="rounded-md px-5 py-2.5 leading-5 font-semibold"
>
Generate
</button>
<span>&nbsp;|&nbsp;</span>
<button
data-on-click="@post(&#39;/event/done&#39;)"
class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer"
>
Done
</button>
<button
data-on-click="@post(&#39;/event/warn&#39;)"
class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer"
>
Warn
</button>
<button
data-on-click="@post(&#39;/event/fail&#39;)"
class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer"
>
Fail
</button>
<button
data-on-click="@post(&#39;/event/info&#39;)"
class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer"
>
Info
</button>
</div>
<div class="mt-2 text-gray-400 font-mono text-sm rounded-md bg-black p-4">
<div id="feed">
Click <code class="text-fuchsia-600">Generate</code> to create
<span data-text="$events">200</span> events, <span data-text="$interval">10</span> milliseconds
apart.<br />
<span class="text-gray-100" data-signals-total="0"> Total: <span data-text="$total">0</span> </span>
|
<span class="text-green-500" data-signals-done="0"> Done: <span data-text="$done">0</span> </span>
|
<span class="text-yellow-500" data-signals-warn="0"> Warn: <span data-text="$warn">0</span> </span>
|
<span class="text-red-500" data-signals-fail="0"> Fail: <span data-text="$fail">0</span> </span>
|
<span class="text-blue-500" data-signals-info="0"> Info: <span data-text="$info">0</span> </span>
<br />
-------------------------------------------------------------
</div>
</div>
</body>
</html>
Loading
Loading