Skip to content
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

WIP: Direct share #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions webApp/src/main/scala/parsers/UrlConfigParsing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package wust.webApp.parsers

import cats.data.NonEmptyList
import wust.graph.Page
import wust.ids.{Cuid, NodeId, View, ViewOperator}
import wust.ids._
import wust.webApp.state._
import kantan.regex._
import kantan.regex.implicits._
import kantan.regex.generic._
import wust.api.Authentication

import scala.scalajs.js
import scala.util.Try

private object ParsingHelpers {
def decodeSeq[A](list: Seq[DecodeResult[A]]): DecodeResult[Seq[A]] =
Expand Down Expand Up @@ -143,8 +144,15 @@ object UrlConfigParser {
result match {
case Right(cfg) => searchOptions.fold(cfg) { searchOptions =>
//Keep in sync with site.webmanifest where mapping of share url is defined
(searchOptions.get("share-title"), searchOptions.get("share-text"), searchOptions.get("share-url")) match {
case (Some(title), text, urlOption) => cfg.copy(shareOptions = Some(ShareOptions(title = title, text = text.getOrElse(""), url = urlOption.getOrElse(""))))
(
searchOptions.get("share-title"),
searchOptions.get("share-text"),
searchOptions.get("share-url"),
searchOptions.get("share-node-role").flatMap(NodeRole.fromString),
searchOptions.get("share-parent-id").flatMap(s => Try(Cuid.fromBase58(s)).toOption.map(NodeId(_)))
) match {
case (Some(title), text, urlOption, Some(nodeRole), Some(parentId)) => cfg.copy(shareOptions = Some(ShareOptions.Direct(title = title, text = text.getOrElse(""), url = urlOption.getOrElse(""), nodeRole = nodeRole, parentId = parentId)))
case (Some(title), text, urlOption, _, _) => cfg.copy(shareOptions = Some(ShareOptions.PreFill(title = title, text = text.getOrElse(""), url = urlOption.getOrElse(""))))
case _ => cfg
}
}
Expand Down
14 changes: 12 additions & 2 deletions webApp/src/main/scala/state/ViewConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package wust.webApp.state

import wust.api.Authentication
import wust.graph._
import wust.ids.View
import wust.ids.{NodeId, NodeRole, View}
import wust.webApp.parsers.{UrlConfigParser, UrlConfigWriter}

// ViewConfig and UrlConfig are the configurations driving our application ui.
Expand All @@ -15,7 +15,17 @@ import wust.webApp.parsers.{UrlConfigParser, UrlConfigWriter}
//TODO: get rid of pagechange, currently needed to know whether we should get a new graph on page change or not.
// we only know whether we need this when changing the page. But it feels like mixing data and commands.

case class ShareOptions(title: String, text: String, url: String)
sealed trait ShareOptions {
def title: String
def text: String
def url: String

def content = List(title, text, url).filter(_.nonEmpty).mkString(" - ")
}
object ShareOptions {
case class PreFill(title: String, text: String, url: String) extends ShareOptions
case class Direct(title: String, text: String, url: String, nodeRole: NodeRole, parentId: NodeId) extends ShareOptions
}
case class PageChange(page: Page, needsGet: Boolean = true)

case class UrlConfig(view: Option[View], pageChange: PageChange, redirectTo: Option[View], shareOptions: Option[ShareOptions], invitation: Option[Authentication.Token]) {
Expand Down
5 changes: 1 addition & 4 deletions webApp/src/main/scala/views/SharedViewElements.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ object SharedViewElements {
showMarkdownHelp: Boolean = false
)(implicit ctx: Ctx.Owner): VNode = {
val initialValue = if(preFillByShareApi) Rx {
state.urlConfig().shareOptions.fold("") { share =>
val elements = List(share.title, share.text, share.url).filter(_.nonEmpty)
elements.mkString(" - ")
}
state.urlConfig().shareOptions.fold("")(_.content)
}.toObservable.dropWhile(_.isEmpty) else Observable.empty // drop starting sequence of empty values. only interested once share api defined.

val autoResizer = new TextAreaAutoResizer
Expand Down