Skip to content

Commit

Permalink
Merge pull request #15 from unisonweb/fix-bug-with-project-routing
Browse files Browse the repository at this point in the history
Project Routing: Fix bug where page was refreshed
  • Loading branch information
hojberg authored Aug 22, 2023
2 parents fcc358b + 7996c0d commit 90b233a
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 16 deletions.
2 changes: 1 addition & 1 deletion elm-git.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"git-dependencies": {
"direct": {
"https://github.com/unisonweb/ui-core": "437f824d14d716b3537ec53e29ba2c9fed993120"
"https://github.com/unisonweb/ui-core": "02a4a7a5ee6ca6bd040474fa929fb5f4bce20c34"
},
"indirect": {}
}
Expand Down
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
},
"indirect": {}
}
}
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/unisonweb/codebase-ui#readme",
"devDependencies": {
"@octokit/core": "^4.0.5",
"@unison-lang/ui-core-scripts": "^1.0.2",
"@unison-lang/ui-core-scripts": "^1.1.9",
"archiver": "^5.3.0",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.4",
Expand Down
35 changes: 29 additions & 6 deletions src/UnisonLocal/ProjectName.elm
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,41 @@ fromString raw =
Nothing


{-| !!! Don't use outside of of testing
-}
unsafeFromString : String -> ProjectName
unsafeFromString raw =
let
parts =
String.split "/" raw
in
case parts of
[ h, s ] ->
ProjectName (h |> UserHandle.unsafeFromString |> Just) (ProjectSlug.unsafeFromString s)

[ s ] ->
ProjectName Nothing (ProjectSlug.unsafeFromString s)

_ ->
ProjectName Nothing (ProjectSlug.unsafeFromString raw)



-- HELPERS


equals : ProjectName -> ProjectName -> Bool
equals (ProjectName handleA slugA) (ProjectName handleB slugB) =
let
handleEquals =
Maybe.map2 UserHandle.equals handleA handleB
|> Maybe.withDefault False
in
handleEquals && ProjectSlug.equals slugA slugB
case ( handleA, handleB ) of
( Just ha, Just hb ) ->
UserHandle.equals ha hb && ProjectSlug.equals slugA slugB

( Nothing, Nothing ) ->
-- if there are no handles, we only care about ProjectSlug equality
ProjectSlug.equals slugA slugB

_ ->
False


toString : ProjectName -> String
Expand Down
71 changes: 71 additions & 0 deletions tests/UnisonLocal/ProjectNameTests.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module UnisonLocal.ProjectNameTests exposing (..)

import Expect
import Test exposing (..)
import UnisonLocal.ProjectName as ProjectName


equals : Test
equals =
describe "ProjectName.equals"
[ test "is true for equal names with handles" <|
\_ ->
let
a =
ProjectName.unsafeFromString "@unison/base"

b =
ProjectName.unsafeFromString "@unison/base"
in
Expect.true "`@unison/base` is equal to `@unison/base`" (ProjectName.equals a b)
, test "is true for equal names without handles" <|
\_ ->
let
a =
ProjectName.unsafeFromString "html"

b =
ProjectName.unsafeFromString "html"
in
Expect.true "`html` is equal `html`" (ProjectName.equals a b)
, test "is false for non-equal names and handles" <|
\_ ->
let
a =
ProjectName.unsafeFromString "@alice/projectA"

b =
ProjectName.unsafeFromString "@bob/projectB"
in
Expect.false "@alice/projectA is not equal to @bob/projectB" (ProjectName.equals a b)
, test "is false for non-equal names without handles" <|
\_ ->
let
a =
ProjectName.unsafeFromString "projectA"

b =
ProjectName.unsafeFromString "projectB"
in
Expect.false "projectA is not equal to projectB" (ProjectName.equals a b)
, test "is false for equal names but not equal handles" <|
\_ ->
let
a =
ProjectName.unsafeFromString "@alice/base"

b =
ProjectName.unsafeFromString "@bob/base"
in
Expect.false "@alice/base is not equal to @bob/base" (ProjectName.equals a b)
, test "is false for non-equal names but equal handles" <|
\_ ->
let
a =
ProjectName.unsafeFromString "@alice/projectA"

b =
ProjectName.unsafeFromString "@alice/projectB"
in
Expect.false "@alice/projectA is npt equal to @alice/projectB" (ProjectName.equals a b)
]

0 comments on commit 90b233a

Please sign in to comment.