Skip to content

Commit

Permalink
Split user/system change frames, custom frame desc
Browse files Browse the repository at this point in the history
  • Loading branch information
Erudition committed Dec 5, 2023
1 parent 9b9104e commit dd7d7a6
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 64 deletions.
4 changes: 2 additions & 2 deletions elm-to-be-migrated/Browserless.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Browser
import Html as PlainHtml
import Html.Styled exposing (node, toUnstyled)
import Main exposing (Msg, StoredRON)
import OldShared.Model exposing (..)
import Profile exposing (..)
import Replicated.Change as Change exposing (ChangeSet, Frame)
import OldShared.Model exposing (..)
import Url
import VirtualDom

Expand All @@ -25,7 +25,7 @@ main =
-- }


initBrowserless : ( String, Profile ) -> ( List Change.Frame, Main.MainModel, Cmd Msg )
initBrowserless : ( String, Profile ) -> ( List (Change.Frame String), Main.MainModel, Cmd Msg )
initBrowserless ( urlAsString, profile ) =
let
flags =
Expand Down
4 changes: 2 additions & 2 deletions elm-to-be-migrated/Headless.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ port module Headless exposing (main)

import Json.Decode.Exploration exposing (..)
import Main exposing (..)
import OldShared.Model exposing (..)
import Platform exposing (worker)
import Profile exposing (..)
import Replicated.Change as Change exposing (ChangeSet, Frame)
import OldShared.Model exposing (..)
import Url


Expand All @@ -22,7 +22,7 @@ main =
-- }


initHeadless : ( String, Profile ) -> ( List Change.Frame, MainModel, Cmd Msg )
initHeadless : ( String, Profile ) -> ( List (Change.Frame String), MainModel, Cmd Msg )
initHeadless ( urlAsString, profile ) =
let
flags =
Expand Down
4 changes: 2 additions & 2 deletions elm-to-be-migrated/ProjectEditor.elm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Json.Encode.Extra as Encode2 exposing (..)
import List.Extra as List
import Log
import Maybe.Extra as Maybe
import OldShared.Model exposing (..)
import Process
import Profile exposing (..)
import Refocus
Expand All @@ -42,7 +43,6 @@ 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 OldShared.Model exposing (..)
import SmartTime.Duration exposing (Duration)
import SmartTime.Human.Calendar as Calendar exposing (CalendarDate)
import SmartTime.Human.Clock as Clock exposing (TimeOfDay)
Expand Down Expand Up @@ -342,7 +342,7 @@ type Msg
| LogError String


update : Msg -> ViewState -> Profile -> Environment -> ( ViewState, Change.Frame, Cmd Msg )
update : Msg -> ViewState -> Profile -> Environment -> ( ViewState, Change.Frame String, Cmd Msg )
update msg state profile env =
case msg of
Add ->
Expand Down
28 changes: 14 additions & 14 deletions elm/Components/Replicator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import Task

{-| Internal Model of the replicator component.
-}
type Replicator replica
type Replicator replica frameDesc
= ReplicatorModel
{ node : Node
, replicaCodec : SkelCodec ReplicaError replica
, replica : replica
, outPort : String -> Cmd Msg
, outPort : String -> Cmd (Msg frameDesc)
}


Expand All @@ -29,14 +29,14 @@ type alias ReplicaError =

{-| Data required to initialize the replicator.
-}
type alias ReplicatorConfig replica =
type alias ReplicatorConfig replica yourFrameDesc =
{ launchTime : Maybe Moment
, replicaCodec : SkelCodec ReplicaError replica
, outPort : String -> Cmd Msg
, outPort : String -> Cmd (Msg yourFrameDesc)
}


init : ReplicatorConfig replica -> ( Replicator replica, replica )
init : ReplicatorConfig replica desc -> ( Replicator replica desc, replica )
init { launchTime, replicaCodec, outPort } =
let
( startNode, initChanges ) =
Expand All @@ -58,15 +58,15 @@ init { launchTime, replicaCodec, outPort } =

{-| This component's internal Msg type.
-}
type Msg
type Msg desc
= LoadRon Int (List String)
| ApplyFrames (List Change.Frame) Moment
| ApplyFrames (List (Change.Frame desc)) Moment


update :
Msg
-> Replicator replica
-> { newReplicator : Replicator replica, newReplica : replica, warnings : List OpImportWarning, cmd : Cmd Msg }
Msg desc
-> Replicator replica desc
-> { newReplicator : Replicator replica desc, newReplica : replica, warnings : List OpImportWarning, cmd : Cmd (Msg desc) }
update msg (ReplicatorModel oldReplicator) =
case msg of
LoadRon originalFrameCount [] ->
Expand Down Expand Up @@ -144,8 +144,8 @@ update msg (ReplicatorModel oldReplicator) =

{-| Type for your "incoming frames" port. Use this on your JS port which is called when you receive new changeframes from elsewhere. The RON data (as a string) will be processed into the replicator.
-}
type alias IncomingFramesPort =
(String -> Msg) -> Sub Msg
type alias IncomingFramesPort desc =
(String -> Msg desc) -> Sub (Msg desc)


{-| Wire this component's subscriptions up into your `Shared.subscriptions`, using `Sub.map` to convert it to your message type, like:
Expand All @@ -159,7 +159,7 @@ type alias IncomingFramesPort =
`incomingRon` is a port you create (you can put it in the `Effect` module if you like) that receives a String, and has the type `IncomingFramesPort`.
-}
subscriptions : IncomingFramesPort -> Sub Msg
subscriptions : IncomingFramesPort desc -> Sub (Msg desc)
subscriptions incomingFramesPort =
let
splitIncomingFrames inRon =
Expand All @@ -172,7 +172,7 @@ subscriptions incomingFramesPort =
incomingFramesPort splitIncomingFrames


saveEffect : List Change.Frame -> Cmd Msg
saveEffect : List (Change.Frame desc) -> Cmd (Msg desc)
saveEffect framesToSave =
case Change.nonEmptyFrames framesToSave of
[] ->
Expand Down
24 changes: 17 additions & 7 deletions elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ port module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, PromptOptions, cancelNotification, clearPreferences, closePopup, dialogPrompt, incomingRon, mlPredict, requestNotificationPermission, saveChanges, saveFrame, saveFrames, sendNotifications, sendSharedMsg, setStorage, syncMarvin, syncTodoist, toast, updateTime
, PromptOptions, cancelNotification, clearPreferences, closePopup, dialogPrompt, incomingRon, mlPredict, requestNotificationPermission, saveFrame, saveFrames, saveSystemChanges, saveUserChanges, sendNotifications, sendSharedMsg, setStorage, syncMarvin, syncTodoist, toast, updateTime, userChangeNow
)

{-|
Expand Down Expand Up @@ -61,7 +61,7 @@ type Effect msg
| SendSharedMsg Shared.Msg.Msg
| UpdateTime
-- REPLICATOR
| Save (List Change.Frame)
| Save (List (Change.Frame String))
-- EXTERNAL APP
| ClearPreferences
| RequestNotificationPermission
Expand Down Expand Up @@ -196,19 +196,24 @@ toast toastMsg =
Toast toastMsg


saveFrame : Change.Frame -> Effect msg
saveFrame : Change.Frame String -> Effect msg
saveFrame changeFrame =
Save [ changeFrame ]


saveFrames : List Change.Frame -> Effect msg
saveFrames : List (Change.Frame String) -> Effect msg
saveFrames changeFrames =
Save changeFrames


saveChanges : String -> List Change.Change -> Effect msg
saveChanges frameTitle changes =
saveFrame (Change.saveChanges frameTitle changes)
saveUserChanges : String -> List Change.Change -> Effect msg
saveUserChanges frameTitle changes =
saveFrame (Change.saveUserChanges frameTitle changes)


saveSystemChanges : List Change.Change -> Effect msg
saveSystemChanges changes =
saveFrame (Change.saveSystemChanges changes)


sendNotifications : List Notif.Notification -> Effect msg
Expand All @@ -225,6 +230,11 @@ mlPredict =
MLPredict


userChangeNow : Profile.UserChange -> Effect msg
userChangeNow profileChange =
SendSharedMsg <| Shared.Msg.ProfileChange profileChange



-- {- The goal here is to get (mouse x / window width) on each mouse event. So if
-- the mouse is at 500px and the screen is 1000px wide, we should get 0.5 from this.
Expand Down
20 changes: 10 additions & 10 deletions elm/Integrations/Marvin.elm
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ getLabelsCmd =
Cmd.batch [ getLabels partialAccessToken ]


handle : Profile -> ( Moment, HumanMoment.Zone ) -> Msg -> ( Change.Frame, String, Cmd Msg )
handle : Profile -> ( Moment, HumanMoment.Zone ) -> Msg -> ( Change.Frame String, String, Cmd Msg )
handle profile ( time, timeZone ) response =
let
projectLayers =
Expand All @@ -291,27 +291,27 @@ handle profile ( time, timeZone ) response =
TestResult result ->
case result of
Ok serversays ->
( Change.saveChanges "Logging Marvin changes" [ RepList.insert RepList.Last ("Marvin TestResult: " ++ serversays) profile.errors ]
( Change.saveUserChanges "Logging Marvin changes" [ RepList.insert RepList.Last ("Marvin TestResult: " ++ serversays) profile.errors ]
, serversays
, Cmd.none
)

Err err ->
( Change.saveChanges "Logging Marvin error" [ RepList.insert RepList.Last (Debug.toString err) profile.errors ]
( Change.saveUserChanges "Logging Marvin error" [ RepList.insert RepList.Last (Debug.toString err) profile.errors ]
, describeError err
, Cmd.none
)

AuthResult result ->
case result of
Ok serversays ->
( Change.saveChanges "Logging Marvin changes" [ RepList.insert RepList.Last ("Marvin AuthResult: " ++ serversays) profile.errors ]
( Change.saveUserChanges "Logging Marvin changes" [ RepList.insert RepList.Last ("Marvin AuthResult: " ++ serversays) profile.errors ]
, serversays
, Cmd.none
)

Err err ->
( Change.saveChanges "Logging Marvin error" [ RepList.insert RepList.Last (Debug.toString err) profile.errors ]
( Change.saveUserChanges "Logging Marvin error" [ RepList.insert RepList.Last (Debug.toString err) profile.errors ]
, describeError err
, Cmd.none
)
Expand All @@ -323,13 +323,13 @@ handle profile ( time, timeZone ) response =
changes =
importItems profile itemList
in
( Change.saveChanges "Imported Marvin Items" changes
( Change.saveUserChanges "Imported Marvin Items" changes
, "Fetched items: " ++ Debug.toString itemList
, getTimeBlockAssignments
)

Err err ->
( Change.saveChanges "Logging Marvin error" [ RepList.insert RepList.Last (Debug.toString err) profile.errors ]
( Change.saveUserChanges "Logging Marvin error" [ RepList.insert RepList.Last (Debug.toString err) profile.errors ]
, "when getting items: " ++ describeError err
, Cmd.none
)
Expand All @@ -341,7 +341,7 @@ handle profile ( time, timeZone ) response =
changes =
importLabels profile labelList
in
( Change.saveChanges "Imported Marvin Labels" changes
( Change.saveUserChanges "Imported Marvin Labels" changes
, "Fetched labels: " ++ Debug.toString labelList
, getTodayItems partialAccessToken
)
Expand All @@ -355,7 +355,7 @@ handle profile ( time, timeZone ) response =
GotTimeBlocks assignments result ->
case result of
Ok timeBlockList ->
( Change.saveChanges "Imported Marvin Timeblocks" <| importTimeBlocks profile assignments timeBlockList
( Change.saveUserChanges "Imported Marvin Timeblocks" <| importTimeBlocks profile assignments timeBlockList
, "Fetched timeblocks: " ++ Debug.toString timeBlockList
, getTrackedItem partialAccessToken
)
Expand Down Expand Up @@ -438,7 +438,7 @@ handle profile ( time, timeZone ) response =
logMsg =
"got timetrack acknowledgement at " ++ HumanMoment.toStandardString time ++ " my time, newest marvin time was off by " ++ (Maybe.withDefault "none" <| Maybe.map newestReport (List.last timesList))
in
( Change.saveChanges "Got Marvin tracking acknowledgement" updateTimeline
( Change.saveUserChanges "Got Marvin tracking acknowledgement" updateTimeline
, logMsg
, Cmd.none
)
Expand Down
6 changes: 3 additions & 3 deletions elm/Integrations/Todoist.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ devSecret =
"0bdc5149510737ab941485bace8135c60e2d812b"


handle : Todoist.Msg -> Profile -> ( Change.Frame, String )
handle : Todoist.Msg -> Profile -> ( Change.Frame String, String )
handle msg app =
case Todoist.handleResponse msg app.todoist.cache of
Ok ( newCache, changes ) ->
Expand Down Expand Up @@ -89,7 +89,7 @@ handle msg app =
-- }
[]
in
( Change.saveChanges "" finalChanges
( Change.saveUserChanges "" finalChanges
, describeSuccess changes
)

Expand All @@ -98,7 +98,7 @@ handle msg app =
description =
Todoist.describeError err
in
( Change.saveChanges "" [ saveError app description ], description )
( Change.saveUserChanges "" [ saveError app description ], description )


describeSuccess : Todoist.LatestChanges -> String
Expand Down
4 changes: 2 additions & 2 deletions elm/Popup/Editor/Assignable.elm
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ update msg model =
)


outputToChanges : Maybe Assignable -> Output -> Change.Frame
outputToChanges : Maybe Assignable -> Output -> Change.Frame String
outputToChanges assignableMaybe output =
case assignableMaybe of
Just assignable ->
Expand Down Expand Up @@ -342,7 +342,7 @@ outputToChanges assignableMaybe output =
else
Just (Assignable.setMaxEffort output.maxEffort assignable)
in
Change.saveChanges "Editing an assignable" <|
Change.saveUserChanges "Editing an assignable" <|
List.filterMap identity
[ updateTitle
, updateImportance
Expand Down
4 changes: 2 additions & 2 deletions elm/Popup/Editor/Assignment.elm
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ update msg model =
)


outputToChanges : Maybe Assignment -> Output -> Change.Frame
outputToChanges : Maybe Assignment -> Output -> Change.Frame String
outputToChanges existingAssignmentMaybe output =
case existingAssignmentMaybe of
Just existingAssignment ->
Expand Down Expand Up @@ -234,7 +234,7 @@ outputToChanges existingAssignmentMaybe output =
else
Just (Assignment.setCompletion output.completion existingAssignment)
in
Change.saveChanges "Editing an assignment" <|
Change.saveUserChanges "Editing an assignment" <|
List.filterMap identity
[ updateRelevanceStarts
, updateRelevanceEnds
Expand Down
2 changes: 1 addition & 1 deletion elm/Refocus.elm
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ switchTracking trackable profile projectLayers ( time, timeZone ) =
reactToNewSession trackable ( time, timeZone ) profile projectLayers
in
-- TODO RUN reactToNewSession AFTER CHANGE
Effect.batch [ reaction, Effect.saveChanges "Started tracking" switchChanges ]
Effect.batch [ reaction, Effect.saveUserChanges "Started tracking" switchChanges ]


reactToNewSession trackable ( time, timeZone ) oldProfile projectLayers =
Expand Down
Loading

0 comments on commit dd7d7a6

Please sign in to comment.