From 71c20233ff79e696d0eeca2ce1462d3083fbcfed Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 15 Jun 2025 04:59:49 +0700 Subject: and were done, just like that --- bs5/server/pages/SinglePageRSC.re | 232 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 bs5/server/pages/SinglePageRSC.re (limited to 'bs5/server/pages/SinglePageRSC.re') diff --git a/bs5/server/pages/SinglePageRSC.re b/bs5/server/pages/SinglePageRSC.re new file mode 100644 index 0000000..685069a --- /dev/null +++ b/bs5/server/pages/SinglePageRSC.re @@ -0,0 +1,232 @@ +open Rsc; +module Section = { + [@react.component] + let make = (~title, ~children, ~description=?) => { + +

+ {React.string(title)} +

+ {switch (description) { + | Some(description) => + description + | None => React.null + }} +
+ children + ; + }; +}; + +module ExpandedContent = { + [@react.component] + let make = (~id, ~content: string, ~updatedAt: float, ~title: string) => { + let lastUpdatedAt = + if (Date.is_today(updatedAt)) { + Date.format_time(updatedAt); + } else { + Date.format_date(updatedAt); + }; + + let summary = + content |> Markdown.extract_text |> Markdown.summarize(~words=20); + + + {switch (String.trim(summary)) { + | "" => {React.string("(No content)")} + | s => s + }} + +
+ }> +
+ title + lastUpdatedAt +
+ ; + }; +}; + +module Page = { + [@react.async.component] + let make = () => { + let promiseIn2 = + Lwt.bind(Lwt_unix.sleep(2.0), _ => + Lwt.return("Solusionao in 2 seconds!") + ); + let promiseIn4 = + Lwt.bind(Lwt_unix.sleep(4.0), _ => + Lwt.return("Solusionao in 4 seconds!") + ); + + Lwt.return( + + +

+ {React.string( + "Server side rendering server components and client components", + )} +

+ + "React server components. Lazy loading of client components. Client props encodings, such as promises, React elements, and primitive types." + +
+
+
+ +
+
+
+ {React.string("H E A D E R")} )} + string_list=["Item 1", "Item 2"] + promise=promiseIn2> +
+ {React.string( + "This footer is a React.element as a server component into client prop, yay!", + )} +
+
+
+
+
+ {React.string("H E A D E R")} )} + string_list=["Item 1", "Item 2"] + promise=promiseIn2> +
+ {React.string( + "This footer is a React.element as a server component into client prop, yay!", + )} +
+
+
+
+
+ +
+
+
+ +
+
+

+ {React.string("Server functions")} +

+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
, + ); + }; +}; + +module App = { + [@react.component] + let make = () => { + + + + + + +
+ +
+ + ; + }; +}; + +let handler = request => + DreamRSC.create_from_request( + ~bootstrap_modules=["/static/demo/SinglePageRSC.re.js"], + , + request, + ); -- cgit v1.2.3