-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use datastar::prelude::*; | ||
use chrono::Local; | ||
use async_stream::stream; | ||
|
||
let current_time = Local::now().format("%Y-%m-%d %H:%M:%S").to_string(); | ||
|
||
Sse(stream! { | ||
yield MergeFragments::new( | ||
format!( | ||
"<div id='time' data-on-interval__duration.5s='@get(\"/endpoint\")'>{}</div>", | ||
current_time | ||
) | ||
).into(); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const datastar = @import("datastar"); | ||
const zdt = @import("zdt"); | ||
const std = @import("std"); | ||
|
||
var tz_chicago = try zdt.Timezone.fromTzdata("America/Chicago", res.arena); | ||
const datetime = try zdt.Datetime.fromISO8601("2006-01-02 15:04:05"); | ||
const current_time = try a_datetime.tzLocalize(.{ .tz = &tz_chicago }); | ||
|
||
var sse = try datastar.ServerSentEventGenerator.init(res); | ||
|
||
sse.mergeFragments( | ||
std.fmt.allocPrint( | ||
res.arena, | ||
"<div id='time' data-on-interval__duration.5s='@get(\"/endpoint\")'>{s}</div>", | ||
.{current_time}, | ||
), | ||
.{}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use datastar::prelude::*; | ||
use chrono::Local; | ||
use async_stream::stream; | ||
|
||
let current_time = Local::now().format("%Y-%m-%d %H:%M:%S").to_string(); | ||
let current_seconds = Local::now().second(); | ||
let duration = if current_seconds < 50 { | ||
5 | ||
} else { | ||
1 | ||
}; | ||
|
||
Sse(stream! { | ||
yield MergeFragments::new( | ||
format!( | ||
"<div id='time' data-on-interval__duration.{}s='@get(\"/endpoint\")'>{}</div>", | ||
duration, | ||
current_time, | ||
) | ||
).into(); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const datastar = @import("datastar"); | ||
const zdt = @import("zdt"); | ||
const std = @import("std"); | ||
|
||
var tz_chicago = try zdt.Timezone.fromTzdata("America/Chicago", res.arena); | ||
const datetime = try zdt.Datetime.fromISO8601("2006-01-02 15:04:05"); | ||
const current_time = try a_datetime.tzLocalize(.{ .tz = &tz_chicago }); | ||
const current_seconds = std.time.timestamp() % 60; | ||
const duration = if (current_seconds < 50) 5 else 1; | ||
|
||
var sse = try datastar.ServerSentEventGenerator.init(res); | ||
|
||
sse.mergeFragments( | ||
std.fmt.allocPrint( | ||
res.arena, | ||
"<div id='time' data-on-interval__duration.{d}s='@get(\"/endpoint\")'>{s}</div>", | ||
.{ duration, current_time }, | ||
), | ||
.{}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use datastar::prelude::*; | ||
use async_stream::stream; | ||
use core::time::Duration; | ||
|
||
Sse(stream! { | ||
yield MergeFragments::new("<div id='indicator'>Redirecting in 3 seconds...</div>").into(); | ||
tokio::time::sleep(core::time::Duration::from_secs(3)).await; | ||
yield ExecuteScript::new("window.location = '/guide'").into(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const datastar = @import("datastar"); | ||
const std = @import("std"); | ||
|
||
var sse = try datastar.ServerSentEventGenerator.init(res); | ||
|
||
sse.mergeFragments("<div id='indicator'>Redirecting in 3 seconds...</div>"); | ||
std.Thread.sleep(std.time.ns_per_s * 3); | ||
sse.executeScript("window.location = '/guide'"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use datastar::prelude::*; | ||
use async_stream::stream; | ||
use core::time::Duration; | ||
|
||
Sse(stream! { | ||
yield MergeFragments::new("<div id='indicator'>Redirecting in 3 seconds...</div>").into(); | ||
tokio::time::sleep(core::time::Duration::from_secs(3)).await; | ||
yield ExecuteScript::new("setTimeout(() => window.location = '/guide')").into(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const datastar = @import("datastar"); | ||
const std = @import("std"); | ||
|
||
var sse = try datastar.ServerSentEventGenerator.init(res); | ||
|
||
sse.mergeFragments("<div id='indicator'>Redirecting in 3 seconds...</div>"); | ||
std.Thread.sleep(std.time.ns_per_s * 3); | ||
sse.executeScript("setTimeout(() => window.location = '/guide')"); |