-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning up the top-level state file. Also fixes: - Context-menu which initiated drag-n-drop - Invisible track selection Adds: - Info about UI
- Loading branch information
Showing
24 changed files
with
552 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module Alfred.State exposing (..) | ||
|
||
import Alfred.System | ||
import Alfred.Types exposing (..) | ||
import Response | ||
import Keyboard.Extra as Keyboard | ||
import Types as TopLevel | ||
|
||
|
||
-- 💧 | ||
|
||
|
||
initialModel : Model TopLevel.Msg | ||
initialModel = | ||
{ instance = Nothing | ||
} | ||
|
||
|
||
|
||
-- 🔥 | ||
|
||
|
||
update : Msg TopLevel.Msg -> Model TopLevel.Msg -> ( Model TopLevel.Msg, Cmd TopLevel.Msg ) | ||
update msg model = | ||
case msg of | ||
Assign instance -> | ||
(!) { model | instance = Just instance } [] | ||
|
||
CalculateResults searchTerm -> | ||
model.instance | ||
|> Maybe.map (Alfred.System.calculateResults searchTerm) | ||
|> (\a -> { model | instance = a }) | ||
|> (\m -> ( m, Cmd.none )) | ||
|
||
Hide -> | ||
(!) { model | instance = Nothing } [] | ||
|
||
RunAction index -> | ||
model.instance | ||
|> Maybe.map (Alfred.System.runAction index) | ||
|> Maybe.map (Tuple.mapFirst <| \a -> { model | instance = Just a }) | ||
|> Maybe.withDefault ( model, Cmd.none ) | ||
|
||
------------------------------------ | ||
-- Keyboard (Down) | ||
------------------------------------ | ||
KeydownMsg Keyboard.ArrowDown -> | ||
case model.instance of | ||
Just context -> | ||
context | ||
|> (\c -> { c | focus = min (List.length c.results - 1) (c.focus + 1) }) | ||
|> (\c -> { model | instance = Just c }) | ||
|> Response.withCmd Cmd.none | ||
|
||
Nothing -> | ||
(,) model Cmd.none | ||
|
||
KeydownMsg Keyboard.ArrowUp -> | ||
case model.instance of | ||
Just context -> | ||
context | ||
|> (\c -> { c | focus = max 0 (c.focus - 1) }) | ||
|> (\c -> { model | instance = Just c }) | ||
|> Response.withCmd Cmd.none | ||
|
||
Nothing -> | ||
(,) model Cmd.none | ||
|
||
KeydownMsg _ -> | ||
(,) model Cmd.none | ||
|
||
|
||
|
||
-- 🌱 | ||
|
||
|
||
subscriptions : Model msg -> Sub (Msg msg) | ||
subscriptions _ = | ||
Sub.batch | ||
[ Keyboard.downs KeydownMsg | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Alfred.Types exposing (..) | ||
|
||
import Keyboard.Extra as Keyboard | ||
|
||
|
||
-- Messages | ||
|
||
|
||
type Msg msg | ||
= Assign (Alfred msg) | ||
| CalculateResults String | ||
| Hide | ||
| RunAction Int | ||
-- Keyboard | ||
| KeydownMsg Keyboard.Key | ||
|
||
|
||
|
||
-- Model | ||
|
||
|
||
type alias Model msg = | ||
{ instance : Maybe (Alfred msg) | ||
} | ||
|
||
|
||
|
||
-- Alfred | ||
|
||
|
||
type alias Alfred msg = | ||
{ action : Maybe String -> Maybe String -> Cmd msg | ||
, focus : Int | ||
, index : List String | ||
, message : String | ||
, results : List String | ||
, searchTerm : Maybe String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module ContextMenu.State exposing (..) | ||
|
||
import ContextMenu.Types exposing (..) | ||
import Playlists.ContextMenu | ||
import Sources.ContextMenu | ||
import Types as TopLevel | ||
|
||
|
||
-- 💧 | ||
|
||
|
||
initialModel : Model TopLevel.Msg | ||
initialModel = | ||
{ instance = Nothing | ||
} | ||
|
||
|
||
|
||
-- 🔥 | ||
|
||
|
||
update : Msg -> Model TopLevel.Msg -> ( Model TopLevel.Msg, Cmd TopLevel.Msg ) | ||
update msg model = | ||
case msg of | ||
Hide -> | ||
(!) { model | instance = Nothing } [] | ||
|
||
ShowPlaylistMenu playlistName mousePos -> | ||
let | ||
instance = | ||
mousePos | ||
|> Playlists.ContextMenu.listMenu playlistName | ||
|> Just | ||
in | ||
(!) { model | instance = instance } [] | ||
|
||
ShowSourceMenu sourceId mousePos -> | ||
let | ||
instance = | ||
mousePos | ||
|> Sources.ContextMenu.listMenu sourceId | ||
|> Just | ||
in | ||
(!) { model | instance = instance } [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module ContextMenu.Types exposing (..) | ||
|
||
import Mouse | ||
import Svg exposing (Svg) | ||
|
||
|
||
-- Messages | ||
|
||
|
||
type Msg | ||
= Hide | ||
| ShowPlaylistMenu String Mouse.Position | ||
| ShowSourceMenu String Mouse.Position | ||
|
||
|
||
|
||
-- Model | ||
|
||
|
||
type alias Model msg = | ||
{ instance : Maybe (ContextMenu msg) | ||
} | ||
|
||
|
||
|
||
-- Context Menu | ||
|
||
|
||
type ContextMenu msg | ||
= ContextMenu (ContextMenuItems msg) Mouse.Position | ||
|
||
|
||
type alias ContextMenuItems msg = | ||
List ( Svg msg, String, msg ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.