Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain coto-selection on changing the current cotonoma #140

Merged
merged 15 commits into from
May 7, 2019
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
14 changes: 13 additions & 1 deletion assets/elm/src/App/Channels.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
module App.Channels exposing (Payload, PresenceEntry, convertPresenceEntriesToConnCounts, cotoChannels, cotonomaChannels, decodePayload, decodePresenceDiff, decodePresenceEntries, decodePresenceState, globalChannel, timelineChannel)
module App.Channels exposing
( Payload
, PresenceEntry
, convertPresenceEntriesToConnCounts
, cotoChannels
, cotonomaChannels
, decodePayload
, decodePresenceDiff
, decodePresenceEntries
, decodePresenceState
, globalChannel
, timelineChannel
)

import App.Messages exposing (..)
import App.Server.Amishi
Expand Down
8 changes: 4 additions & 4 deletions assets/elm/src/App/Messages.elm
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ type Msg
| CotoClick ElementId CotoId
| CotoMouseEnter ElementId CotoId
| CotoMouseLeave ElementId CotoId
| SelectCoto CotoId
| SelectCoto Coto
| OpenTraversal CotoId
| CotonomaClick CotonomaKey
| ToggleCotoContent ElementId
| ConfirmDeleteCoto Coto
| DeleteCotoInServerSide Coto
| DeleteCotoInClientSide Coto
| ConfirmDeleteCoto CotoId
| DeleteCotoInServerSide CotoId
| DeleteCotoInClientSide CotoId
| CotoDeleted (Result Http.Error String)
| CotoUpdated (Result Http.Error Coto)
| ConfirmCotonomatize Coto
Expand Down
36 changes: 16 additions & 20 deletions assets/elm/src/App/Modals/ConnectModal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import App.Modals.ConnectModalMsg as ModalMsg exposing (Msg(..))
import App.Server.Graph
import App.Server.Post
import App.Submodels.Context exposing (Context)
import App.Submodels.CotoSelection
import App.Submodels.LocalCotos exposing (LocalCotos)
import App.Types.Connection exposing (Direction(..))
import App.Types.Coto exposing (Coto, CotoContent, CotoId)
Expand All @@ -40,7 +41,6 @@ type ConnectingTarget

type alias Model =
{ target : ConnectingTarget
, selectedCotos : List Coto
, direction : Direction
, linkingPhrase : String
, onPosted : AppMsg.Msg
Expand All @@ -50,18 +50,16 @@ type alias Model =
defaultModel : Model
defaultModel =
{ target = None
, selectedCotos = []
, direction = Inbound
, linkingPhrase = ""
, onPosted = AppMsg.NoOp
}


initModel : ConnectingTarget -> List Coto -> Direction -> Model
initModel target selectedCotos direction =
initModel : ConnectingTarget -> Direction -> Model
initModel target direction =
{ defaultModel
| target = target
, selectedCotos = selectedCotos
, direction = direction
}

Expand Down Expand Up @@ -101,10 +99,7 @@ modalConfig context model =
[ id primaryButtonId
, class "button button-primary"
, autofocus True
, onClick
(AppMsg.ConnectModalMsg
(Connect coto model.selectedCotos)
)
, onClick (AppMsg.ConnectModalMsg (Connect coto))
]
[ text (context.i18nText I18nKeys.ConnectModal_Connect) ]
]
Expand All @@ -128,13 +123,10 @@ modalContent : Context context -> Model -> Html AppMsg.Msg
modalContent context model =
let
selectedCotosHtml =
Html.Keyed.node
"div"
[ class "selected-cotos" ]
(List.map
(\coto -> ( toString coto.id, App.Views.Connection.cotoDiv coto ))
model.selectedCotos
)
context
|> App.Submodels.CotoSelection.cotosInSelectedOrder
|> List.map (\coto -> ( toString coto.id, App.Views.Connection.cotoDiv coto ))
|> Html.Keyed.node "div" [ class "selected-cotos" ]

targetHtml =
case model.target of
Expand Down Expand Up @@ -207,11 +199,15 @@ update context msg ({ connectModal } as model) =
{ model | connectModal = { connectModal | linkingPhrase = input } }
|> withoutCmd

Connect target objects ->
Connect target ->
let
selectedCotos =
App.Submodels.CotoSelection.cotosInSelectedOrder context
in
App.Submodels.LocalCotos.connect
context.session
target
objects
selectedCotos
model.connectModal.direction
(getLinkingPhrase model.connectModal)
model
Expand All @@ -221,7 +217,7 @@ update context msg ({ connectModal } as model) =
context.clientId
(Maybe.map .key model.cotonoma)
target.id
(List.map .id objects)
(List.map .id selectedCotos)
model.connectModal.direction
(getLinkingPhrase model.connectModal)
)
Expand Down Expand Up @@ -276,7 +272,7 @@ connectPostToSelection context post model =
(\target ->
let
objects =
App.Submodels.LocalCotos.getSelectedCotos context model
App.Submodels.CotoSelection.cotosInSelectedOrder context
in
( App.Submodels.LocalCotos.connect
context.session
Expand Down
2 changes: 1 addition & 1 deletion assets/elm/src/App/Modals/ConnectModalMsg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import Http
type Msg
= ReverseDirection
| LinkingPhraseInput String
| Connect Coto (List Coto)
| Connect Coto
| PostAndConnectToSelection CotoContent
| PostedAndConnectToSelection Int (Result Http.Error Post)
2 changes: 1 addition & 1 deletion assets/elm/src/App/Modals/CotoMenuModal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ menuItemDelete context session model =
, span [ class "menu-title" ]
[ text (context.i18nText I18nKeys.CotoMenuModal_Delete) ]
]
(AppMsg.ConfirmDeleteCoto model.coto)
(AppMsg.ConfirmDeleteCoto model.coto.id)

else
Utils.HtmlUtil.none
Expand Down
5 changes: 3 additions & 2 deletions assets/elm/src/App/Modals/EditorModal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import App.Server.Cotonoma
import App.Server.Graph
import App.Server.Post
import App.Submodels.Context exposing (Context)
import App.Submodels.CotoSelection
import App.Submodels.LocalCotos exposing (LocalCotos)
import App.Types.Connection
import App.Types.Coto exposing (Coto, CotoContent)
Expand Down Expand Up @@ -410,7 +411,7 @@ sourceCotoDiv context model =
buttonsForNewCoto : Context context -> Model -> List (Html AppMsg.Msg)
buttonsForNewCoto context model =
[ if
App.Submodels.Context.anySelection context
App.Submodels.CotoSelection.anySelection context
&& (model.mode == NewCoto Nothing)
then
button
Expand Down Expand Up @@ -726,7 +727,7 @@ handleShortcut context keyboardEvent model =

else if
keyboardEvent.altKey
&& App.Submodels.Context.anySelection context
&& App.Submodels.CotoSelection.anySelection context
then
( model
, App.Commands.sendMsg
Expand Down
17 changes: 9 additions & 8 deletions assets/elm/src/App/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import App.Modals.InviteModal
import App.Modals.SigninModal
import App.Route exposing (Route)
import App.Submodels.Context
import App.Submodels.CotoSelection
import App.Submodels.LocalCotos
import App.Submodels.Modals exposing (Confirmation, Modal(..))
import App.Submodels.NarrowViewport exposing (ActiveView(..), NarrowViewportState)
import App.Submodels.Traversals
import App.Submodels.WideViewport exposing (WideViewportState)
import App.Types.Amishi exposing (Amishi, AmishiId, Presences)
import App.Types.Connection exposing (Direction(..), Reordering)
import App.Types.Coto exposing (Coto, CotoId, CotoSelection, Cotonoma, CotonomaKey, ElementId)
import App.Types.Coto exposing (Coto, CotoId, Cotonoma, ElementId)
import App.Types.Graph exposing (Graph)
import App.Types.SearchResults exposing (SearchResults)
import App.Types.Session exposing (Session)
Expand Down Expand Up @@ -54,7 +55,7 @@ type alias Model =
, contentOpenElements : Set ElementId
, reordering : Maybe Reordering
, cotoFocus : Maybe CotoId
, selection : CotoSelection
, selection : List Coto
, deselecting : Set CotoId
, presences : Presences
, confirmation : Maybe Confirmation
Expand Down Expand Up @@ -133,16 +134,16 @@ initModel version seed lang route =
}


deleteCoto : Coto -> Model -> Model
deleteCoto coto model =
deleteCoto : CotoId -> Model -> Model
deleteCoto cotoId model =
model
|> App.Submodels.LocalCotos.deleteCoto coto
|> App.Submodels.Context.deleteSelection coto.id
|> App.Submodels.Traversals.closeTraversal coto.id
|> App.Submodels.LocalCotos.deleteCoto cotoId
|> App.Submodels.CotoSelection.deselect cotoId
|> App.Submodels.Traversals.closeTraversal cotoId


openTraversal : CotoId -> Model -> Model
openTraversal cotoId model =
model
|> App.Submodels.LocalCotos.incorporateLocalCotoInGraph cotoId
|> App.Submodels.LocalCotos.ensureCotoIsInGraph cotoId
|> App.Submodels.Traversals.openTraversal cotoId
5 changes: 2 additions & 3 deletions assets/elm/src/App/Pushed.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ handlePost payload model =

handleDelete : Payload CotoId -> Model -> ( Model, Cmd Msg )
handleDelete payload model =
App.Submodels.LocalCotos.getCoto payload.body model
|> Maybe.map (\coto -> App.Model.deleteCoto coto model)
|> Maybe.withDefault model
model
|> App.Model.deleteCoto payload.body
|> withCmd App.Server.Cotonoma.refreshCotonomaList
|> addCmd (\_ -> App.Commands.sendMsg GraphChanged)

Expand Down
64 changes: 2 additions & 62 deletions assets/elm/src/App/Submodels/Context.elm
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
module App.Submodels.Context exposing
( Context
, anySelection
, anyUnreadCotos
, atHome
, clearCotoFocus
, clearSelection
, contentOpen
, deleteSelection
, findWatchForCurrentCotonoma
, finishBeingDeselected
, focusCoto
, generateClientId
, hasPinnedCotosInReordering
, hasSubCotosInReordering
, isSelected
, isServerOwner
, isTriggerElementInReordering
, isWatched
, orignatedHere
, setBeingDeselected
, setCotonoma
, setCotonomaLoading
, toggleContent
, updateSelection
)

import App.I18n.Keys exposing (TextKey)
import App.Types.Connection exposing (Reordering(..))
import App.Types.Coto exposing (Coto, CotoId, CotoSelection, Cotonoma, ElementId)
import App.Types.Coto exposing (Coto, CotoId, Cotonoma, ElementId)
import App.Types.Graph exposing (Graph)
import App.Types.Session exposing (Session)
import App.Types.Watch exposing (Watch)
Expand All @@ -51,7 +44,7 @@ type alias Context a =
, contentOpenElements : Set ElementId
, reordering : Maybe Reordering
, cotoFocus : Maybe CotoId
, selection : CotoSelection
, selection : List Coto
, deselecting : Set CotoId
, graph : Graph
, loadingGraph : Bool
Expand Down Expand Up @@ -117,59 +110,6 @@ contentOpen elementId context =
Set.member elementId context.contentOpenElements


anySelection : Context a -> Bool
anySelection context =
not (List.isEmpty context.selection)


isSelected : Maybe CotoId -> Context a -> Bool
isSelected maybeCotoId context =
maybeCotoId
|> Maybe.map (\cotoId -> List.member cotoId context.selection)
|> Maybe.withDefault False


updateSelection : CotoId -> Context a -> Context a
updateSelection cotoId context =
{ context
| selection =
if context.selection |> List.member cotoId then
List.filter (\id -> cotoId /= id) context.selection

else
cotoId :: context.selection
}


clearSelection : Context a -> Context a
clearSelection context =
{ context | selection = [] }


deleteSelection : CotoId -> Context a -> Context a
deleteSelection cotoId context =
{ context | selection = List.filter (\id -> cotoId /= id) context.selection }


setBeingDeselected : CotoId -> Context a -> Context a
setBeingDeselected cotoId context =
{ context
| deselecting =
context.deselecting |> Set.insert cotoId
}


finishBeingDeselected : Context a -> Context a
finishBeingDeselected context =
{ context
| selection =
List.filter
(\id -> not (Set.member id context.deselecting))
context.selection
, deselecting = Set.empty
}


setCotonomaLoading : Context a -> Context a
setCotonomaLoading context =
{ context
Expand Down
Loading