From f01901e2b3866a4ed7da2f769b5694cc2ba0ed18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Mon, 17 Jul 2023 11:16:01 -0400 Subject: [PATCH] Add various url parses back from share --- src/Code/Branch.elm | 5 ++- src/Code/Project/ProjectRef.elm | 3 ++ src/Code/UrlParsers.elm | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/Code/Branch.elm b/src/Code/Branch.elm index f3c40467..6c838632 100644 --- a/src/Code/Branch.elm +++ b/src/Code/Branch.elm @@ -8,10 +8,9 @@ import Json.Decode.Pipeline exposing (required) import UI.DateTime as DateTime exposing (DateTime) -type alias Branch b p = +type alias Branch b = { b | ref : BranchRef - , project : Project p , createdAt : DateTime , updatedAt : DateTime , causalHash : Hash @@ -19,7 +18,7 @@ type alias Branch b p = type alias BranchSummary = - Branch {} {} + Branch { project : Project {} } decodeSummary : Decode.Decoder BranchSummary diff --git a/src/Code/Project/ProjectRef.elm b/src/Code/Project/ProjectRef.elm index 88dd7cdd..b1d8268f 100644 --- a/src/Code/Project/ProjectRef.elm +++ b/src/Code/Project/ProjectRef.elm @@ -1,3 +1,6 @@ +{- TODO: Move this to UnisonShare, its not compatible with UCM projects -} + + module Code.Project.ProjectRef exposing ( ProjectRef , decode diff --git a/src/Code/UrlParsers.elm b/src/Code/UrlParsers.elm index c5cdd767..6674084b 100644 --- a/src/Code/UrlParsers.elm +++ b/src/Code/UrlParsers.elm @@ -10,11 +10,14 @@ module Code.UrlParsers exposing (..) +import Code.BranchRef as BranchRef exposing (BranchRef, BranchSlug) import Code.Definition.Reference exposing (Reference(..)) import Code.FullyQualifiedName as FQN exposing (FQN) import Code.Hash as Hash exposing (Hash) import Code.HashQualified exposing (HashQualified(..)) import Code.Perspective exposing (PerspectiveParams(..), RootPerspective(..)) +import Code.Version as Version exposing (Version) +import Lib.UserHandle as UserHandle exposing (UserHandle) import Parser exposing ((|.), (|=), Parser, backtrackable, keyword, succeed) @@ -59,6 +62,67 @@ fqnEnd = Parser.symbol ";" +userHandle : Parser UserHandle +userHandle = + let + parseMaybe mhandle = + case mhandle of + Just u -> + Parser.succeed u + + Nothing -> + Parser.problem "Invalid handle" + in + Parser.chompUntilEndOr "/" + |> Parser.getChompedString + |> Parser.map UserHandle.fromString + |> Parser.andThen parseMaybe + + +version : Parser Version +version = + let + parseMaybe mversion = + case mversion of + Just s_ -> + Parser.succeed s_ + + Nothing -> + Parser.problem "Invalid Version" + in + Parser.chompUntilEndOr "/" + |> Parser.getChompedString + |> Parser.map Version.fromUrlString + |> Parser.andThen parseMaybe + + +branchRef : Parser BranchRef +branchRef = + Parser.oneOf + [ b (succeed BranchRef.releaseDraftBranchRef |. s "releases" |. slash |. s "drafts" |. slash |= version) + , b (succeed BranchRef.releaseBranchRef |. s "releases" |. slash |= version) + , b (succeed BranchRef.contributorBranchRef |= userHandle |. slash |= branchSlug) + , b (succeed BranchRef.projectBranchRef |= branchSlug) + ] + + +branchSlug : Parser BranchSlug +branchSlug = + let + parseMaybe mslug = + case mslug of + Just s_ -> + Parser.succeed s_ + + Nothing -> + Parser.problem "Invalid Slug" + in + Parser.chompUntilEndOr "/" + |> Parser.getChompedString + |> Parser.map BranchRef.branchSlugFromString + |> Parser.andThen parseMaybe + + {-| Hash example url segment: "@asd123". contextual positioning in the url makes this different than a UserHandle -}