Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit 57078f7

Browse files
committed
Add a project route for Unison Share
Move the perspective routes into 1 route with 2 subroutes: Project with ProjectRoute.
1 parent 76bb32c commit 57078f7

File tree

3 files changed

+97
-76
lines changed

3 files changed

+97
-76
lines changed

src/UnisonShare/App.elm

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ init env route navKey =
6161
let
6262
( workspace, workspaceCmd ) =
6363
case route of
64-
Route.Definition _ ref ->
64+
Route.Project (Route.ProjectDefinition _ ref) ->
6565
Workspace.init env (Just ref)
6666

6767
_ ->
@@ -156,7 +156,7 @@ update msg ({ env } as model) =
156156
in
157157
( { model2 | catalog = catalog }, Cmd.map CatalogMsg cmd )
158158

159-
Route.Definition params ref ->
159+
Route.Project (Route.ProjectDefinition params ref) ->
160160
let
161161
( workspace, cmd ) =
162162
Workspace.open (newEnv params) model.workspace ref
@@ -169,7 +169,7 @@ update msg ({ env } as model) =
169169
in
170170
( model4, Cmd.batch [ Cmd.map WorkspaceMsg cmd, fetchPerspectiveCmd ] )
171171

172-
Route.Perspective params ->
172+
Route.Project (Route.ProjectRoot params) ->
173173
fetchPerspectiveAndCodebaseTree env.perspective { model2 | env = newEnv params }
174174

175175
( _, ChangePerspective perspective ) ->
@@ -233,27 +233,20 @@ update msg ({ env } as model) =
233233
in
234234
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )
235235

236-
( _, WorkspaceMsg wMsg ) ->
237-
-- TODO: Clean this up, there should be a top level Project route
238-
-- instead of 2 separate workspace routes (perspective and
239-
-- definition)
240-
if model.route /= Route.Catalog then
241-
let
242-
( workspace, wCmd, outMsg ) =
243-
Workspace.update env wMsg model.workspace
244-
245-
model2 =
246-
{ model | workspace = workspace }
236+
( Route.Project _, WorkspaceMsg wMsg ) ->
237+
let
238+
( workspace, wCmd, outMsg ) =
239+
Workspace.update env wMsg model.workspace
247240

248-
( model3, cmd ) =
249-
handleWorkspaceOutMsg model2 outMsg
250-
in
251-
( model3, Cmd.batch [ cmd, Cmd.map WorkspaceMsg wCmd ] )
241+
model2 =
242+
{ model | workspace = workspace }
252243

253-
else
254-
( model, Cmd.none )
244+
( model3, cmd ) =
245+
handleWorkspaceOutMsg model2 outMsg
246+
in
247+
( model3, Cmd.batch [ cmd, Cmd.map WorkspaceMsg wCmd ] )
255248

256-
( _, PerspectiveLandingMsg rMsg ) ->
249+
( Route.Project (Route.ProjectRoot _), PerspectiveLandingMsg rMsg ) ->
257250
let
258251
( perspectiveLanding, outMsg ) =
259252
PerspectiveLanding.update rMsg model.perspectiveLanding
@@ -271,7 +264,7 @@ update msg ({ env } as model) =
271264
PerspectiveLanding.None ->
272265
( model2, Cmd.none )
273266

274-
( _, CodebaseTreeMsg cMsg ) ->
267+
( Route.Project _, CodebaseTreeMsg cMsg ) ->
275268
let
276269
( codebaseTree, cCmd, outMsg ) =
277270
CodebaseTree.update env cMsg model.codebaseTree
@@ -690,7 +683,7 @@ view model =
690683
Route.Catalog ->
691684
Html.map CatalogMsg (Catalog.view model.catalog)
692685

693-
Route.Perspective _ ->
686+
Route.Project (Route.ProjectRoot _) ->
694687
Html.map PerspectiveLandingMsg
695688
(PerspectiveLanding.view
696689
model.env
@@ -699,7 +692,7 @@ view model =
699692
|> withSidebar
700693
|> PageLayout.view
701694

702-
Route.Definition _ _ ->
695+
Route.Project (Route.ProjectDefinition _ _) ->
703696
Html.map WorkspaceMsg (Workspace.view model.workspace)
704697
|> withSidebar
705698
|> PageLayout.view

src/UnisonShare/Route.elm

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module UnisonShare.Route exposing
2-
( Route(..)
2+
( ProjectRoute(..)
3+
, Route(..)
34
, forProject
45
, fromUrl
56
, navigate
@@ -73,10 +74,14 @@ import Url.Builder exposing (relative)
7374
-}
7475

7576

77+
type ProjectRoute
78+
= ProjectRoot PerspectiveParams
79+
| ProjectDefinition PerspectiveParams Reference
80+
81+
7682
type Route
7783
= Catalog
78-
| Perspective PerspectiveParams
79-
| Definition PerspectiveParams Reference
84+
| Project ProjectRoute
8085

8186

8287
updatePerspectiveParams : Route -> PerspectiveParams -> Route
@@ -85,11 +90,11 @@ updatePerspectiveParams route params =
8590
Catalog ->
8691
Catalog
8792

88-
Perspective _ ->
89-
Perspective params
93+
Project (ProjectRoot _) ->
94+
Project (ProjectRoot params)
9095

91-
Definition _ ref ->
92-
Definition params ref
96+
Project (ProjectDefinition _ ref) ->
97+
Project (ProjectDefinition params ref)
9398

9499

95100

@@ -103,12 +108,12 @@ catalog =
103108

104109
perspective : Parser Route
105110
perspective =
106-
succeed Perspective |. slash |= RP.perspectiveParams |. end
111+
succeed (ProjectRoot >> Project) |. slash |= RP.perspectiveParams |. end
107112

108113

109114
definition : Parser Route
110115
definition =
111-
succeed Definition |. slash |= RP.perspectiveParams |. slash |= reference |. end
116+
succeed (\pp r -> Project (ProjectDefinition pp r)) |. slash |= RP.perspectiveParams |. slash |= reference |. end
112117

113118

114119
toRoute : Parser Route
@@ -149,7 +154,7 @@ fromUrl basePath url =
149154
"/" ++ path
150155

151156
parse url_ =
152-
Result.withDefault (Perspective (ByCodebase Relative)) (Parser.run toRoute url_)
157+
Result.withDefault (Project (ProjectRoot (ByCodebase Relative))) (Parser.run toRoute url_)
153158
in
154159
url
155160
|> .path
@@ -168,11 +173,11 @@ perspectiveParams route =
168173
Catalog ->
169174
Nothing
170175

171-
Perspective nsRef ->
172-
Just nsRef
176+
Project (ProjectRoot pp) ->
177+
Just pp
173178

174-
Definition nsRef _ ->
175-
Just nsRef
179+
Project (ProjectDefinition pp _) ->
180+
Just pp
176181

177182

178183

@@ -185,7 +190,7 @@ forProject project_ =
185190
fqn =
186191
FQN.cons (Project.ownerToString project_.owner) project_.name
187192
in
188-
Perspective (Perspective.ByNamespace Relative fqn)
193+
Project (ProjectRoot (Perspective.ByNamespace Relative fqn))
189194

190195

191196

@@ -200,7 +205,7 @@ toDefinition oldRoute ref =
200205
|> perspectiveParams
201206
|> Maybe.withDefault (ByCodebase Relative)
202207
in
203-
Definition params ref
208+
Project (ProjectDefinition params ref)
204209

205210

206211
toUrlString : Route -> String
@@ -253,10 +258,10 @@ toUrlString route =
253258
Catalog ->
254259
[ "catalog" ]
255260

256-
Perspective pp ->
261+
Project (ProjectRoot pp) ->
257262
perspectiveParamsToPath pp False
258263

259-
Definition pp ref ->
264+
Project (ProjectDefinition pp ref) ->
260265
case ref of
261266
TypeReference hq ->
262267
perspectiveParamsToPath pp True ++ ("types" :: hqToPath hq)
@@ -284,9 +289,13 @@ navigate navKey route =
284289
|> Nav.pushUrl navKey
285290

286291

292+
293+
-- TODO: this should go away in UnisonShare
294+
295+
287296
navigateToPerspective : Nav.Key -> PerspectiveParams -> Cmd msg
288297
navigateToPerspective navKey perspectiveParams_ =
289-
navigate navKey (Perspective perspectiveParams_)
298+
navigate navKey (Project (ProjectRoot perspectiveParams_))
290299

291300

292301
navigateToCurrentPerspective : Nav.Key -> Route -> Cmd msg
@@ -310,6 +319,10 @@ navigateToDefinition navKey currentRoute reference =
310319
navigate navKey (toDefinition currentRoute reference)
311320

312321

322+
323+
-- TODO: This should go away in UnisonShare
324+
325+
313326
replacePerspective : Nav.Key -> PerspectiveParams -> Route -> Cmd msg
314327
replacePerspective navKey perspectiveParams_ oldRoute =
315328
let
@@ -318,10 +331,10 @@ replacePerspective navKey perspectiveParams_ oldRoute =
318331
Catalog ->
319332
Catalog
320333

321-
Perspective _ ->
322-
Perspective perspectiveParams_
334+
Project (ProjectRoot _) ->
335+
Project (ProjectRoot perspectiveParams_)
323336

324-
Definition _ ref ->
325-
Definition perspectiveParams_ ref
337+
Project (ProjectDefinition _ ref) ->
338+
Project (ProjectDefinition perspectiveParams_ ref)
326339
in
327340
navigate navKey newRoute

0 commit comments

Comments
 (0)