<commit_before>module Data.TodoDoc exposing (..)

import Data.DeviceId exposing (DeviceId)
import Data.Todo.Schedule exposing (TodoSchedule)
import Document exposing (..)
import GroupDoc exposing (..)
import Json.Decode as D exposing (Decoder)
import Json.Decode.Pipeline as D
import Json.Encode as E
import List
import Maybe.Extra as Maybe
import Random.Pcg
import Store exposing (..)
import Time exposing (Time)
import Toolkit.Helpers exposing (..)
import Toolkit.Operators exposing (..)
import X.Function exposing (..)
import X.Function.Infix exposing (..)
import X.Record exposing (over, set)


type alias TodoText =
    String


type alias TodoRecord =
    { done : Bool
    , text : TodoText
    , schedule : TodoSchedule
    , projectId : DocId
    , contextId : DocId
    }


type alias TodoDoc =
    Document TodoRecord


type TodoAction
    = TA_MarkDone
    | TA_SetText TodoText
    | TA_SetContextId DocId
    | TA_SetScheduleFromMaybeTime (Maybe Time)
    | TA_SetContext ContextDoc
    | TA_SetProjectId DocId
    | TA_CopyProjectAndContextId TodoDoc
    | TA_SetProject ProjectDoc
    | TA_ToggleDone
    | TA_ToggleDeleted
    | TA_TurnReminderOff
    | TA_SetSchedule TodoSchedule
    | TA_SnoozeTill Time
    | TA_AutoSnooze Time


type alias TodoStore =
    Store TodoRecord


type alias Text =
    String


type alias Record =
    { done : Bool
    , text : Text
    , schedule : Data.Todo.Schedule.Model
    , projectId : DocId
    , contextId : DocId
    }


type alias Model =
    Document Record


type alias ViewModel =
    Model


type alias Encoded =
    E.Value


type alias ModelF =
    Model -> Model


getMaybeDueAt : Model -> Maybe Time
getMaybeDueAt =
    .schedule >> Data.Todo.Schedule.getMaybeDueAt


getMaybeReminderTime =
    .schedule >> Data.Todo.Schedule.getMaybeReminderTime


isActive =
    isInActive >> not


isInActive =
    anyPass [ Document.isDeleted, isDone ]


getProjectId =
    .projectId


getCreatedAt : Model -> Time
getCreatedAt =
    .createdAt


getModifiedAt : Model -> Time
getModifiedAt =
    .modifiedAt


getMaybeTime model =
    getMaybeReminderTime model |> Maybe.orElse (getMaybeDueAt model)


done =
    X.Record.fieldLens .done (\s b -> { b | done = s })


text =
    X.Record.fieldLens .text (\s b -> { b | text = s })


schedule =
    X.Record.fieldLens .schedule (\s b -> { b | schedule = s })


projectId =
    X.Record.fieldLens .projectId (\s b -> { b | projectId = s })


contextId =
    X.Record.fieldLens .contextId (\s b -> { b | contextId = s })


deleted =
    X.Record.fieldLens .deleted (\s b -> { b | deleted = s })


updateSchedule fn model =
    over schedule fn model


update : TodoAction -> ModelF
update action =
    case action of
        TA_SetText val ->
            set text val

        TA_SetContextId val ->
            set contextId val

        TA_SetProjectId val ->
            set projectId val

        TA_SetSchedule val ->
            set schedule val

        TA_CopyProjectAndContextId fromTodo ->
            update (TA_SetContextId fromTodo.contextId)
                >> update (TA_SetProjectId fromTodo.projectId)

        TA_SetProject project ->
            Document.getId project |> set projectId

        TA_SetContext context ->
            Document.getId context |> set contextId

        TA_ToggleDone ->
            over done not

        TA_MarkDone ->
            set done True

        TA_ToggleDeleted ->
            over deleted not

        TA_SetScheduleFromMaybeTime maybeTime ->
            set schedule (Data.Todo.Schedule.fromMaybeTime maybeTime)

        TA_TurnReminderOff ->
            updateSchedule Data.Todo.Schedule.turnReminderOff<commit_msg>WIP: add store model to manage store updates.<commit_after>module Data.TodoDoc exposing (..)

import Data.DeviceId exposing (DeviceId)
import Data.Todo.Schedule exposing (TodoSchedule)
import Document exposing (..)
import GroupDoc exposing (..)
import Json.Decode as D exposing (Decoder)
import Json.Decode.Pipeline as D
import Json.Encode as E
import List
import Maybe.Extra as Maybe
import Random.Pcg
import Store exposing (..)
import Time exposing (Time)
import Toolkit.Helpers exposing (..)
import Toolkit.Operators exposing (..)
import X.Function exposing (..)
import X.Function.Infix exposing (..)
import X.Record exposing (..)


type alias TodoText =
    String


type alias TodoRecord =
    { done : Bool
    , text : TodoText
    , schedule : TodoSchedule
    , projectId : DocId
    , contextId : DocId
    }


type alias TodoDoc =
    Document TodoRecord


type TodoAction
    = TA_MarkDone
    | TA_SetText TodoText
    | TA_SetContextId DocId
    | TA_SetScheduleFromMaybeTime (Maybe Time)
    | TA_SetContext ContextDoc
    | TA_SetProjectId DocId
    | TA_CopyProjectAndContextId TodoDoc
    | TA_SetProject ProjectDoc
    | TA_ToggleDone
    | TA_ToggleDeleted
    | TA_TurnReminderOff
    | TA_SetSchedule TodoSchedule
    | TA_SnoozeTill Time
    | TA_AutoSnooze Time


type alias TodoStore =
    Store TodoRecord


type alias Text =
    String


type alias Record =
    { done : Bool
    , text : Text
    , schedule : Data.Todo.Schedule.Model
    , projectId : DocId
    , contextId : DocId
    }


type alias Model =
    Document Record


type alias ViewModel =
    Model


type alias Encoded =
    E.Value


type alias ModelF =
    Model -> Model


getMaybeDueAt : Model -> Maybe Time
getMaybeDueAt =
    .schedule >> Data.Todo.Schedule.getMaybeDueAt


getMaybeReminderTime =
    .schedule >> Data.Todo.Schedule.getMaybeReminderTime


isActive =
    isInActive >> not


isInActive =
    anyPass [ Document.isDeleted, isDone ]


getProjectId =
    .projectId


getCreatedAt : Model -> Time
getCreatedAt =
    .createdAt


getModifiedAt : Model -> Time
getModifiedAt =
    .modifiedAt


getMaybeTime model =
    getMaybeReminderTime model |> Maybe.orElse (getMaybeDueAt model)


done =
    X.Record.fieldLens .done (\s b -> { b | done = s })


text =
    X.Record.fieldLens .text (\s b -> { b | text = s })


schedule =
    X.Record.fieldLens .schedule (\s b -> { b | schedule = s })


projectId =
    X.Record.fieldLens .projectId (\s b -> { b | projectId = s })


contextId =
    X.Record.fieldLens .contextId (\s b -> { b | contextId = s })


deleted =
    X.Record.fieldLens .deleted (\s b -> { b | deleted = s })


updateSchedule fn model =
    over schedule fn model


update : TodoAction -> ModelF
update action =
    case action of
        TA_SetText val ->
            set text val

        TA_SetContextId val ->
            set contextId val

        TA_SetProjectId val ->
            set projectId val

        TA_SetSchedule val ->
            set schedule val

        TA_CopyProjectAndContextId fromTodo ->
            update (TA_SetContextId fromTodo.contextId)
                >> update (TA_SetProjectId fromTodo.projectId)

        TA_SetProject project ->
            Document.getId project |> set projectId

        TA_SetContext context ->
            Document.getId context |> set contextId

        TA_ToggleDone ->
            toggle done

        TA_MarkDone ->
            set done True

        TA_ToggleDeleted ->
            toggle deleted

        TA_SetScheduleFromMaybeTime maybeTime ->
            set schedule (Data.Todo.Schedule.fromMaybeTime maybeTime)

        TA_TurnReminderOff ->
            updateSchedule Data.Todo.Schedule.turnReminderOff
{'fraction_non_alphanumeric': 0.07842340511986998, 'fraction_numerical': 0.0, 'mean_word_length': 2.440820130475303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4478590', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2209, 'n_words': 626}