From 199e9543aa59e4d8e19d12b7c1ad25270d2200b6 Mon Sep 17 00:00:00 2001 From: Erudition Date: Mon, 4 Dec 2023 21:32:53 -0600 Subject: [PATCH] Test new global change type --- elm/Layouts/AppFrame.elm | 4 +-- elm/Pages/TaskList.elm | 35 ++++++------------------- elm/Profile.elm | 16 +++++++----- elm/Shared.elm | 56 +++++++++++++++++++++++++++++++++++++++- elm/Shared/Msg.elm | 4 ++- 5 files changed, 77 insertions(+), 38 deletions(-) diff --git a/elm/Layouts/AppFrame.elm b/elm/Layouts/AppFrame.elm index 4a554d8d..a3f85601 100644 --- a/elm/Layouts/AppFrame.elm +++ b/elm/Layouts/AppFrame.elm @@ -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" ] ] ] ] @@ -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 diff --git a/elm/Pages/TaskList.elm b/elm/Pages/TaskList.elm index 03dd3ae3..1316c5b3 100644 --- a/elm/Pages/TaskList.elm +++ b/elm/Pages/TaskList.elm @@ -182,27 +182,8 @@ 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 -> @@ -210,7 +191,7 @@ update shared msg model = 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 @@ -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 @@ -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 } @@ -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 @@ -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 ) @@ -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 diff --git a/elm/Profile.elm b/elm/Profile.elm index d5c554c1..bc025f8d 100644 --- a/elm/Profile.elm +++ b/elm/Profile.elm @@ -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) @@ -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) @@ -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 diff --git a/elm/Shared.elm b/elm/Shared.elm index 8816fc17..2e5b0347 100644 --- a/elm/Shared.elm +++ b/elm/Shared.elm @@ -2,6 +2,7 @@ module Shared exposing ( Flags, decoder , Model, Msg , init, update, subscriptions + , profileChangeToString ) {-| @@ -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 @@ -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) @@ -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 @@ -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 ) @@ -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 diff --git a/elm/Shared/Msg.elm b/elm/Shared/Msg.elm index f086e03e..ab343505 100644 --- a/elm/Shared/Msg.elm +++ b/elm/Shared/Msg.elm @@ -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) @@ -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