Skip to content

Commit

Permalink
webapp: Replace Doc Page with external links
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed Nov 28, 2023
1 parent 0fbe76d commit 1f1bcff
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 44 deletions.
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,15 @@ lazy val webapp = project
libraryDependencies ++= Seq(D.laminar.value, D.waypoint.value, D.upickle.value),
libraryDependencies ++= Seq(D.zio.value, D.zioJson.value),
)
.settings( // for doc
libraryDependencies += D.laika.value,
Compile / sourceGenerators += {
val needThis: Task[Unit] = (docs / mdoc).toTask("").taskValue
val generateCode: Task[Seq[File]] = makeDocSources.taskValue
needThis.flatMap(unit => generateCode)
// I have no clue what I did here but types match and its working =)
},
)
// .settings( // for doc
// libraryDependencies += D.laika.value,
// Compile / sourceGenerators += {
// val needThis: Task[Unit] = (docs / mdoc).toTask("").taskValue
// val generateCode: Task[Seq[File]] = makeDocSources.taskValue
// needThis.flatMap(unit => generateCode)
// // I have no clue what I did here but types match and its working =)
// },
// )
.dependsOn(didExample.js)
.dependsOn(serviceworker)

Expand Down
21 changes: 16 additions & 5 deletions webapp/src/main/scala/fmgp/webapp/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ object App {

lazy val appElement = {
div(
AppUtils.drawer(linkPages, MyRouter.router.currentPageSignal),
AppUtils.drawer(
currentPage = MyRouter.router.currentPageSignal,
linkPages = linkPages,
wipLinkPages = wipLinkPages,
deprecatedLinkPages = deprecatedLinkPages
),
AppUtils.drawerScrim,
AppUtils.topBarHeader(MyRouter.router.currentPageSignal.map {
case p: HomePage.type => "DID Comm v2 - Playground"
Expand Down Expand Up @@ -71,7 +76,7 @@ object App {
.collectStatic(NFCScannerPage)(NFCScannerTool())
.collectStatic(WebBluetoothPage)(WebBluetoothTool())
.collectStatic(DiscordBotPage)(DiscordBotInfo())
.collectSignal[DocPage](page => Doc(page))
// .collectSignal[DocPage](page => Doc(page))
.collectStatic(AgentManagementPage)(AgentManagement())
// .collectStatic(AgentDBPage)(AgentDB())
.collectStatic(AgentMessageStoragePage)(AgentMessageStorage())
Expand All @@ -88,17 +93,23 @@ object App {
SettingsPage,
QRcodePage,
NFCScannerPage,
WebBluetoothPage,
DiscordBotPage,
OOBPage(oobExample),
ResolverPage(didExample),
AgentManagementPage,
AgentMessageStoragePage,
EncryptPage,
DecryptPage,
)

private val wipLinkPages: List[Page] = List(
WebBluetoothPage,
DiscordBotPage,
)

private val deprecatedLinkPages: List[Page] = List(
TapIntoStreamPage,
// AgentDBPage,
DocPage(Seq()),
// DocPage(Seq()),
BasicMessagePage,
TrustPingPage,
// DAppStorePage,
Expand Down
102 changes: 83 additions & 19 deletions webapp/src/main/scala/fmgp/webapp/AppUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,39 +122,95 @@ object AppUtils { // TODO RENAME TO UIUtils
}

val drawerScrim = div(className("mdc-drawer-scrim"))
def drawer(linkPages: List[Page], currentPage: Signal[Page]) =

def drawer(
currentPage: Signal[Page],
linkPages: List[Page],
wipLinkPages: List[Page],
deprecatedLinkPages: List[Page]
) =
asideTag(
className("mdc-drawer mdc-drawer--modal"),
div(
className("mdc-drawer__header"),
h3(className("mdc-drawer__title"), "FMGP scala-did"),
h3(className("mdc-drawer__title"), "FMGP Scala-DID"),
h6(className("mdc-drawer__subtitle"), "[email protected]"),
),
div(
className("mdc-drawer__content"),
navTag(
className("mdc-list"),
linkPages.map(page =>
a(
className <-- currentPage.map { p =>
if (p == page) "mdc-list-item mdc-list-item--activated" else "mdc-list-item"
},
aria.current := "page",
tabIndex(0),
span(className("mdc-list-item__ripple")),
i(
className("material-icons mdc-list-item__graphic"),
aria.hidden(true),
page.icon
),
navigateTo(page),
span(className("mdc-list-item__text"), page.title),
),
)
linkPages.map(page => drawerAux(currentPage, page)),
hr(className := "mdc-list-divider"),
h6(className := "mdc-list-group__subheader", "WIP Tools"),
wipLinkPages.map(page => drawerAux(currentPage, page)),
hr(className := "mdc-list-divider"),
h6(className := "mdc-list-group__subheader", "Deprecated Tools"),
deprecatedLinkPages.map(page => drawerAux(currentPage, page)),
hr(className := "mdc-list-divider"),
h6(className := "mdc-list-group__subheader", "External Links"),
drawerItemExternalLink(
url = "https://doc.did.fmgp.app/",
icon = "menu_book",
text = "Scala-DID Documentation"
),
drawerItemExternalLink(
url = "https://doc.did.fmgp.app/api/",
icon = "api",
text = "Scala-DID Scaladoc API"
),
drawerItemExternalLink(
url = "https://github.com/FabioPinheiro/scala-did",
icon = "code",
text = "Scala-DID Source"
),
drawerItemExternalLink(
url = "https://identity.foundation/didcomm-messaging/spec/",
icon = "menu_book",
text = "DID Comm V2 Specification"
),
drawerItemExternalLink(
url = "https://didcomm.org/search/?page=1",
icon = "design_services",
text = "DID Comm Protocols"
),
drawerItemExternalLink(
url = "https://dev.uniresolver.io/",
icon = "travel_explore",
text = "Universal Resolver"
),
drawerItemExternalLink(url = "https://demo.didcomm.org/", icon = "chat", text = "Chat Demo"),
drawerItemExternalLink(url = "https://didlint.ownyourdata.eu/", icon = "fact_check", text = "DID Lint"),
)
)
)

private def drawerAux(currentPage: Signal[Page], page: Page) = a(
className <-- currentPage.map { p =>
if (p == page) "mdc-list-item mdc-list-item--activated" else "mdc-list-item"
},
aria.current := "page",
tabIndex(0),
span(className("mdc-list-item__ripple")),
i(
className("material-icons mdc-list-item__graphic"),
aria.hidden(true),
page.icon
),
navigateTo(page),
span(className("mdc-list-item__text"), page.title),
)
private def drawerItemExternalLink(url: String, icon: String, text: String) = a(
href := url,
target := "_blank",
className := "mdc-list-item",
aria.current := "page",
tabIndex(0),
span(className("mdc-list-item__ripple")),
i(className("material-icons mdc-list-item__graphic"), aria.hidden(true), icon),
span(className("mdc-list-item__text"), text),
)

def myButton(text: String) = {
div(
className("mdc-touch-target-wrapper"),
Expand All @@ -170,4 +226,12 @@ object AppUtils { // TODO RENAME TO UIUtils
def linkToResolveDID(subject: DIDSubject) =
a(subject.did, MyRouter.navigateTo(MyRouter.ResolverPage(subject.did)))

def openDocumentation = a(
href := "https://doc.did.fmgp.app/",
"Open ",
b("Documentation"),
// MyRouter.navigateTo(page),
i(className("material-icons mdc-list-item__graphic"), aria.hidden(true), "menu_book")
)

}
4 changes: 3 additions & 1 deletion webapp/src/main/scala/fmgp/webapp/Doc.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
package fmgp.webapp
import org.scalajs.dom
Expand Down Expand Up @@ -53,7 +54,7 @@ object Doc {
}
.build
.parser
.parse(fmgp.did.DocSource.quickstart_basic_examples_md)
.parse(fmgp.did.DocSource._01_about_01_scala_did_md)
// .transform(fmgp.did.DocSource.quickstart_basic_examples_md, laika.ast.Path(List("doc", "fixme")) match
// case Left(value) => value.message
// case Right(value) => value
Expand Down Expand Up @@ -86,3 +87,4 @@ object Doc {
)
}
}
*/
8 changes: 6 additions & 2 deletions webapp/src/main/scala/fmgp/webapp/Home.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ object Home {
def apply(): HtmlElement = // rootElement
div(
p("Sandbox for DID Comm v2.1"),
// showPage(MyRouter.DocPage(Seq()), "Documentation for scala-did lib"),
AppUtils.openDocumentation,
br(),
showPage(MyRouter.SettingsPage, "Settings Page"),
showPage(MyRouter.AgentManagementPage, "Agent Management"),
showPage(MyRouter.AgentMessageStoragePage, "Agent Message Storage"),
Expand All @@ -49,12 +52,12 @@ object Home {
showPage(MyRouter.BasicMessagePage, "Basic Message"),
showPage(MyRouter.TrustPingPage, "Trust Ping"),
showPage(MyRouter.TapIntoStreamPage, "TapIntoStream Tool"),
showPage(MyRouter.DocPage(Seq()), "Documentation for scala-did lib"),
br(),
p("Ideas for experiments and applications:"),
ul(
li("[Done] DID Comm over Websocket"),
li("[WIP] DID Comm over Push API"),
li("GitHub action step: a simple DID agent that sends a message"),
li("DID Comm Protocol to Bootstrap WebRTC"),
li("DID Comm over WebRTC: This would be indeed very interesting"),
li("DID Comm over Email (in top of a SMTP server): Prove the control/ownership of emails addresses"),
Expand All @@ -63,9 +66,10 @@ object Home {
li("DID Comm over Audio Waves"),
),
br(),
p("DIDs:"),
p("DIDs setup:"),
div(child <-- statementVar.signal.map(e => getHtml(e)))
)

def getHtml(statement: Option[Statement], indent: Int = 0): ReactiveHtmlElement[HTMLElement] =
div(className("mermaid"), statementToMermaid(statement), onMountCallback(ctx => { Global.update("div.mermaid") }))

Expand Down
16 changes: 8 additions & 8 deletions webapp/src/main/scala/fmgp/webapp/MyRouter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object MyRouter {
case object NFCScannerPage extends Page("NFCScanner", "nfc") // or "contactless"
case object WebBluetoothPage extends Page("WebBluetooth", "bluetooth")
case object DiscordBotPage extends Page("DiscordBot", "smart_toy")
case class DocPage(path: Seq[String]) extends Page("Doc", "menu_book")
// case class DocPage(path: Seq[String]) extends Page("Doc", "menu_book")
case object AgentManagementPage extends Page("AgentManagement", "manage_accounts")
// case object DIDPage extends Page("DID", "visibility")
// case object AgentDBPage extends Page("MessageDB", "folder_open")
Expand All @@ -47,7 +47,7 @@ object MyRouter {
given nfcScannerPageRW: ReadWriter[NFCScannerPage.type] = macroRW
given webBluetoothPageRW: ReadWriter[WebBluetoothPage.type] = macroRW
given discordBotPageRW: ReadWriter[DiscordBotPage.type] = macroRW
given docPageRW: ReadWriter[DocPage] = macroRW
// given docPageRW: ReadWriter[DocPage] = macroRW
given keysPageRW: ReadWriter[AgentManagementPage.type] = macroRW
// given agentDBPageRW: ReadWriter[AgentDBPage.type] = macroRW
given agentMessageStoragePageRW: ReadWriter[AgentMessageStoragePage.type] = macroRW
Expand Down Expand Up @@ -91,12 +91,12 @@ object MyRouter {
Route.static(TrustPingPage, root / "trustping" / endOfSegments, Router.localFragmentBasePath),
Route.static(TapIntoStreamPage, root / "stream" / endOfSegments, Router.localFragmentBasePath),
Route.static(DAppStorePage, root / "dapp" / endOfSegments, Router.localFragmentBasePath),
Route[DocPage, List[String]](
encode = page => page.path.toList,
decode = arg => DocPage(path = if (arg.isEmpty) Seq("readme.md") else arg.toSeq),
pattern = root / "doc" / remainingSegments,
Router.localFragmentBasePath
),
// Route[DocPage, List[String]](
// encode = page => page.path.toList,
// decode = arg => DocPage(path = if (arg.isEmpty) Seq("readme.md") else arg.toSeq),
// pattern = root / "doc" / remainingSegments,
// Router.localFragmentBasePath
// ),
)

val router = new Router[Page](
Expand Down

0 comments on commit 1f1bcff

Please sign in to comment.