Skip to content

Commit

Permalink
Test new global change type
Browse files Browse the repository at this point in the history
  • Loading branch information
Erudition committed Dec 5, 2023
1 parent dd7d7a6 commit 199e954
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 38 deletions.
4 changes: 2 additions & 2 deletions elm/Layouts/AppFrame.elm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ globalLayout model shared route bodyContentList toContentMsg =
, Ion.Toolbar.title [] [ H.text "Minder" ]
, Ion.Toolbar.title [ HA.attribute "size" "small" ] [ H.text formattedTime ]
, Ion.Toolbar.buttons [ Ion.Toolbar.placeEnd ]
[ Ion.Button.button [ HA.disabled True ] [ Ion.Icon.basic "arrow-undo-circle-outline" ]
[ Ion.Button.button [ Route.Path.href Route.Path.Undo ] [ Ion.Icon.basic "arrow-undo-circle-outline" ]
]
]
]
Expand Down Expand Up @@ -423,7 +423,7 @@ trackingTaskCompletionSlider instance =
]
)
]
{ onChange = \input -> JustRunEffects [ Effect.saveChanges "Updating Progress" [ Assignment.setCompletion (round input) instance ] ]
{ onChange = \input -> JustRunEffects [ Effect.saveUserChanges "Updating Progress" [ Assignment.setCompletion (round input) instance ] ]
, label =
Input.labelHidden "Task Progress"
, min = 0
Expand Down
35 changes: 8 additions & 27 deletions elm/Pages/TaskList.elm
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,16 @@ update shared msg model =
( model, Effect.none )

newProjectTitle ->
let
newProjectSkel =
Project.createTopLevelSkel projectChanger

projectChanger project =
[ Project.setTitle (Just newProjectTitle) project ]

frameDescription =
"Added project: " ++ newProjectTitle

finalChanges =
[ RepList.insert RepList.Last frameDescription shared.replica.errors
, RepDb.addNew newProjectSkel shared.replica.projects

-- , RepList.insertNew RepList.Last
-- [ \c -> Project.AssignableIsHere (newAssignable (Change.reuseContext "Assignable in Project" c)) ]
-- shared.replica.projects
]
in
( { model | newTaskField = "", expandedTask = Nothing }
, Effect.saveChanges frameDescription finalChanges
, Effect.userChangeNow (Profile.AddProject newProjectTitle)
)

AddAssignable project ->
let
handleResult result =
case result of
Ok newName ->
RunEffect <| Effect.saveChanges (frameDescription newName) (finalChanges newName)
RunEffect <| Effect.saveUserChanges (frameDescription newName) (finalChanges newName)

Err _ ->
RunEffect <| Effect.none
Expand Down Expand Up @@ -252,7 +233,7 @@ update shared msg model =
, Assignment.create (\_ -> []) assignable
]
in
( model, Effect.saveChanges frameDescription finalChanges )
( model, Effect.saveUserChanges frameDescription finalChanges )

DeleteAssignment assignment ->
let
Expand All @@ -264,7 +245,7 @@ update shared msg model =
, Assignment.delete assignment
]
in
( model, Effect.saveChanges frameDescription finalChanges )
( model, Effect.saveUserChanges frameDescription finalChanges )

UpdateNewEntryField typedSoFar ->
( { model | newTaskField = typedSoFar }
Expand Down Expand Up @@ -298,7 +279,7 @@ update shared msg model =
Effect.none

else
Effect.saveChanges "Updating project title" [ Assignable.setTitle newTitle assignable ]
Effect.saveUserChanges "Updating project title" [ Assignable.setTitle newTitle assignable ]
in
( { model | currentlyEditing = Nothing }
, changeTitleIfValid
Expand Down Expand Up @@ -426,10 +407,10 @@ update shared msg model =
)

SimpleChange change ->
( model, Effect.saveChanges "Simple change" [ change ] )
( model, Effect.saveUserChanges "Simple change" [ change ] )

LogError errorMsg ->
( model, Effect.saveChanges "Log Error" [ RepList.insert RepList.Last errorMsg shared.replica.errors ] )
( model, Effect.saveUserChanges "Log Error" [ RepList.insert RepList.Last errorMsg shared.replica.errors ] )

Toast toastMsg ->
( model, Effect.toast toastMsg )
Expand All @@ -442,7 +423,7 @@ update shared msg model =
handleResult result =
case result of
Ok newName ->
RunEffect <| Effect.saveChanges "renaming" [ newNameToChange newName ]
RunEffect <| Effect.saveUserChanges "renaming" [ newNameToChange newName ]

Err _ ->
RunEffect <| Effect.none
Expand Down
16 changes: 9 additions & 7 deletions elm/Profile.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Profile exposing (AppInstance, Profile, TodoistIntegrationData, codec, currentActivityID, currentAssignmentID, currentSession, currentlyTracking, getActivityByID, saveDecodeErrors, saveError, saveWarnings, userTimeZoneAtMoment)
module Profile exposing (Profile, TodoistIntegrationData, UserChange(..), codec, currentActivityID, currentAssignmentID, currentSession, currentlyTracking, getActivityByID, saveDecodeErrors, saveError, saveWarnings, userTimeZoneAtMoment)

import Activity.Activity as Activity exposing (..)
import Activity.HistorySession exposing (HistorySession, Timeline)
Expand Down Expand Up @@ -30,12 +30,6 @@ import TimeTrackable exposing (TimeTrackable)
import ZoneHistory


{-| TODO "Instance" will be a UUID. Was going to have a user ID (for multi-user one day) and a device ID, but instead we can just have one UUID for every instance out there and determine who owns it when needed.
-}
type alias AppInstance =
Int


type alias Profile =
{ errors : RepList String
, projects : RepDb (Reg ProjectSkel)
Expand Down Expand Up @@ -135,3 +129,11 @@ currentlyTracking profile =
currentSession : Profile -> Maybe HistorySession
currentSession profile =
Activity.HistorySession.current (RepList.listValues profile.timeline)



-- USER CHANGE


type UserChange
= AddProject String
56 changes: 55 additions & 1 deletion elm/Shared.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Shared exposing
( Flags, decoder
, Model, Msg
, init, update, subscriptions
, profileChangeToString
)

{-|
Expand All @@ -27,7 +28,13 @@ import List.Nonempty exposing (Nonempty(..))
import Log
import NativeScript.Notification as Notif
import Profile exposing (Profile)
import Replicated.Change as Change exposing (Change, Parent)
import Replicated.Codec as Codec exposing (Codec, SkelCodec, WrappedOrSkelCodec)
import Replicated.Node.Node as Node exposing (Node)
import Replicated.Reducer.Register as Reg exposing (Reg)
import Replicated.Reducer.RepDb as RepDb exposing (RepDb)
import Replicated.Reducer.RepDict as RepDict exposing (RepDict, RepDictEntry(..))
import Replicated.Reducer.RepList as RepList exposing (RepList)
import Route exposing (Route)
import Route.Path
import Shared.Model
Expand All @@ -40,6 +47,14 @@ import SmartTime.Human.Duration exposing (HumanDuration(..))
import SmartTime.Human.Moment as HumanMoment exposing (Zone, utc)
import SmartTime.Moment as Moment exposing (Moment, zero)
import SmartTime.Period as Period exposing (Period)
import Task.ActionSkel as Action
import Task.Assignable as Assignable exposing (Assignable, AssignableID)
import Task.Assignment as Assignment exposing (Assignment, AssignmentID)
import Task.Layers
import Task.Progress
import Task.Project as Project exposing (Project)
import Task.ProjectSkel as ProjectSkel
import Task.SubAssignableSkel as SubAssignableSkel exposing (SubAssignableSkel)



Expand Down Expand Up @@ -113,6 +128,7 @@ init flagsResult route =
, replica = replica
, tickEnabled = False
, oddModel = oddModel
, uiHistory = []
}
, Effect.sendCmd (Cmd.map OddUpdate oddInit)
-- TODO Effect.saveChanges "init" initChanges
Expand All @@ -135,6 +151,13 @@ update route msg shared =
, Effect.none
)

ProfileChange profileChange ->
let
( afterHandlerShared, afterHandlerEffects ) =
profileUpdate Nothing profileChange shared
in
( { afterHandlerShared | uiHistory = profileChange :: afterHandlerShared.uiHistory }, afterHandlerEffects )

Tick newTime ->
( { shared | time = newTime }, Effect.none )

Expand Down Expand Up @@ -264,11 +287,42 @@ update route msg shared =
, Effect.sendNotifications [ notification ]
, Effect.toast whatHappened
, Effect.saveFrame marvinChanges
, Effect.saveChanges "Log it temporarily" [ Profile.saveError shared.replica ("Synced with Marvin: \n" ++ whatHappened) ]
, Effect.saveUserChanges "Log it temporarily" [ Profile.saveError shared.replica ("Synced with Marvin: \n" ++ whatHappened) ]
]
)


profileUpdate : Maybe Moment -> Profile.UserChange -> Model -> ( Model, Effect Msg )
profileUpdate happenedMaybe profileChange shared =
let
frameDescription =
profileChangeToString profileChange
in
case profileChange of
Profile.AddProject newProjectTitle ->
let
newProjectSkel =
Project.createTopLevelSkel projectChanger

projectChanger project =
[ Project.setTitle (Just newProjectTitle) project ]

finalChanges =
[ RepDb.addNew newProjectSkel shared.replica.projects
]
in
( { shared | uiHistory = profileChange :: shared.uiHistory }
, Effect.saveUserChanges frameDescription finalChanges
)


profileChangeToString : Profile.UserChange -> String
profileChangeToString profileChange =
case profileChange of
Profile.AddProject newProjectTitle ->
"Created new project \"" ++ newProjectTitle ++ "\""



-- SUBSCRIPTIONS

Expand Down
4 changes: 3 additions & 1 deletion elm/Shared/Msg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Components.Replicator
import Incubator.Todoist as Todoist
import Integrations.Marvin as Marvin
import NativeScript.Notification as Notif
import Profile
import Replicated.Change as Change
import SmartTime.Human.Duration exposing (HumanDuration(..))
import SmartTime.Human.Moment exposing (Zone)
Expand All @@ -20,8 +21,9 @@ Naming Convention: Use "what happened" phrasing, not "action to take" (verb) phr
-}
type Msg
= NoUpdate
| ProfileChange Profile.UserChange
| Tick Moment
| ReplicatorUpdate Components.Replicator.Msg
| ReplicatorUpdate (Components.Replicator.Msg String)
| OddUpdate Components.Odd.Msg
--| RunEffects (List (Effect.Effect Msg))
| WantsLogCleared
Expand Down

0 comments on commit 199e954

Please sign in to comment.