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

Commit d6b308e

Browse files
authored
Merge pull request #303 from unisonweb/catalog-search-keyboard
Add keyboard support to catalog search
2 parents 27d28b1 + 755c41c commit d6b308e

File tree

10 files changed

+290
-84
lines changed

10 files changed

+290
-84
lines changed

src/Env.elm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Env exposing (..)
22

33
import Api exposing (ApiBasePath(..))
4+
import Browser.Navigation as Nav
45
import Env.AppContext as AppContext exposing (AppContext)
56
import Perspective exposing (Perspective)
67

@@ -19,6 +20,7 @@ type alias Env =
1920
, basePath : String
2021
, apiBasePath : ApiBasePath
2122
, appContext : AppContext
23+
, navKey : Nav.Key
2224
, perspective : Perspective
2325
}
2426

@@ -31,12 +33,13 @@ type alias Flags =
3133
}
3234

3335

34-
init : Flags -> Perspective -> Env
35-
init flags perspective =
36+
init : Flags -> Nav.Key -> Perspective -> Env
37+
init flags navKey perspective =
3638
{ operatingSystem = operatingSystemFromString flags.operatingSystem
3739
, basePath = flags.basePath
3840
, apiBasePath = ApiBasePath flags.apiBasePath
3941
, appContext = AppContext.fromString flags.appContext
42+
, navKey = navKey
4043
, perspective = perspective
4144
}
4245

src/SearchResults.elm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SearchResults exposing
22
( Matches
33
, SearchResults(..)
4+
, empty
45
, focus
56
, focusOn
67
, from
@@ -32,6 +33,11 @@ type SearchResults a
3233
| SearchResults (Matches a)
3334

3435

36+
empty : SearchResults a
37+
empty =
38+
Empty
39+
40+
3541
isEmpty : SearchResults a -> Bool
3642
isEmpty results =
3743
case results of

src/UnisonLocal/App.elm

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ type Modal
4949

5050

5151
type alias Model =
52-
{ navKey : Nav.Key
53-
, route : Route
52+
{ route : Route
5453
, codebaseTree : CodebaseTree.Model
5554
, workspace : Workspace.Model
5655
, perspectiveLanding : PerspectiveLanding.Model
@@ -64,8 +63,8 @@ type alias Model =
6463
}
6564

6665

67-
init : Env -> Route -> Nav.Key -> ( Model, Cmd Msg )
68-
init env route navKey =
66+
init : Env -> Route -> ( Model, Cmd Msg )
67+
init env route =
6968
let
7069
( workspace, workspaceCmd ) =
7170
case route of
@@ -85,8 +84,7 @@ init env route navKey =
8584
|> Maybe.withDefault Cmd.none
8685

8786
model =
88-
{ navKey = navKey
89-
, route = route
87+
{ route = route
9088
, workspace = workspace
9189
, perspectiveLanding = PerspectiveLanding.init
9290
, codebaseTree = codebaseTree
@@ -133,7 +131,7 @@ update msg ({ env } as model) =
133131
LinkClicked urlRequest ->
134132
case urlRequest of
135133
Browser.Internal url ->
136-
( model, Nav.pushUrl model.navKey (Url.toString url) )
134+
( model, Nav.pushUrl env.navKey (Url.toString url) )
137135

138136
-- External links are handled via target blank and never end up
139137
-- here
@@ -299,7 +297,7 @@ update msg ({ env } as model) =
299297

300298
navigateToDefinition : Model -> Reference -> ( Model, Cmd Msg )
301299
navigateToDefinition model ref =
302-
( model, Route.navigateToDefinition model.navKey model.route ref )
300+
( model, Route.navigateToDefinition model.env.navKey model.route ref )
303301

304302

305303
navigateToPerspective : Model -> Perspective -> ( Model, Cmd Msg )
@@ -319,7 +317,7 @@ navigateToPerspective model perspective =
319317
|> Maybe.withDefault model.route
320318

321319
changeRouteCmd =
322-
Route.replacePerspective model.navKey (Perspective.toParams perspective) focusedReferenceRoute
320+
Route.replacePerspective model.env.navKey (Perspective.toParams perspective) focusedReferenceRoute
323321
in
324322
( { model | workspace = workspace }, changeRouteCmd )
325323

@@ -352,7 +350,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =
352350

353351

354352
handleWorkspaceOutMsg : Model -> Workspace.OutMsg -> ( Model, Cmd Msg )
355-
handleWorkspaceOutMsg model out =
353+
handleWorkspaceOutMsg ({ env } as model) out =
356354
case out of
357355
Workspace.None ->
358356
( model, Cmd.none )
@@ -361,10 +359,10 @@ handleWorkspaceOutMsg model out =
361359
showFinder model withinNamespace
362360

363361
Workspace.Focused ref ->
364-
( model, Route.navigateToDefinition model.navKey model.route ref )
362+
( model, Route.navigateToDefinition env.navKey model.route ref )
365363

366364
Workspace.Emptied ->
367-
( model, Route.navigateToCurrentPerspective model.navKey model.route )
365+
( model, Route.navigateToCurrentPerspective env.navKey model.route )
368366

369367
Workspace.ChangePerspectiveToNamespace fqn ->
370368
fqn

src/UnisonLocal/PreApp.elm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ init flags url navKey =
4242
perspectiveToAppInit perspective =
4343
let
4444
env =
45-
Env.init preEnv.flags perspective
45+
Env.init preEnv.flags preEnv.navKey perspective
4646

4747
( app, cmd ) =
48-
App.init env preEnv.route preEnv.navKey
48+
App.init env preEnv.route
4949
in
5050
( Initialized app, Cmd.map AppMsg cmd )
5151

@@ -79,15 +79,15 @@ update msg model =
7979
Ok perspective ->
8080
let
8181
env =
82-
Env.init preEnv.flags perspective
82+
Env.init preEnv.flags preEnv.navKey perspective
8383

8484
newRoute =
8585
perspective
8686
|> Perspective.toParams
8787
|> Route.updatePerspectiveParams preEnv.route
8888

8989
( app, cmd ) =
90-
App.init env newRoute preEnv.navKey
90+
App.init env newRoute
9191
in
9292
( Initialized app, Cmd.map AppMsg cmd )
9393

src/UnisonShare/App.elm

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ import Workspace.WorkspaceItems as WorkspaceItems
4141

4242

4343
type alias Model =
44-
{ navKey : Nav.Key
45-
, route : Route
44+
{ route : Route
4645
, codebaseTree : CodebaseTree.Model
4746
, workspace : Workspace.Model
4847
, perspectiveLanding : PerspectiveLanding.Model
@@ -57,8 +56,8 @@ type alias Model =
5756
}
5857

5958

60-
init : Env -> Route -> Nav.Key -> ( Model, Cmd Msg )
61-
init env route navKey =
59+
init : Env -> Route -> ( Model, Cmd Msg )
60+
init env route =
6261
let
6362
-- TODO: This whole thing should be route driven
6463
( workspace, workspaceCmd ) =
@@ -82,8 +81,7 @@ init env route navKey =
8281
Catalog.init env
8382

8483
model =
85-
{ navKey = navKey
86-
, route = route
84+
{ route = route
8785
, workspace = workspace
8886
, perspectiveLanding = PerspectiveLanding.init
8987
, codebaseTree = codebaseTree
@@ -132,7 +130,7 @@ update msg ({ env } as model) =
132130
( _, LinkClicked urlRequest ) ->
133131
case urlRequest of
134132
Browser.Internal url ->
135-
( model, Nav.pushUrl model.navKey (Url.toString url) )
133+
( model, Nav.pushUrl env.navKey (Url.toString url) )
136134

137135
-- External links are handled via target blank and never end up
138136
-- here
@@ -231,7 +229,7 @@ update msg ({ env } as model) =
231229
( Route.Catalog, CatalogMsg cMsg ) ->
232230
let
233231
( catalog, cmd ) =
234-
Catalog.update cMsg model.catalog
232+
Catalog.update env cMsg model.catalog
235233
in
236234
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )
237235

@@ -311,7 +309,7 @@ update msg ({ env } as model) =
311309

312310
navigateToDefinition : Model -> Reference -> ( Model, Cmd Msg )
313311
navigateToDefinition model ref =
314-
( model, Route.navigateToDefinition model.navKey model.route ref )
312+
( model, Route.navigateToDefinition model.env.navKey model.route ref )
315313

316314

317315
navigateToPerspective : Model -> Perspective -> ( Model, Cmd Msg )
@@ -331,7 +329,7 @@ navigateToPerspective model perspective =
331329
|> Maybe.withDefault model.route
332330

333331
changeRouteCmd =
334-
Route.replacePerspective model.navKey (Perspective.toParams perspective) focusedReferenceRoute
332+
Route.replacePerspective model.env.navKey (Perspective.toParams perspective) focusedReferenceRoute
335333
in
336334
( { model | workspace = workspace }, changeRouteCmd )
337335

@@ -364,7 +362,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =
364362

365363

366364
handleWorkspaceOutMsg : Model -> Workspace.OutMsg -> ( Model, Cmd Msg )
367-
handleWorkspaceOutMsg model out =
365+
handleWorkspaceOutMsg ({ env } as model) out =
368366
case out of
369367
Workspace.None ->
370368
( model, Cmd.none )
@@ -373,14 +371,14 @@ handleWorkspaceOutMsg model out =
373371
showFinder model withinNamespace
374372

375373
Workspace.Focused ref ->
376-
( model, Route.navigateToDefinition model.navKey model.route ref )
374+
( model, Route.navigateToDefinition env.navKey model.route ref )
377375

378376
Workspace.Emptied ->
379-
( model, Route.navigateToCurrentPerspective model.navKey model.route )
377+
( model, Route.navigateToCurrentPerspective env.navKey model.route )
380378

381379
Workspace.ChangePerspectiveToNamespace fqn ->
382380
fqn
383-
|> Perspective.toNamespacePerspective model.env.perspective
381+
|> Perspective.toNamespacePerspective env.perspective
384382
|> navigateToPerspective model
385383

386384

0 commit comments

Comments
 (0)