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

Add keyboard support to catalog search #303

Merged
merged 1 commit into from
Jan 12, 2022
Merged
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
7 changes: 5 additions & 2 deletions src/Env.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Env exposing (..)

import Api exposing (ApiBasePath(..))
import Browser.Navigation as Nav
import Env.AppContext as AppContext exposing (AppContext)
import Perspective exposing (Perspective)

Expand All @@ -19,6 +20,7 @@ type alias Env =
, basePath : String
, apiBasePath : ApiBasePath
, appContext : AppContext
, navKey : Nav.Key
, perspective : Perspective
}

Expand All @@ -31,12 +33,13 @@ type alias Flags =
}


init : Flags -> Perspective -> Env
init flags perspective =
init : Flags -> Nav.Key -> Perspective -> Env
init flags navKey perspective =
{ operatingSystem = operatingSystemFromString flags.operatingSystem
, basePath = flags.basePath
, apiBasePath = ApiBasePath flags.apiBasePath
, appContext = AppContext.fromString flags.appContext
, navKey = navKey
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the navKey out of the App model and into Env so that we can navigate from any page.

, perspective = perspective
}

Expand Down
6 changes: 6 additions & 0 deletions src/SearchResults.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module SearchResults exposing
( Matches
, SearchResults(..)
, empty
, focus
, focusOn
, from
Expand Down Expand Up @@ -32,6 +33,11 @@ type SearchResults a
| SearchResults (Matches a)


empty : SearchResults a
empty =
Empty


isEmpty : SearchResults a -> Bool
isEmpty results =
case results of
Expand Down
22 changes: 10 additions & 12 deletions src/UnisonLocal/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ type Modal


type alias Model =
{ navKey : Nav.Key
, route : Route
{ route : Route
, codebaseTree : CodebaseTree.Model
, workspace : Workspace.Model
, perspectiveLanding : PerspectiveLanding.Model
Expand All @@ -63,8 +62,8 @@ type alias Model =
}


init : Env -> Route -> Nav.Key -> ( Model, Cmd Msg )
init env route navKey =
init : Env -> Route -> ( Model, Cmd Msg )
init env route =
let
( workspace, workspaceCmd ) =
case route of
Expand All @@ -84,8 +83,7 @@ init env route navKey =
|> Maybe.withDefault Cmd.none

model =
{ navKey = navKey
, route = route
{ route = route
, workspace = workspace
, perspectiveLanding = PerspectiveLanding.init
, codebaseTree = codebaseTree
Expand Down Expand Up @@ -132,7 +130,7 @@ update msg ({ env } as model) =
LinkClicked urlRequest ->
case urlRequest of
Browser.Internal url ->
( model, Nav.pushUrl model.navKey (Url.toString url) )
( model, Nav.pushUrl env.navKey (Url.toString url) )

-- External links are handled via target blank and never end up
-- here
Expand Down Expand Up @@ -298,7 +296,7 @@ update msg ({ env } as model) =

navigateToDefinition : Model -> Reference -> ( Model, Cmd Msg )
navigateToDefinition model ref =
( model, Route.navigateToDefinition model.navKey model.route ref )
( model, Route.navigateToDefinition model.env.navKey model.route ref )


navigateToPerspective : Model -> Perspective -> ( Model, Cmd Msg )
Expand All @@ -318,7 +316,7 @@ navigateToPerspective model perspective =
|> Maybe.withDefault model.route

changeRouteCmd =
Route.replacePerspective model.navKey (Perspective.toParams perspective) focusedReferenceRoute
Route.replacePerspective model.env.navKey (Perspective.toParams perspective) focusedReferenceRoute
in
( { model | workspace = workspace }, changeRouteCmd )

Expand Down Expand Up @@ -351,7 +349,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =


handleWorkspaceOutMsg : Model -> Workspace.OutMsg -> ( Model, Cmd Msg )
handleWorkspaceOutMsg model out =
handleWorkspaceOutMsg ({ env } as model) out =
case out of
Workspace.None ->
( model, Cmd.none )
Expand All @@ -360,10 +358,10 @@ handleWorkspaceOutMsg model out =
showFinder model withinNamespace

Workspace.Focused ref ->
( model, Route.navigateToDefinition model.navKey model.route ref )
( model, Route.navigateToDefinition env.navKey model.route ref )

Workspace.Emptied ->
( model, Route.navigateToCurrentPerspective model.navKey model.route )
( model, Route.navigateToCurrentPerspective env.navKey model.route )

Workspace.ChangePerspectiveToNamespace fqn ->
fqn
Expand Down
8 changes: 4 additions & 4 deletions src/UnisonLocal/PreApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ init flags url navKey =
perspectiveToAppInit perspective =
let
env =
Env.init preEnv.flags perspective
Env.init preEnv.flags preEnv.navKey perspective

( app, cmd ) =
App.init env preEnv.route preEnv.navKey
App.init env preEnv.route
in
( Initialized app, Cmd.map AppMsg cmd )

Expand Down Expand Up @@ -79,15 +79,15 @@ update msg model =
Ok perspective ->
let
env =
Env.init preEnv.flags perspective
Env.init preEnv.flags preEnv.navKey perspective

newRoute =
perspective
|> Perspective.toParams
|> Route.updatePerspectiveParams preEnv.route

( app, cmd ) =
App.init env newRoute preEnv.navKey
App.init env newRoute
in
( Initialized app, Cmd.map AppMsg cmd )

Expand Down
26 changes: 12 additions & 14 deletions src/UnisonShare/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ import Workspace.WorkspaceItems as WorkspaceItems


type alias Model =
{ navKey : Nav.Key
, route : Route
{ route : Route
, codebaseTree : CodebaseTree.Model
, workspace : Workspace.Model
, perspectiveLanding : PerspectiveLanding.Model
Expand All @@ -56,8 +55,8 @@ type alias Model =
}


init : Env -> Route -> Nav.Key -> ( Model, Cmd Msg )
init env route navKey =
init : Env -> Route -> ( Model, Cmd Msg )
init env route =
let
-- TODO: This whole thing should be route driven
( workspace, workspaceCmd ) =
Expand All @@ -81,8 +80,7 @@ init env route navKey =
Catalog.init env

model =
{ navKey = navKey
, route = route
{ route = route
, workspace = workspace
, perspectiveLanding = PerspectiveLanding.init
, codebaseTree = codebaseTree
Expand Down Expand Up @@ -131,7 +129,7 @@ update msg ({ env } as model) =
( _, LinkClicked urlRequest ) ->
case urlRequest of
Browser.Internal url ->
( model, Nav.pushUrl model.navKey (Url.toString url) )
( model, Nav.pushUrl env.navKey (Url.toString url) )

-- External links are handled via target blank and never end up
-- here
Expand Down Expand Up @@ -230,7 +228,7 @@ update msg ({ env } as model) =
( Route.Catalog, CatalogMsg cMsg ) ->
let
( catalog, cmd ) =
Catalog.update cMsg model.catalog
Catalog.update env cMsg model.catalog
in
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )

Expand Down Expand Up @@ -310,7 +308,7 @@ update msg ({ env } as model) =

navigateToDefinition : Model -> Reference -> ( Model, Cmd Msg )
navigateToDefinition model ref =
( model, Route.navigateToDefinition model.navKey model.route ref )
( model, Route.navigateToDefinition model.env.navKey model.route ref )


navigateToPerspective : Model -> Perspective -> ( Model, Cmd Msg )
Expand All @@ -330,7 +328,7 @@ navigateToPerspective model perspective =
|> Maybe.withDefault model.route

changeRouteCmd =
Route.replacePerspective model.navKey (Perspective.toParams perspective) focusedReferenceRoute
Route.replacePerspective model.env.navKey (Perspective.toParams perspective) focusedReferenceRoute
in
( { model | workspace = workspace }, changeRouteCmd )

Expand Down Expand Up @@ -363,7 +361,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =


handleWorkspaceOutMsg : Model -> Workspace.OutMsg -> ( Model, Cmd Msg )
handleWorkspaceOutMsg model out =
handleWorkspaceOutMsg ({ env } as model) out =
case out of
Workspace.None ->
( model, Cmd.none )
Expand All @@ -372,14 +370,14 @@ handleWorkspaceOutMsg model out =
showFinder model withinNamespace

Workspace.Focused ref ->
( model, Route.navigateToDefinition model.navKey model.route ref )
( model, Route.navigateToDefinition env.navKey model.route ref )

Workspace.Emptied ->
( model, Route.navigateToCurrentPerspective model.navKey model.route )
( model, Route.navigateToCurrentPerspective env.navKey model.route )

Workspace.ChangePerspectiveToNamespace fqn ->
fqn
|> Perspective.toNamespacePerspective model.env.perspective
|> Perspective.toNamespacePerspective env.perspective
|> navigateToPerspective model


Expand Down
Loading