Permalink
Browse files

move search-box to top

  • Loading branch information...
1 parent d1488d3 commit be74ee7fa2dab8517ac8dd5b5b43ff46cc2e9f48 @torii-y torii-y committed Nov 29, 2016
@@ -1,5 +1,6 @@
module Component.Header exposing (..)
+import Mouse
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
@@ -14,22 +15,32 @@ import View.HeaderView as HeaderView
import InlineHover exposing (hover)
-type alias State = Bool
+type alias Model = Bool
type Msg
= ToggleUserMenu
+ | CloseUserMenu
-init : State
+init : Model
init = False
-update : Msg -> State -> State
+update : Msg -> Model -> Model
update msg menuOpened =
case msg of
ToggleUserMenu ->
not menuOpened
+ CloseUserMenu ->
+ False
+
+
+subscriptions : Sub Msg
+subscriptions =
+ -- Mouse.clicks (\_ -> CloseUserMenu)
+ Sub.none
+
type alias Context msg =
{ onSignInClicked : msg
@@ -43,37 +54,52 @@ type alias Context msg =
, user : Maybe User
, editing : Bool
, printMode : Bool
+ , searchInput : Maybe (Html msg)
}
-view : Context msg -> State -> Html msg
+view : Context msg -> Model -> Html msg
view context state =
if context.printMode then
- HeaderView.view context.printMode context.title Nothing (menu [ printButtonView context.onTogglePrintView context.lang True ])
+ HeaderView.view
+ context.printMode
+ context.title
+ Nothing
+ (menu [ printButtonView context.onTogglePrintView context.lang True ])
else
- HeaderView.view context.printMode context.title (Just "/") (normalMenu context state)
+ HeaderView.view
+ context.printMode
+ context.title
+ (Just "/")
+ (normalMenu context state)
-normalMenu : Context msg -> State -> Html msg
+normalMenu : Context msg -> Model -> Html msg
normalMenu context menuOpened =
- menu <|
- case context.user of
- Just user ->
- editingToggle context.onToggleEditing context.lang user context.editing ::
- printButton context.onTogglePrintView context.lang user ::
- ( if user == Guest then
- [ signIn context.onSignInClicked context.lang ]
- else
- [ userMenuToggle context.onUpdate user menuOpened
- , if menuOpened then
- userMenuView context
- else
- text ""
- ]
- )
-
- Nothing ->
- []
+ let
+ searchInput =
+ context.searchInput |> Maybe.withDefault (text "")
+
+ others =
+ case context.user of
+ Just user ->
+ editingToggle context.onToggleEditing context.lang user context.editing ::
+ printButton context.onTogglePrintView context.lang user ::
+ ( if user == Guest then
+ [ signIn context.onSignInClicked context.lang ]
+ else
+ [ userMenuToggle context.onUpdate user menuOpened
+ , if menuOpened then
+ userMenuView context
+ else
+ text ""
+ ]
+ )
+
+ Nothing ->
+ []
+ in
+ menu (searchInput :: others)
userMenuToggle : (Msg -> msg) -> User -> Bool -> Html msg
View
@@ -1,14 +1,13 @@
module Model.Mode exposing (..)
-type Tab
- = SearchTab
- | EditTab
-
-
type Mode
- = Viewing Bool EditingMode
- | Editing Tab EditingMode
+ = Mode
+ { printMode : Bool
+ , searchResult : Bool
+ , editing : Bool
+ , editMode : EditingMode
+ }
type EditingMode
@@ -20,105 +19,115 @@ type EditingMode
init : Bool -> Mode
init isEditMode =
- if isEditMode then
- Editing EditTab Select
- else
- Viewing False Select
+ Mode
+ { printMode = False
+ , searchResult = False
+ , editing = isEditMode
+ , editMode = Select
+ }
+
+
+showingSearchResult : Mode -> Bool
+showingSearchResult (Mode mode) =
+ mode.searchResult
toggleEditing : Mode -> Mode
-toggleEditing mode =
- case mode of
- Viewing _ editMode -> Editing EditTab editMode
- Editing _ editMode -> Viewing False editMode
+toggleEditing (Mode mode) =
+ Mode
+ { mode
+ | editing = not (mode.editing)
+ }
togglePrintView : Mode -> Mode
-togglePrintView mode =
- case mode of
- Viewing printMode editMode -> Viewing (not printMode) editMode
- Editing _ editMode -> Viewing True editMode
+togglePrintView (Mode mode) =
+ Mode
+ { mode
+ | printMode = not (mode.printMode)
+ }
toSelectMode : Mode -> Mode
-toSelectMode mode =
- case mode of
- Editing tab _ -> Editing tab Select
- _ -> Editing EditTab Select
+toSelectMode (Mode mode) =
+ Mode
+ { mode
+ | editing = True
+ , editMode = Select
+ }
toStampMode : Mode -> Mode
-toStampMode mode =
- case mode of
- Editing tab _ -> Editing tab Stamp
- _ -> Editing EditTab Stamp
+toStampMode (Mode mode) =
+ Mode
+ { mode
+ | editing = True
+ , editMode = Stamp
+ }
isEditMode : Mode -> Bool
-isEditMode mode =
- case mode of
- Editing _ _ -> True
- _ -> False
+isEditMode (Mode mode) =
+ mode.editing
+
+
+currentEditMode : Mode -> Maybe EditingMode
+currentEditMode (Mode mode) =
+ if mode.editing then
+ Just mode.editMode
+ else
+ Nothing
isSelectMode : Mode -> Bool
-isSelectMode mode =
- case mode of
- Editing _ Select -> True
- _ -> False
+isSelectMode (Mode mode) =
+ mode.editing && mode.editMode == Select
isPenMode : Mode -> Bool
-isPenMode mode =
- case mode of
- Editing _ Pen -> True
- _ -> False
+isPenMode (Mode mode) =
+ mode.editing && mode.editMode == Pen
isStampMode : Mode -> Bool
-isStampMode mode =
- case mode of
- Editing _ Stamp -> True
- _ -> False
+isStampMode (Mode mode) =
+ mode.editing && mode.editMode == Stamp
isLabelMode : Mode -> Bool
-isLabelMode mode =
- case mode of
- Editing _ Label -> True
- _ -> False
+isLabelMode (Mode mode) =
+ mode.editing && mode.editMode == Label
isViewMode : Mode -> Bool
-isViewMode mode =
- case mode of
- Viewing _ _ -> True
- _ -> False
+isViewMode (Mode mode) =
+ not mode.editing
isPrintMode : Mode -> Bool
-isPrintMode mode =
- case mode of
- Viewing True _ -> True
- _ -> False
-
-
-changeTab : Tab -> Mode -> Mode
-changeTab tab mode =
- case mode of
- Editing _ editingMode -> Editing tab editingMode
- x -> x
+isPrintMode (Mode mode) =
+ mode.printMode
changeEditingMode : EditingMode -> Mode -> Mode
-changeEditingMode editingMode mode =
- case mode of
- Editing tab _ -> Editing tab editingMode
- _ -> Editing EditTab editingMode
-
-
-showSearchTab : Mode -> Mode
-showSearchTab mode =
- case mode of
- Editing _ editingMode -> Editing SearchTab editingMode
- x -> x
+changeEditingMode editingMode (Mode mode) =
+ Mode
+ { mode
+ | editing = True
+ , editMode = editingMode
+ }
+
+showSearchResult : Mode -> Mode
+showSearchResult (Mode mode) =
+ Mode
+ { mode
+ | searchResult = True
+ }
+
+
+hideSearchResult : Mode -> Mode
+hideSearchResult (Mode mode) =
+ Mode
+ { mode
+ | searchResult = False
+ }
@@ -28,7 +28,7 @@ import Model.SearchResult as SearchResult exposing (SearchResult, SearchResultsF
import Model.ProfilePopupLogic as ProfilePopupLogic
import Model.ColorPalette as ColorPalette exposing (ColorPalette)
import Model.EditingFloor as EditingFloor exposing (EditingFloor)
-import Model.Mode as Mode exposing (Mode(..), EditingMode(..), Tab(..))
+import Model.Mode as Mode exposing (Mode(..), EditingMode(..))
import Model.SaveRequest as SaveRequest exposing (SaveRequest(..))
import API.API as API
@@ -87,7 +87,7 @@ type alias Model =
, personPopupSize : (Int, Int)
, lang : Language
, cache : Cache
- , headerState : Header.State
+ , header : Header.Model
, saveFloorDebounce : Debounce SaveRequest
}
@@ -160,7 +160,7 @@ init apiConfig title initialSize randomSeed visitDate isEditMode query scale off
, personPopupSize = (300, 160)
, lang = lang
, cache = Cache.cache
- , headerState = Header.init
+ , header = Header.init
, saveFloorDebounce = Debounce.init
}
@@ -5,7 +5,7 @@ import Mouse exposing (Position)
import Debounce exposing (Debounce)
import ContextMenu exposing (ContextMenu)
-import Model.Mode as Mode exposing (Mode(..), EditingMode(..), Tab(..))
+import Model.Mode as Mode exposing (Mode(..), EditingMode(..))
import Model.User as User exposing (User)
import Model.Person as Person exposing (Person)
import Model.Object as Object exposing (..)
@@ -83,7 +83,7 @@ type Msg
| Rotate Id
| FirstNameOnly (List Id)
| RemoveSpaces (List Id)
- | UpdateHeaderState Header.Msg
+ | HeaderMsg Header.Msg
| SignIn
| SignOut
| ToggleEditing
@@ -104,7 +104,7 @@ type Msg
| GotDiffSource (Floor, Maybe Floor)
| CloseDiff
| ConfirmDiff
- | ChangeTab Tab
+ | HideSearchResult
| ClosePopup
| ShowDetailForObject Id
| CreateNewFloor
Oops, something went wrong.

0 comments on commit be74ee7

Please sign in to comment.