From 87a560fa0d35cc3c1ab44b437c14cd48930a13a0 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 12:45:01 +0800 Subject: [PATCH 1/7] Add All filter to mobile Tasks --- shared/src/logseq/core/journal_task_dates.ml | 130 +++++++++++++----- shared/src/logseq/core/mobile_session.ml | 14 +- shared/src/logseq/core/mobile_session.mli | 16 ++- shared/src/logseq/core/rpc_session.ml | 17 ++- shared/src/logseq/core/session_types.ml | 2 + shared/src/logseq/core/session_types.mli | 1 + .../src/logseq/entry/logseq_mobile_entry.ml | 2 +- shared/src/logseq/model.ml | 24 ++-- shared/src/logseq/model.mli | 4 +- shared/src/logseq/native_bridge.ml | 4 + shared/src/logseq/native_bridge.mli | 1 + shared/src/logseq/view_outliner.ml | 123 ++++++++++------- shared/src/logseq/view_rows.ml | 25 ++-- shared/src/logseq/view_rows.mli | 2 +- shared/test/logseq/app_test.ml | 33 ++++- shared/test/logseq/editor_command_test.ml | 43 +++++- 16 files changed, 312 insertions(+), 129 deletions(-) diff --git a/shared/src/logseq/core/journal_task_dates.ml b/shared/src/logseq/core/journal_task_dates.ml index e105f391..7a246eff 100644 --- a/shared/src/logseq/core/journal_task_dates.ml +++ b/shared/src/logseq/core/journal_task_dates.ml @@ -28,16 +28,20 @@ let lookback_of_string = function let task_group_key section page = "task-page:" ^ section ^ ":" ^ page +let task_group_is_collapsed ~section ~disclosed_groups page = + List.mem (task_group_key section page) disclosed_groups <> (section = "all") + let task_field key = function | `Assoc fields -> Option.value ~default:`Null (List.assoc_opt key fields) | _ -> `Null let visible_in_tasks ~section ~show_completed ~show_past task = - let status = task_field "ident" (task_field "status" (task_field "block" task)) in - (show_completed || status <> `String Task_recurrence.done_ident) - && (section = "upcoming" || show_past || task_field "past" task <> `Bool true) + if section = "all" then true else + let status = task_field "ident" (task_field "status" (task_field "block" task)) in + (show_completed || status <> `String Task_recurrence.done_ident) + && (section = "upcoming" || show_past || task_field "past" task <> `Bool true) -let task_is_visible agenda ~section ~collapsed ~group_by_page ~show_completed ~show_past uuid = +let task_is_visible agenda ~section ~disclosed_groups ~group_by_page ~show_completed ~show_past uuid = match task_field section agenda with | `List tasks -> List.exists (fun task -> @@ -45,7 +49,7 @@ let task_is_visible agenda ~section ~collapsed ~group_by_page ~show_completed ~s && visible_in_tasks ~section ~show_completed ~show_past task && (not group_by_page || match task_field "pageId" (task_field "block" task) with - | `String page -> not (List.mem (task_group_key section page) collapsed) + | `String page -> not (task_group_is_collapsed ~section ~disclosed_groups page) | _ -> true)) tasks | _ -> false @@ -69,7 +73,7 @@ let date = Task_recurrence.date let status_attr = "logseq.property/status" let doing_ident = "logseq.property/status.doing" -let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today lookahead = +let rows ?actor ?on_comment_reference ?eids ~lookback ~include_all db today lookahead = let offset_day days = Option.value ~default:today (Dev_query.Date_time_util.journal_day_plus today days) in let first_upcoming = offset_day 1 in @@ -111,13 +115,23 @@ let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today looka let eids_with_ref attr value = Datascript_value.datoms_by_ref db Ds.Aevt attr value |> Seq.map (fun datom -> datom.Ds.e) in let doing = Ds.entid db "db/ident" (Ds.Keyword doing_ident) in + let task_classes () = + Option.fold ~none:[] ~some:(Read.class_descendants db) + (Ds.entid db "db/ident" (Ds.Keyword "logseq.class/Task")) in + let all_task_classes = if not include_all then [] else + let status_classes = + match Ds.entid db "db/ident" (Ds.Keyword status_attr) with + | None -> [] + | Some property -> + eids_with_ref "logseq.property.class/properties" property + |> Seq.flat_map (fun eid -> List.to_seq (Read.class_descendants db eid)) + |> List.of_seq in + List.sort_uniq Int.compare (task_classes () @ status_classes) in + let all_class_set = Hashtbl.create (List.length all_task_classes) in + List.iter (fun eid -> Hashtbl.add all_class_set eid ()) all_task_classes; + let has_task_class eid = List.exists (Hashtbl.mem all_class_set) (Read.ref_eids db eid "block/tags") in let doing_classes = - match doing with - | Some eid when default_status_eid = Some eid -> - (match Ds.entid db "db/ident" (Ds.Keyword "logseq.class/Task") with - | Some task -> Read.class_descendants db task - | None -> []) - | _ -> [] in + if Option.exists (fun eid -> default_status_eid = Some eid) doing then task_classes () else [] in let start = Date.journal_day_to_local_ms first_today in let next_after_upcoming = Option.value ~default:last_upcoming (Date.journal_day_plus last_upcoming 1) in let stop = Int64.pred (Date.journal_day_to_local_ms next_after_upcoming) in @@ -145,7 +159,7 @@ let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today looka Some datom.e | _ -> None) in let in_today day = day >= first_today && day <= today in - let candidates = match eids with + let agenda_candidates = match eids with | None -> let doing_eids = Option.fold ~none:Seq.empty ~some:(eids_with_ref status_attr) doing in let doing_class_eids = List.to_seq doing_classes |> Seq.flat_map (eids_with_ref "block/tags") in @@ -170,6 +184,18 @@ let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today looka || Option.exists (Read.has_ref db eid status_attr) doing || List.exists (Read.has_ref db eid "block/tags") doing_classes || List.exists on_recent_journal (Read.ref_eids db eid "block/page")) in + let candidates, in_agenda = + if not include_all then agenda_candidates, (fun _ -> true) + else + let agenda_eids = Hashtbl.create 32 in + Seq.iter (fun eid -> Hashtbl.replace agenda_eids eid ()) agenda_candidates; + let all_candidates = match eids with + | Some eids -> List.to_seq eids + | None -> + let with_attr attr = Ds.Db.datoms db Ds.Aevt ~a:attr () |> Seq.map (fun datom -> datom.Ds.e) in + let class_eids = List.to_seq all_task_classes |> Seq.flat_map (eids_with_ref "block/tags") in + Seq.concat (List.to_seq [with_attr status_attr; with_attr scheduled; with_attr deadline; class_eids]) in + Seq.append (Hashtbl.to_seq_keys agenda_eids) all_candidates, Hashtbl.mem agenda_eids in let order_path eid page = let rec collect seen path eid = if eid = page || List.mem eid seen then path @@ -180,6 +206,14 @@ let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today looka | parent :: _ -> collect (eid :: seen) path parent | [] -> path in collect [] [] eid in + let all_page_visibility = Hashtbl.create 16 in + let all_page_visible page = + match Hashtbl.find_opt all_page_visibility page with + | Some visible -> visible + | None -> + let visible = not (Read.page_is_hidden db page) in + Hashtbl.add all_page_visibility page visible; + visible in let candidates = Seq.filter_map (fun eid -> if Hashtbl.mem seen eid then None else ( Hashtbl.add seen eid (); @@ -195,19 +229,21 @@ let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today looka else match Read.ref_eids db eid "block/page" with | page :: _ -> let day = Read.int_value (Read.value db page "block/journal-day") in + let all_row = include_all && (dates <> [] || status <> None || has_task_class eid) + && all_page_visible page in let visible = ident <> Some "logseq.property/status.canceled" in let journal_task = dates = [] && status <> None && Option.exists in_today day in let recently_active = dates = [] && ident = Some doing_ident && Option.exists (fun date -> in_today (Cache_model.journal_day_for_ms date)) (last_activity eid) in let past = (due && not (List.mem today dates)) || (journal_task && day <> Some today) in - let today_row = visible && (due || journal_task || recently_active) in - let upcoming_row = visible && upcoming && ident <> Some "logseq.property/status.done" in - if not today_row && not upcoming_row then None else + let today_row = in_agenda eid && visible && (due || journal_task || recently_active) in + let upcoming_row = in_agenda eid && visible && upcoming && ident <> Some "logseq.property/status.done" in + if not today_row && not upcoming_row && not all_row then None else Option.map (fun block -> let status = match status with Some _ -> status | None -> default_status in let render_block = {block with Cache_model.status} in let title, created, updated = page_details page in - (today_row, upcoming_row, block.uuid, + (today_row, upcoming_row, all_row, block.uuid, `Assoc ["uuid", `String block.uuid; "block", decorate block.uuid (Rpc_encode.block_json render_block); "page", `String title; "pageJournalDay", json_int day; "pageCreated", json_int created; "pageUpdated", json_int updated; @@ -217,16 +253,21 @@ let rows ?actor ?on_comment_reference ?eids ?(lookback = OneWeek) db today looka (Read.block ~with_breadcrumbs:false identity db eid) | _ -> None)) candidates |> List.of_seq - |> List.sort (fun (_, _, left, _) (_, _, right, _) -> String.compare left right) in - let today = List.filter_map (fun (today, _, _, row) -> if today then Some row else None) candidates in - let upcoming = List.filter_map (fun (_, upcoming, _, row) -> if upcoming then Some row else None) candidates in - `List today, `List upcoming + |> List.sort (fun (_, _, _, left, _) (_, _, _, right, _) -> String.compare left right) in + let today = List.filter_map (fun (today, _, _, _, row) -> if today then Some row else None) candidates in + let upcoming = List.filter_map (fun (_, upcoming, _, _, row) -> if upcoming then Some row else None) candidates in + let all = if include_all then + `List (List.filter_map (fun (_, _, all, _, row) -> if all then Some row else None) candidates) + else `Null in + `List today, `List upcoming, all type cached_projection = { day : int; timezone : string; actor : string option; lookback : lookback; + include_all : bool; + all_uuids : Uuids.t; db : Ds.db Weak.t; result : Json.t; comment_references : Uuids.t; @@ -238,11 +279,16 @@ let create_cache () : cache = ref [] let remove_cached_graph cache graph = cache := List.remove_assoc graph !cache let clear_cache cache = cache := [] -let project ?read_rows ?actor ?(lookback = OneWeek) cache ~graph ~now ~force db = +let task_uuids = function + | `List rows -> List.filter_map (fun row -> match task_field "uuid" row with + | `String uuid -> Some uuid | _ -> None) rows |> Uuids.of_list + | _ -> Uuids.empty + +let project ?read_rows ?actor ?(lookback = OneWeek) ?(include_all = false) cache ~graph ~now ~force db = let comment_references = ref Uuids.empty in let on_comment_reference uuid = comment_references := Uuids.add uuid !comment_references in let read_rows = Option.value ~default:(fun db day days -> - rows ?actor ~on_comment_reference ~lookback db day days) read_rows in + rows ?actor ~on_comment_reference ~lookback ~include_all db day days) read_rows in let day = Cache_model.journal_day_for_ms now in let timezone = Int64.to_string (Dev_query.Date_time_util.journal_day_to_local_ms day) in let previous = match List.assoc_opt graph !cache with @@ -255,25 +301,28 @@ let project ?read_rows ?actor ?(lookback = OneWeek) cache ~graph ~now ~force db cache := (graph, value) :: List.filteri (fun index _ -> index < 3) remaining; value.result in match previous with - | Some value when not force && Option.exists ((==) db) (Weak.get value.db 0) -> + | Some value when not force && value.include_all = include_all + && Option.exists ((==) db) (Weak.get value.db 0) -> remember value | _ -> let range = "lookback", `String (lookback_to_string lookback) in let result = try let disabled, days = configuration db in - let today, upcoming = read_rows db day (if disabled then None else Some days) in + let today, upcoming, all = read_rows db day (if disabled then None else Some days) in `Assoc ["graphId", `String graph; "day", `Int day; "error", `Bool false; "success", `Bool true; - "retained", `Bool false; range; "today", today; "upcoming", upcoming] + "retained", `Bool false; range; "today", today; "upcoming", upcoming; "all", all] with error -> prerr_endline ("journal task query: " ^ Printexc.to_string error); let prior name = match previous with Some value -> member name value.result | None -> `List [] in `Assoc ["graphId", `String graph; "day", `Int day; "error", `Bool true; "retained", `Bool (Option.exists (fun value -> member "success" value.result = `Bool true || member "retained" value.result = `Bool true) previous); - range; "today", prior "today"; "upcoming", prior "upcoming"] in + range; "today", prior "today"; "upcoming", prior "upcoming"; + "all", (if include_all then prior "all" else `Null)] in let source = Weak.create 1 in Weak.set source 0 (Some db); - remember {day; timezone; actor; lookback; db = source; result; comment_references = !comment_references} + remember {day; timezone; actor; lookback; include_all; db = source; result; + all_uuids = task_uuids (member "all" result); comment_references = !comment_references} let refreshable_attr = function | "block/title" | "block/updated-at" | "block/tx-id" @@ -313,27 +362,34 @@ let refresh_blocks cache ~before ~after eids = conservative entries until the next full projection. *) let comment_references = ref cached.comment_references in let on_comment_reference uuid = comment_references := Uuids.add uuid !comment_references in - let result = if eids = [] then cached.result else + let result, all_uuids = if eids = [] then cached.result, cached.all_uuids else let disabled, days = configuration after in - let uuids = Hashtbl.create (List.length eids) in - List.iter (fun eid -> - Option.iter (fun uuid -> Hashtbl.replace uuids (`String uuid) ()) (Read.uuid_for_eid after eid)) eids; - let today, upcoming = rows ?actor:cached.actor ~on_comment_reference ~eids - ~lookback:cached.lookback after cached.day (if disabled then None else Some days) in + let uuids = List.filter_map (Read.uuid_for_eid after) eids |> Uuids.of_list in + let today, upcoming, all = rows ?actor:cached.actor ~on_comment_reference ~eids + ~lookback:cached.lookback ~include_all:cached.include_all + after cached.day (if disabled then None else Some days) in let uuid row = task_field "uuid" row in let compare_rows left right = compare (uuid left) (uuid right) in let replace old updated = match old, updated with | `List old, `List updated -> - let old = List.filter (fun row -> not (Hashtbl.mem uuids (uuid row))) old in + let old = List.filter (fun row -> match uuid row with + | `String id -> not (Uuids.mem id uuids) | _ -> true) old in `List (List.merge compare_rows old updated) | _ -> updated in + let updated_all = task_uuids all in + (* A change to a non-task never needs to walk the All list. *) + let all_changed = not (Uuids.is_empty updated_all) + || Uuids.exists (fun id -> Uuids.mem id cached.all_uuids) uuids in + let all_uuids = if all_changed then Uuids.union (Uuids.diff cached.all_uuids uuids) updated_all + else cached.all_uuids in `Assoc (List.map (function | "today", old -> "today", replace old today | "upcoming", old -> "upcoming", replace old upcoming - | field -> field) fields) in + | "all", old when all_changed -> "all", replace old all + | field -> field) fields), all_uuids in let source = Weak.create 1 in Weak.set source 0 (Some after); - {cached with db = source; result; comment_references = !comment_references} + {cached with db = source; result; all_uuids; comment_references = !comment_references} | _ -> cached in (* An unreadable row can be handled by the normal full query and its retained-result fallback. The edit is already staged. *) diff --git a/shared/src/logseq/core/mobile_session.ml b/shared/src/logseq/core/mobile_session.ml index fb696d3c..c1096b5f 100644 --- a/shared/src/logseq/core/mobile_session.ml +++ b/shared/src/logseq/core/mobile_session.ml @@ -146,12 +146,12 @@ let host_options ?journal_tasks ?show_journal_tasks (database : Database.mobile_ Some (fun day -> Graph.journal_page_uuid graph day); } -let create_rpc_session ?show_journal_tasks ?task_lookback ?show_notifications database ring catalog = +let create_rpc_session ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications database ring catalog = let journal_tasks = Journal_task_dates.create_cache () in let options = host_options ~journal_tasks ?show_journal_tasks database ring catalog in - Rpc.create_session ~journal_tasks {options with task_lookback; show_notifications} + Rpc.create_session ~journal_tasks {options with show_all_tasks; task_lookback; show_notifications} -let create ?show_journal_tasks ?task_lookback ?show_notifications crypto_call = +let create ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications crypto_call = let ring = Platform.create_keyring crypto_call Http.send in let graph = Graph.create @@ -166,7 +166,7 @@ let create ?show_journal_tasks ?task_lookback ?show_notifications crypto_call = } in let database = Database.create graph in - let session = create_rpc_session ?show_journal_tasks ?task_lookback ?show_notifications database ring None in + let session = create_rpc_session ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications database ring None in session.Types.state := { !(session.Types.state) with Types.sidebar_deferred = true }; { database; keyring = ring; session = ref session } @@ -238,7 +238,7 @@ let call (host : mobile_session) request = let catalog = Database.open_catalog host.database path in let options = Types.host !(host.session) in let session = create_rpc_session ?show_journal_tasks:options.show_journal_tasks - ?task_lookback:options.task_lookback + ?show_all_tasks:options.show_all_tasks ?task_lookback:options.task_lookback ?show_notifications:options.show_notifications host.database host.keyring (Some catalog) in session.Types.state := { !(session.Types.state) with Types.sidebar_deferred = true }; @@ -254,7 +254,7 @@ let call (host : mobile_session) request = | _ -> Rpc.dispatch session action payload) request -let start ?show_journal_tasks ?task_lookback ?show_notifications crypto_call = - let host = create ?show_journal_tasks ?task_lookback ?show_notifications crypto_call in +let start ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications crypto_call = + let host = create ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications crypto_call in Callback.register "logseq_mobile_call" (fun request -> call host request); host diff --git a/shared/src/logseq/core/mobile_session.mli b/shared/src/logseq/core/mobile_session.mli index 77101425..ea702aff 100644 --- a/shared/src/logseq/core/mobile_session.mli +++ b/shared/src/logseq/core/mobile_session.mli @@ -17,6 +17,18 @@ val host_options : E2ee_keyring.e2ee_keyring -> Sqlite.session option -> Session_types.host_options -val create : ?show_journal_tasks:(unit -> bool) -> ?task_lookback:(unit -> Journal_task_dates.lookback) -> ?show_notifications:(unit -> bool) -> (string -> string) -> mobile_session +val create : + ?show_journal_tasks:(unit -> bool) -> + ?show_all_tasks:(unit -> bool) -> + ?task_lookback:(unit -> Journal_task_dates.lookback) -> + ?show_notifications:(unit -> bool) -> + (string -> string) -> + mobile_session val call : mobile_session -> string -> string -val start : ?show_journal_tasks:(unit -> bool) -> ?task_lookback:(unit -> Journal_task_dates.lookback) -> ?show_notifications:(unit -> bool) -> (string -> string) -> mobile_session +val start : + ?show_journal_tasks:(unit -> bool) -> + ?show_all_tasks:(unit -> bool) -> + ?task_lookback:(unit -> Journal_task_dates.lookback) -> + ?show_notifications:(unit -> bool) -> + (string -> string) -> + mobile_session diff --git a/shared/src/logseq/core/rpc_session.ml b/shared/src/logseq/core/rpc_session.ml index 07185aec..f8502ea7 100644 --- a/shared/src/logseq/core/rpc_session.ml +++ b/shared/src/logseq/core/rpc_session.ml @@ -126,7 +126,8 @@ let journal_tasks_json ?(force = false) session = let cache = session.Types.journal_tasks in let actor = Option.map snd (collaboration_identity session) in let lookback = Option.map (fun read -> read ()) (host session).Types.task_lookback in - Journal_task_dates.project ?actor ?lookback cache ~graph:graph_id ~now:(now_ms ()) ~force db + let include_all = Option.exists (fun read -> read ()) (host session).Types.show_all_tasks in + Journal_task_dates.project ?actor ?lookback ~include_all cache ~graph:graph_id ~now:(now_ms ()) ~force db | None -> `Null) | _ -> `Null @@ -2845,16 +2846,18 @@ let rec dispatch session action payload = | Ok (), Some intent -> let after_stage () = let current = state session in - match Json.Util.member "agendaCollapsedSections" input, - Json.Util.member "editingUuid" input, current.outliner_state.editing, - Json.Util.member "tasksView" input with - | `List collapsed, `String uuid, Some editing, (`Assoc _ as view) when editing.uuid = uuid -> + let disclosed = match Json.Util.member "agendaDisclosedGroups" input with + | `Null -> Json.Util.member "agendaCollapsedSections" input + | groups -> groups in + match disclosed, Json.Util.member "editingUuid" input, + current.outliner_state.editing, Json.Util.member "tasksView" input with + | `List groups, `String uuid, Some editing, (`Assoc _ as view) when editing.uuid = uuid -> let boolean key = Json.Util.member key view = `Bool true in let visible = match Json.Util.member "section" view with - | `String ("today" | "upcoming" as section) -> + | `String ("today" | "upcoming" | "all" as section) -> Journal_task_dates.task_is_visible (journal_tasks_json session) ~section - ~collapsed:(List.filter_map (function `String key -> Some key | _ -> None) collapsed) + ~disclosed_groups:(List.filter_map (function `String key -> Some key | _ -> None) groups) ~group_by_page:(boolean "groupByPage") ~show_completed:(boolean "showCompleted") ~show_past:(boolean "showPast") uuid | _ -> false in diff --git a/shared/src/logseq/core/session_types.ml b/shared/src/logseq/core/session_types.ml index 7344e978..6e12fe06 100644 --- a/shared/src/logseq/core/session_types.ml +++ b/shared/src/logseq/core/session_types.ml @@ -81,6 +81,7 @@ type host_options = ; storage : Datascript.storage option ; outliner_projection_limit : int option ; show_journal_tasks : (unit -> bool) option + ; show_all_tasks : (unit -> bool) option ; task_lookback : (unit -> Journal_task_dates.lookback) option ; show_notifications : (unit -> bool) option ; open_graph : (string -> (unit, string) result) option @@ -203,6 +204,7 @@ let default_options = storage = None; outliner_projection_limit = None; show_journal_tasks = None; + show_all_tasks = None; task_lookback = None; show_notifications = None; open_graph = None; diff --git a/shared/src/logseq/core/session_types.mli b/shared/src/logseq/core/session_types.mli index f313881f..0a9fd9c3 100644 --- a/shared/src/logseq/core/session_types.mli +++ b/shared/src/logseq/core/session_types.mli @@ -74,6 +74,7 @@ type host_options = ; storage : Datascript.storage option ; outliner_projection_limit : int option ; show_journal_tasks : (unit -> bool) option + ; show_all_tasks : (unit -> bool) option ; task_lookback : (unit -> Journal_task_dates.lookback) option ; show_notifications : (unit -> bool) option ; open_graph : (string -> (unit, string) result) option diff --git a/shared/src/logseq/entry/logseq_mobile_entry.ml b/shared/src/logseq/entry/logseq_mobile_entry.ml index b963dfbb..ee5fee6b 100644 --- a/shared/src/logseq/entry/logseq_mobile_entry.ml +++ b/shared/src/logseq/entry/logseq_mobile_entry.ml @@ -2,7 +2,7 @@ let () = if not (Native_bridge.linked ()) then failwith "OCaml/LUI native bridge failed to link"; let host = Mobile_session.start ~show_journal_tasks:Native_bridge.show_journal_tasks - ~task_lookback:Native_bridge.task_lookback + ~show_all_tasks:Native_bridge.show_all_tasks ~task_lookback:Native_bridge.task_lookback ~show_notifications:Native_bridge.show_notifications Native_crypto.call_raw in Native_bridge.set_search_index_source (fun () -> Mobile_graph.pending_search_index host.database.graph) diff --git a/shared/src/logseq/model.ml b/shared/src/logseq/model.ml index e4fe74b0..79d3e4df 100644 --- a/shared/src/logseq/model.ml +++ b/shared/src/logseq/model.ml @@ -49,7 +49,7 @@ type sidebar_page = type node_deletion = PageToDelete of sidebar_page | BlockToDelete of sidebar_page -type tasks_tab = TasksToday | TasksUpcoming +type tasks_tab = TasksToday | TasksUpcoming | TasksAll type push_preferences = { enabled : bool; comments : bool; reactions : bool } type task_sort = ScheduledDate | DeadlineDate | PageOrder type task_page_sort = PageName | PageUpdated | PageCreated @@ -1168,7 +1168,7 @@ let journal_task_retry_available_ (current : logseq_model) = let outliner_task_selection_ (current : logseq_model) = current.outliner_selected_task_block_ids <> [] -let journal_tasks_collapsed (current : logseq_model) = +let journal_task_disclosed_groups (current : logseq_model) = match current.selected_graph_id, journal_task_field "day" current.journal_tasks with | Some graph, `Int day -> (match Lui_protocol.String_map.find_opt graph current.journal_task_disclosures with @@ -1176,7 +1176,7 @@ let journal_tasks_collapsed (current : logseq_model) = | _ -> []) | _ -> [] -let set_journal_tasks_collapsed (current : logseq_model) sections = +let set_journal_task_disclosed_groups (current : logseq_model) sections = match current.selected_graph_id, journal_task_field "day" current.journal_tasks with | Some graph, `Int day -> {current with journal_task_disclosures = @@ -1184,7 +1184,10 @@ let set_journal_tasks_collapsed (current : logseq_model) sections = else Lui_protocol.String_map.add graph (day, sections) current.journal_task_disclosures} | _ -> current -let tasks_view_section = function TasksToday -> "today" | TasksUpcoming -> "upcoming" +let tasks_view_section = function + | TasksToday -> "today" + | TasksUpcoming -> "upcoming" + | TasksAll -> "all" let tasks_selection_active current = let selecting = function @@ -1765,7 +1768,7 @@ let settle_hidden_task_editor ?(remount = false) current = match current.destination, current.outliner_edit_scope with | TasksDestination, Some (scope, uuid) when scope = "journal-task." ^ uuid -> let visible = Journal_task_dates.task_is_visible current.journal_tasks - ~section:(tasks_view_section options.tab) ~collapsed:(journal_tasks_collapsed current) + ~section:(tasks_view_section options.tab) ~disclosed_groups:(journal_task_disclosed_groups current) ~group_by_page:options.group_by_page ~show_completed:options.show_completed ~show_past:options.show_past uuid in if remount || not visible then begin @@ -2418,10 +2421,10 @@ let rec update (current : logseq_model) action = else current | ToggleJournalTaskSection _ when tasks_selection_active current -> current | ToggleJournalTaskSection section -> - let collapsed = journal_tasks_collapsed current in - let updated = set_journal_tasks_collapsed current - (if List.mem section collapsed then List.filter ((<>) section) collapsed - else section :: collapsed) in + let groups = journal_task_disclosed_groups current in + let updated = set_journal_task_disclosed_groups current + (if List.mem section groups then List.filter ((<>) section) groups + else section :: groups) in settle_hidden_task_editor updated | RetryJournalTasks -> let key = "journal-tasks.refresh" in @@ -3392,7 +3395,8 @@ let rec update (current : logseq_model) action = if { current.tasks_view with tab = tasks_view.tab } = tasks_view then updated else update updated SaveUISession in (match updated.selected_graph_id with - | Some graph when current.tasks_view.lookback <> tasks_view.lookback -> + | Some graph when current.tasks_view.lookback <> tasks_view.lookback + || (tasks_view.tab = TasksAll && current.tasks_view.tab <> TasksAll) -> let payload = Yojson.Basic.to_string (`Assoc ["action", `String "refreshJournalTasks"; "graphId", `String graph]) in update updated (SubmitNodeProperty ("journal-tasks.refresh", payload)) | _ -> updated) diff --git a/shared/src/logseq/model.mli b/shared/src/logseq/model.mli index 70a8e6c8..abf3e6f9 100644 --- a/shared/src/logseq/model.mli +++ b/shared/src/logseq/model.mli @@ -36,7 +36,7 @@ type sidebar_page = type node_deletion = PageToDelete of sidebar_page | BlockToDelete of sidebar_page -type tasks_tab = TasksToday | TasksUpcoming +type tasks_tab = TasksToday | TasksUpcoming | TasksAll type push_preferences = { enabled : bool; comments : bool; reactions : bool } type task_sort = ScheduledDate | DeadlineDate | PageOrder type task_page_sort = PageName | PageUpdated | PageCreated @@ -821,7 +821,7 @@ val available_task_statuses : task_status list -> task_status list val string_vector_contains_ : string list -> string -> bool val graph_local_ : logseq_model -> string -> bool val remove_string : string list -> string -> string list -val journal_tasks_collapsed : logseq_model -> string list +val journal_task_disclosed_groups : logseq_model -> string list val journal_task_retry_available_ : logseq_model -> bool val outliner_task_selection_ : logseq_model -> bool val bounded_url_delimiter : int -> int -> int diff --git a/shared/src/logseq/native_bridge.ml b/shared/src/logseq/native_bridge.ml index d1691fbd..f6e8140a 100644 --- a/shared/src/logseq/native_bridge.ml +++ b/shared/src/logseq/native_bridge.ml @@ -41,6 +41,10 @@ let show_journal_tasks () = let current = App.model app in View_base.tasks_destination_ current && View_base.node_navigation_inactive_ current) !current_app +let show_all_tasks () = + show_journal_tasks () + && (App.model (app ())).Model.tasks_view.tab = Model.TasksAll + let show_notifications () = Option.exists (fun app -> let current = App.model app in diff --git a/shared/src/logseq/native_bridge.mli b/shared/src/logseq/native_bridge.mli index e3da6326..c72cba76 100644 --- a/shared/src/logseq/native_bridge.mli +++ b/shared/src/logseq/native_bridge.mli @@ -6,6 +6,7 @@ val app : unit -> (Model.logseq_model, Model.logseq_action) Lui_app.reducer_app val show_journal_tasks : unit -> bool +val show_all_tasks : unit -> bool val task_lookback : unit -> Journal_task_dates.lookback val show_notifications : unit -> bool diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index 4012e7bb..587c964a 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -98,7 +98,7 @@ let task_dates_dialog model_source send : t = let current = Signal.sample model_source in let collapsed = match editing, current.outliner_edit_scope with | Some uuid, Some (scope, target) when target = uuid && scope = View_rows.journal_task_scope uuid -> - `List (List.map (fun name -> `String name) (Model.journal_tasks_collapsed current)) + `List (List.map (fun name -> `String name) (Model.journal_task_disclosed_groups current)) | _ -> `Null in let task_view = match current.destination, collapsed with | Model.TasksDestination, `List _ -> @@ -110,7 +110,7 @@ let task_dates_dialog model_source send : t = let payload = Yojson.Basic.to_string (`Assoc [ "action", `String "saveTaskDates"; "graphId", `String graph; "editingUuid", Option.fold ~none:`Null ~some:(fun uuid -> `String uuid) editing; - "agendaCollapsedSections", collapsed; + "agendaDisclosedGroups", collapsed; "tasksView", task_view; "targets", `List targets; "changes", `Assoc changes; "repeat", repeat]) in ignore (send (Model.SubmitNodeProperty (key, payload))) @@ -2054,9 +2054,11 @@ let journal_task_row context model_source task_source send = outliner_discussion context view_model source send_block; ]) -let task_heading ?page context model_source send section ~identifier label = +let task_heading ~page context model_source send group (label, count) = let collapsed = Signal.map (fun (model : Model.logseq_model) -> - List.mem section (Model.journal_tasks_collapsed model)) model_source in + let section = Model.tasks_view_section model.tasks_view.tab in + Journal_task_dates.task_group_is_collapsed ~section + ~disclosed_groups:(Model.journal_task_disclosed_groups model) page) model_source in let title = text ~value:label ~style_class:"semibold" ~foreground:"muted-foreground" [] in let chevron = if Lui_ui.platform context = IOS && Lui_ui.host context = SwiftUIHost then @@ -2071,33 +2073,37 @@ let task_heading ?page context model_source send section ~identifier label = else icon ~name:(`app "chevron-down") ~name_signal:(Signal.map (fun collapsed -> `app (if collapsed then "chevron-right" else "chevron-down")) collapsed) ~width:14 ~height:14 ~foreground:"muted-foreground" [] in - let contents = if Lui_ui.host context = KotlinHost then - [row ~gap:6 ~cross:`center [title; chevron]] - else [title; box ~width:6 []; chevron] in - let toggle () = ignore (send (Model.ToggleJournalTaskSection section)) in + let toggle () = ignore (send (Model.ToggleJournalTaskSection group)) in let current = Signal.sample model_source in - box ~padding_horizontal:16 ~margin_top:12 (match page with - | Some page when page <> "" -> + let disabled = Signal.map View_base.outliner_selection_active_ model_source in + box ~padding_horizontal:16 ~margin_top:12 (match count with + | Some count -> + [button ~variant:`ghost ~padding_horizontal:0 ~min_height:44 ~text:"" ~label + ~disabled_signal:disabled ~accessibility_identifier:group ~on_press:(fun _ -> toggle ()) [ + row ~grow:1.0 ~gap:8 ~cross:`center [ + box ~grow:1.0 [title]; + text ~value:(string_of_int count) ~style_class:"footnote" ~foreground:"muted-foreground" []; + chevron; + ] + ]] + | None when page <> "" -> let disclosure_label = Signal.map (fun collapsed -> View_base.tr current (if collapsed then "Expand" else "Collapse")) collapsed in [row ~gap:0 ~cross:`center [ button ~variant:`ghost ~padding_horizontal:0 ~foreground:"muted-foreground" ~min_height:44 ~text_alignment:`start ~text:label ~label:(View_base.tr_named current "Open {1}" label) - ~disabled_signal:(Signal.map View_base.outliner_selection_active_ model_source) - ~accessibility_identifier:(identifier ^ ".open") + ~disabled_signal:disabled ~accessibility_identifier:(group ^ ".open") ~on_press:(fun _ -> ignore (send (View_base.request_node_action (Signal.sample model_source) page))) [title]; View_base.with_string_prop_signal AccessibilityLabel disclosure_label (button ~variant:`ghost ~width:44 ~min_height:44 ~text:"" - ~disabled_signal:(Signal.map View_base.outliner_selection_active_ model_source) - ~accessibility_identifier:identifier ~on_press:(fun _ -> toggle ()) [chevron]); + ~disabled_signal:disabled ~accessibility_identifier:group ~on_press:(fun _ -> toggle ()) [chevron]); ]] - | _ -> - (if page = None then [separator []] else []) @ + | None -> [button ~variant:`ghost ~padding_horizontal:0 ~foreground:"muted-foreground" ~min_height:44 ~text_alignment:`start ~text:label ~label - ~accessibility_identifier:identifier - ~on_press:(fun _ -> toggle ()) contents]) + ~disabled_signal:disabled ~accessibility_identifier:group + ~on_press:(fun _ -> toggle ()) [row ~gap:6 ~cross:`center [title; chevron]]]) let journal_task_entry context model_source send = function | View_rows.Journal_task_error -> @@ -2122,7 +2128,7 @@ let with_journal_task_transition model_source content = attach context parent node; Lui_ui.extension_property_signal context node "collapsed" (Signal.map (fun model -> - StringValue (String.concat "," (List.sort String.compare (Model.journal_tasks_collapsed model)))) model_source); + StringValue (String.concat "," (List.sort String.compare (Model.journal_task_disclosed_groups model)))) model_source); ignore (mount context ~parent:node content); node | _ -> mount context ?parent content @@ -2132,9 +2138,10 @@ let mount_journal_task_entry context model_source send entry_source = | View_rows.Journal_task_row (initial, _) -> journal_task_row context model_source (Signal.map (function | View_rows.Journal_task_row (task, _) -> task | _ -> initial) entry_source) send - | View_rows.Tasks_page_heading (section, page, initial) -> - reactive (task_heading ~page context model_source send section ~identifier:section) - (Signal.map (function View_rows.Tasks_page_heading (_, _, title) -> title | _ -> initial) entry_source) + | View_rows.Tasks_page_heading (group, page, label, count) -> + reactive (task_heading ~page context model_source send group) + (Signal.map (function View_rows.Tasks_page_heading (_, _, label, count) -> label, count + | _ -> label, count) entry_source) | entry -> journal_task_entry context model_source send entry let outliner_bottom_spacer () = @@ -2233,32 +2240,50 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par let own signal = Signal.own_signal mount_context.ui_scope signal in let tab = own (Signal.map (fun (current : Model.logseq_model) -> current.tasks_view.tab) model_source) in let entry_inputs_equal (left : Model.logseq_model) (right : Model.logseq_model) = - left.journal_tasks = right.journal_tasks - && left.tasks_view = right.tasks_view + let section = Model.tasks_view_section left.tasks_view.tab in + let task_input field = + let previous = journal_task_field field left.journal_tasks in + let next = journal_task_field field right.journal_tasks in + previous == next || previous = next in + left.tasks_view = right.tasks_view + && task_input section + && task_input "error" && left.journal_title_format = right.journal_title_format && left.language = right.language && left.system_language = right.system_language && left.selected_graph_id = right.selected_graph_id - && Model.journal_tasks_collapsed left = Model.journal_tasks_collapsed right + && Model.journal_task_disclosed_groups left = Model.journal_task_disclosed_groups right && left.outliner_edit_scope = right.outliner_edit_scope && Option.map (fun (edit : Model.outliner_editing) -> edit.editing_uuid) left.outliner_editing = Option.map (fun (edit : Model.outliner_editing) -> edit.editing_uuid) right.outliner_editing in let entry_inputs = own (Signal.cutoff entry_inputs_equal model_source) in let entries = own (Signal.map View_rows.tasks_view_rows entry_inputs) in let empty = own (Signal.map ((=) []) entries) in - let tab_button id name image value = + let loading = own (Signal.map (fun (current : Model.logseq_model) -> + current.tasks_view.tab = Model.TasksAll + && journal_task_field "all" current.journal_tasks = `Null + && task_effect_active "journal-tasks.refresh" current) model_source) in + let tab_icon = function + | Model.TasksToday -> "tasks-today" + | Model.TasksUpcoming -> "calendar" + | Model.TasksAll -> "toolbar-task" in + let tab_button active_tab value name = let label = View_base.tr (Signal.sample model_source) name in - let selected = own (Signal.map ((=) value) tab) in - let background = own (Signal.map (fun selected -> - if selected then "task-tab-selected-background" else "task-tab-background") selected) in - View_base.with_string_prop_signal BackgroundValue background (box ~corner_radius:22 [ - button ~text:label ~label ~icon:(`app image) ~variant:`ghost ~min_height:44 - ~padding_horizontal:15 ~corner_radius:22 ~selected_signal:selected - ~disabled_signal:(own (Signal.map View_base.outliner_selection_active_ model_source)) - ~foreground_signal:(own (Signal.map (fun selected -> if selected then "link" else "foreground") selected)) - ~accessibility_identifier:("tasks.tab." ^ id) - ~on_press:(fun _ -> update_tasks_view model_source send (fun options -> { options with tab = value })) []; - ]) in + let selected = active_tab = value in + let background = if selected then "task-tab-selected-background" else "task-tab-background" in + let foreground = if selected then "link" else "foreground" in + let disabled = own (Signal.map View_base.outliner_selection_active_ model_source) in + let identifier = "tasks.tab." ^ Model.tasks_view_section value in + let icon = `app (tab_icon value) in + let on_press _ = update_tasks_view model_source send (fun options -> { options with tab = value }) in + box ~background ~corner_radius:22 [ + (if selected then + button ~text:label ~label ~icon ~variant:`ghost ~min_height:44 ~padding_horizontal:15 + ~corner_radius:22 ~selected ~disabled_signal:disabled ~foreground ~accessibility_identifier:identifier ~on_press [] + else + icon_button ~label ~icon ~variant:`ghost ~width:44 ~min_height:44 + ~corner_radius:22 ~selected ~disabled_signal:disabled ~foreground ~accessibility_identifier:identifier ~on_press []); + ] in mount mount_context ?parent (View_base.with_reading_insets (column ~grow:1.0 ~accessibility_identifier:"screen.tasks" [ keyed ~source:(own (Signal.map2 (fun tab empty -> [tab, empty]) tab empty)) ~key:Fun.id ~cmp:compare @@ -2270,8 +2295,9 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par heading ~value:(View_base.tr (Signal.sample model_source) "Tasks") ~level:`h1 ~style_class:"semibold" ~accessibility_identifier:"tasks.title" []; row ~gap:8 ~cross:`center [ - tab_button "today" "Today" "tasks-today" Model.TasksToday; - tab_button "upcoming" "Upcoming" "calendar" Model.TasksUpcoming; + tab_button active_tab Model.TasksToday "Today"; + tab_button active_tab Model.TasksUpcoming "Upcoming"; + tab_button active_tab Model.TasksAll "All"; ]; ]; box ~height:16 []; @@ -2283,15 +2309,16 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par if not is_empty then list else overlay ~grow:1.0 ~alignment:`center [ box ~grow:1.0 [list]; - column ~gap:10 ~cross:`center ~padding_horizontal:16 [ - icon ~name:(`app (if active_tab = Model.TasksToday then "tasks-today" else "calendar")) - ~width:25 ~height:25 ~foreground:"muted-foreground" - ~accessibility_identifier:"tasks.empty.icon" []; - text ~value:(View_base.tr (Signal.sample model_source) - (if active_tab = Model.TasksToday then "No tasks to show" else "No upcoming tasks")) - ~text_alignment:`center ~foreground:"muted-foreground" - ~accessibility_identifier:"tasks.empty" []; - ]; + if_ ~test:loading (spinner ~accessibility_identifier:"tasks.loading" []); + if_ ~test:(own (Signal.map not loading)) + (column ~gap:10 ~cross:`center ~padding_horizontal:16 [ + icon ~name:(`app (tab_icon active_tab)) ~width:25 ~height:25 ~foreground:"muted-foreground" + ~accessibility_identifier:"tasks.empty.icon" []; + text ~value:(View_base.tr (Signal.sample model_source) + (if active_tab = Model.TasksUpcoming then "No upcoming tasks" else "No tasks to show")) + ~text_alignment:`center ~foreground:"muted-foreground" + ~accessibility_identifier:"tasks.empty" []; + ]); ]); ])) diff --git a/shared/src/logseq/view_rows.ml b/shared/src/logseq/view_rows.ml index 196bf8f6..d5a21347 100644 --- a/shared/src/logseq/view_rows.ml +++ b/shared/src/logseq/view_rows.ml @@ -322,7 +322,7 @@ type placeholder = { } type page_entry = Outline_entry of retained_row | Reference_entry of reference_entry | Placeholder_entry of placeholder - | Tasks_page_heading of string * string * string + | Tasks_page_heading of string * string * string * int option | Journal_task_row of Yojson.Basic.t * bool | Journal_task_error @@ -388,11 +388,13 @@ let journal_task_editing (current : Model.logseq_model) task = current.outliner_editing let journal_task_editing_row (current : Model.logseq_model) = - match current.outliner_edit_scope with - | Some (scope, _) when String.starts_with ~prefix:"journal-task." scope -> - ["today"; "upcoming"] |> List.find_map (fun section -> - Option.bind (List.find_opt (journal_task_editing current) (task_list current.journal_tasks section)) - (fun task -> Response_snapshot.related_row (task_field "block" task))) + match current.outliner_edit_scope, current.outliner_editing with + | Some (scope, uuid), Some editing when scope = journal_task_scope uuid && editing.editing_uuid = uuid -> + let sections = if current.tasks_view.tab = Model.TasksAll then ["all"; "today"; "upcoming"] + else ["today"; "upcoming"] in + List.find_map (fun section -> + Option.bind (List.find_opt (fun task -> journal_task_uuid task = uuid) (task_list current.journal_tasks section)) + (fun task -> Response_snapshot.related_row (task_field "block" task))) sections | _ -> None let tasks_view_rows (current : Model.logseq_model) = @@ -441,14 +443,16 @@ let tasks_view_rows (current : Model.logseq_model) = let id = page_id task in let previous = Option.value ~default:[] (Hashtbl.find_opt groups id) in Hashtbl.replace groups id (task :: previous)) tasks; + let disclosed_groups = Model.journal_task_disclosed_groups current in Hashtbl.to_seq_values groups |> List.of_seq |> List.sort (fun left right -> compare_pages (List.hd left) (List.hd right)) |> List.concat_map (function | task :: _ as tasks -> let page = page_id task in let key = Journal_task_dates.task_group_key section page in - Tasks_page_heading (key, page, page_title task) :: - (if List.mem key (Model.journal_tasks_collapsed current) then [] else render tasks) + let count = if options.tab = Model.TasksAll then Some (List.length tasks) else None in + Tasks_page_heading (key, page, page_title task, count) :: + (if Journal_task_dates.task_group_is_collapsed ~section ~disclosed_groups page then [] else render tasks) | [] -> []) in (if task_field "error" agenda = `Bool true then [Journal_task_error] else []) @ entries @@ -524,7 +528,7 @@ let page_entry_identifier = function | Reference_entry row -> "reference." ^ reference_entry_identifier row | Placeholder_entry {parent_uuid; journal_heading = Some _; _} -> "placeholder.journal-heading." ^ parent_uuid | Placeholder_entry value -> "placeholder." ^ value.parent_uuid - | Tasks_page_heading (key, _, _) -> key + | Tasks_page_heading (key, _, _, _) -> key | Journal_task_row (task, _) -> journal_task_scope (journal_task_uuid task) | Journal_task_error -> "journal-tasks.error" @@ -552,7 +556,8 @@ let page_entry_fast_equal left right = | Outline_entry l, Outline_entry r -> retained_row_fast_equal l r | Reference_entry l, Reference_entry r -> l == r || l = r | Placeholder_entry l, Placeholder_entry r -> l = r - | Tasks_page_heading (k1, p1, t1), Tasks_page_heading (k2, p2, t2) -> k1 = k2 && p1 = p2 && t1 = t2 + | Tasks_page_heading (k1, p1, t1, c1), Tasks_page_heading (k2, p2, t2, c2) -> + k1 = k2 && p1 = p2 && t1 = t2 && c1 = c2 | Journal_task_row (t1, b1), Journal_task_row (t2, b2) -> b1 = b2 && (t1 == t2 || t1 = t2) | Journal_task_error, Journal_task_error -> true | _ -> false diff --git a/shared/src/logseq/view_rows.mli b/shared/src/logseq/view_rows.mli index 219a075b..cb07a4d9 100644 --- a/shared/src/logseq/view_rows.mli +++ b/shared/src/logseq/view_rows.mli @@ -50,7 +50,7 @@ type placeholder = { } type page_entry = Outline_entry of retained_row | Reference_entry of reference_entry | Placeholder_entry of placeholder - | Tasks_page_heading of string * string * string + | Tasks_page_heading of string * string * string * int option | Journal_task_row of Yojson.Basic.t * bool | Journal_task_error val task_field : string -> Yojson.Basic.t -> Yojson.Basic.t diff --git a/shared/test/logseq/app_test.ml b/shared/test/logseq/app_test.ml index 09cbc625..34f35ab5 100644 --- a/shared/test/logseq/app_test.ml +++ b/shared/test/logseq/app_test.ml @@ -7614,7 +7614,7 @@ let journal_agenda_is_retained_across_navigation () = graphs; outliner_rows = [row]; journal_outliner_rows = [row]; journal_tasks = `Assoc ["graphId", `String id; "day", `Int day; "today", `List [task (id ^ "-overdue") "inbox" 20261122; task (id ^ "-due") "project" day]; - "upcoming", `List []] } in + "upcoming", `List []; "all", `List [task (id ^ "-all-only") "project" 20260901]] } in let snapshot data = apply (Model.ApplyCoreSnapshot data) in let root = Lui_app.root_node app in let find parent id = descendant_with_identifier renderer parent id in @@ -7638,7 +7638,34 @@ let journal_agenda_is_retained_across_navigation () = tap root "tasks.menu.expanded"; tap root "tasks.tab.upcoming"; check_eq (find root "tasks.menu.past") (-1); + let chip_property section = property renderer (find root ("tasks.tab." ^ section)) in + let chip_text section = chip_property section Lui_protocol.TextValue in + check_eq (chip_text "upcoming") (Some (Lui_protocol.StringValue "Upcoming")); + check_eq (chip_text "all") None; + check_eq (chip_property "all" Lui_protocol.AccessibilityLabel) (Some (Lui_protocol.StringValue "All")); + tap root "tasks.tab.all"; + let refresh_id = match List.find_map (function + | Model.NodePropertyEffect (id, "journal-tasks.refresh", _) -> Some id + | _ -> None) (App.model app).pending_effects with + | Some id -> id + | None -> fail "Expected All to load its task projection" in + apply (Model.DequeueEffect refresh_id); + snapshot work; + apply (Model.ResolveEffect (refresh_id, true, "")); + check_eq (chip_text "all") (Some (Lui_protocol.StringValue "All")); + check_eq (chip_text "upcoming") None; + check_eq (find root "tasks.menu.past") (-1); + let all_group = Journal_task_dates.task_group_key "all" "project" in + let all_task () = find root "journal-task.work-all-only" in + check (find root all_group <> -1); + check_eq (all_task ()) (-1); + tap root all_group; + check (all_task () <> -1); + tap root all_group; + check_eq (all_task ()) (-1); tap root "tasks.tab.today"; + check_eq (chip_text "today") (Some (Lui_protocol.StringValue "Today")); + check_eq (all_task ()) (-1); check (find root "tasks.menu.past" <> -1); let pane () = find root "screen.tasks" in let group = Journal_task_dates.task_group_key "today" "project" in @@ -7673,10 +7700,10 @@ let journal_agenda_is_retained_across_navigation () = (App.model app).journal_tasks `Null; snapshot notes; apply (Model.ApplyGraphLoading false); - check_eq (Model.journal_tasks_collapsed (App.model app)) []; + check_eq (Model.journal_task_disclosed_groups (App.model app)) []; check_eq (overdue ()) (-1); snapshot work; - check_eq (Model.journal_tasks_collapsed (App.model app)) [group]; + check_eq (Model.journal_task_disclosed_groups (App.model app)) [group]; let failure = `Assoc (["error", `Bool true; "retained", `Bool true] @ Yojson.Basic.Util.to_assoc work.journal_tasks) in snapshot {work with journal_tasks = failure}; diff --git a/shared/test/logseq/editor_command_test.ml b/shared/test/logseq/editor_command_test.ml index d5f7c8f3..f4dec6fc 100644 --- a/shared/test/logseq/editor_command_test.ml +++ b/shared/test/logseq/editor_command_test.ml @@ -1497,7 +1497,7 @@ let journal_task_dates_partition_and_recover () = R.with_runtime (fun _ runtime check ~msg:"dated blocks without status still render the graph's default status" (member "status" display <> `Null); let other_graph = project ~graph:"other" - ~read_rows:(fun _ _ _ -> `List [], `List []) () in + ~read_rows:(fun _ _ _ -> `List [], `List [], `Null) () in check_eq (uuids "today" other_graph) []; check_eq ~msg:"revisiting an unchanged resident graph reuses its task projection" (project ~read_rows:(fun _ _ _ -> failwith "cache miss") ()) successful; @@ -1587,6 +1587,46 @@ let task_tabs_follow_status_and_due_dates () = R.with_runtime (fun _ runtime con check_eq (uuids "today" changed) [`String Q.owner]; check_eq (uuids "upcoming" changed) []) +let all_tasks_include_undated_and_out_of_range_blocks () = R.with_runtime (fun _ runtime conn -> + let local = Dev_query.Date_time_util.journal_day_to_local_ms in + let status uuid choice = put uuid "logseq.property/status" + (Ds.Ref_to (Ds.Ident ("logseq.property/status." ^ choice))) in + rebase runtime conn [ + put Q.page "block/journal-day" (Ds.Int64 20261123L); + put Q.alpha "block/tags" (Ds.Ref_to (Ds.Ident "logseq.class/Task")); + put Q.beta Journal_task_dates.scheduled (Ds.Int64 (local 20270101)); + put Q.beta Journal_task_dates.deadline (Ds.Int64 (local 20240101)); + status Q.owner "done"; + put Q.definition Journal_task_dates.scheduled (Ds.Int64 (local 20261124))]; + let cache = Journal_task_dates.create_cache () in + let project ?read_rows ?(force = false) ~include_all () = + Journal_task_dates.project ?read_rows ~include_all cache ~graph:"tasks" + ~now:(Int64.to_int (local 20261123)) ~force (Graph_runtime.db runtime) in + let ids section snapshot = List.map (member "uuid") (items section snapshot) in + let agenda = project ~include_all:false () in + check_eq (member "all" agenda) `Null; + check (List.mem (`String Q.alpha) (ids "today" agenda)); + check_eq (ids "upcoming" agenda) [`String Q.definition]; + let all = project ~include_all:true () in + check_eq (ids "all" all) + (List.sort compare [`String Q.alpha; `String Q.beta; `String Q.definition; `String Q.owner]); + List.iter (fun section -> check_eq (ids section all) (ids section agenda)) ["today"; "upcoming"]; + let before = Graph_runtime.db runtime in + rebase runtime conn [ + Ds.Retract (Q.ref_uuid Q.beta, Journal_task_dates.scheduled, None); + Ds.Retract (Q.ref_uuid Q.beta, Journal_task_dates.deadline, None); + status R.gamma "canceled"]; + let after = Graph_runtime.db runtime in + let eids = List.filter_map (fun uuid -> Ds.entid after "block/uuid" (Ds.Uuid uuid)) [Q.beta; R.gamma] in + Journal_task_dates.refresh_blocks cache ~before ~after eids; + let refreshed = project ~include_all:true ~read_rows:(fun _ _ _ -> fail "expected incremental reuse") () in + check_eq (member "error" refreshed) (`Bool false); + check_eq (ids "all" refreshed) + (List.sort compare [`String Q.alpha; `String Q.definition; `String Q.owner; `String R.gamma]); + let failed = project ~include_all:true ~force:true ~read_rows:(fun _ _ _ -> failwith "query failed") () in + check_eq (ids "all" failed) (ids "all" refreshed); + check_eq (member "all" (project ~include_all:false ())) `Null) + let journal_tasks_use_a_bounded_date_window () = R.with_runtime (fun _ runtime conn -> let local = Dev_query.Date_time_util.journal_day_to_local_ms in let deadline uuid day = put uuid Journal_task_dates.deadline (Ds.Int64 (local day)) in @@ -1911,6 +1951,7 @@ let cases = [ case "block selection toggles with haptic feedback" block_selection_toggles_with_haptic_feedback; case "block menu targets the pressed selection" block_menu_targets_the_pressed_selection; case "journal Doing tasks follow status and due dates" task_tabs_follow_status_and_due_dates; + case "All tasks include undated and out-of-range blocks" all_tasks_include_undated_and_out_of_range_blocks; case "journal tasks use a bounded date window" journal_tasks_use_a_bounded_date_window; case "Tasks includes tasks from journal pages" tasks_tab_includes_tasks_from_journal_pages; case "journal task projection survives page navigation" journal_task_projection_survives_page_navigation; From d850ffd6f7218c7464091f18e7d26a6b5c703fb7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 12:58:00 +0800 Subject: [PATCH 2/7] Fix All task selection and send incremental updates --- shared/bench/outliner_perf.ml | 43 +++++- shared/bench/outliner_workload.ml | 3 +- shared/src/logseq/core/journal_task_dates.ml | 144 +++++++++++++----- shared/src/logseq/core/mobile_session.ml | 14 +- shared/src/logseq/core/mobile_session.mli | 4 +- shared/src/logseq/core/rpc_session.ml | 37 +++-- shared/src/logseq/core/session_types.ml | 4 +- shared/src/logseq/core/session_types.mli | 2 +- .../src/logseq/entry/logseq_mobile_entry.ml | 2 +- shared/src/logseq/model.ml | 27 +++- shared/src/logseq/model.mli | 1 + shared/src/logseq/native_bridge.ml | 10 +- shared/src/logseq/native_bridge.mli | 2 +- shared/src/logseq/view_outliner.ml | 3 +- shared/test/logseq/app_test.ml | 23 +++ shared/test/logseq/editor_command_test.ml | 15 ++ 16 files changed, 262 insertions(+), 72 deletions(-) diff --git a/shared/bench/outliner_perf.ml b/shared/bench/outliner_perf.ml index d8667d92..ca1769ae 100644 --- a/shared/bench/outliner_perf.ml +++ b/shared/bench/outliner_perf.ml @@ -142,6 +142,47 @@ let check_rtc_and_tasks db = assert (task "today" date = None && Option.is_some (task "upcoming" date))); print_endline "RTC edits, repeated Enter with confirmations, and Tasks edits are within budget" +let check_all_task_edits db = + let agenda = ref `Null in + let request () = Journal_task_dates.All_visible (Journal_task_dates.projection_revision !agenda) in + let agenda_payload response = Workload.member "journalTasks" (Workload.result response) in + let all_rows () = Json.Util.to_list (Workload.member "all" !agenda) in + let target () = List.find (fun row -> Workload.member "uuid" row = `String Workload.external_task) (all_rows ()) in + Workload.with_session ~show_journal_tasks:(fun () -> true) ~all_tasks_request:request db (fun session -> + let initial = agenda_payload (Workload.dispatch session "clearSelectedPage" "") in + agenda := initial; + assert (List.length (all_rows ()) = 1_040); + let full_size = String.length (Json.to_string initial) in + let transport = Workload.connected session in + Workload.edit_external_task session; + let draft, (_, _, size) = measure (fun () -> Workload.type_external_task session) in + assert (agenda_payload draft = `Null && size < 8_192); + let change label run = + let response, (ms, _, response_size) = measure (fun () -> run session) in + let payload = agenda_payload response in + let delta_size = String.length (Json.to_string payload) in + assert (Journal_task_dates.delta_base payload = Journal_task_dates.projection_revision !agenda); + assert (Workload.member "all" payload = `Null && delta_size < 8_192); + agenda := Journal_task_dates.apply_delta !agenda payload; + assert (List.length (all_rows ()) = 1_040); + let _, ack = Workload.confirm_pending session transport in + let acknowledgment = agenda_payload ack in + if acknowledgment <> `Null then begin + assert (Journal_task_dates.delta_base acknowledgment = Journal_task_dates.projection_revision !agenda); + assert (String.length (Json.to_string acknowledgment) < 8_192); + agenda := Journal_task_dates.apply_delta !agenda acknowledgment + end; + Printf.printf "All %s: %.2f ms, %d-byte agenda delta, %d-byte response (full agenda %d bytes)\n%!" + label ms delta_size response_size full_size in + change "title edit" Workload.save; + assert (Workload.member "title" (Workload.member "block" (target ())) = `String "Updated task"); + change "status change" Workload.external_task_status; + assert (Workload.member "ident" (Workload.member "status" (Workload.member "block" (target ()))) + = `String "logseq.property/status.doing"); + let before = Workload.member "scheduled" (target ()) in + change "date change" Workload.external_task_date; + assert (before <> Workload.member "scheduled" (target ()))) + let check db = Workload.with_session db (fun session -> let today = Workload.result (Workload.open_today session) in @@ -215,6 +256,6 @@ let check db = let () = let db = Workload.fixture () in match Array.to_list Sys.argv with - | [_] -> check db; check_notification_demand db; check_rtc_and_tasks db + | [_] -> check db; check_notification_demand db; check_rtc_and_tasks db; check_all_task_edits db | [_; "--bench"; count] when int_of_string count > 0 -> benchmark db (int_of_string count) | _ -> failwith "usage: outliner_perf [--bench ITERATIONS]" diff --git a/shared/bench/outliner_workload.ml b/shared/bench/outliner_workload.ml index cfd9f022..27b881e4 100644 --- a/shared/bench/outliner_workload.ml +++ b/shared/bench/outliner_workload.ml @@ -82,7 +82,7 @@ let result raw = if member "ok" response <> `Bool true then failwith raw; member "result" response -let with_session ?show_journal_tasks ?show_notifications db f = +let with_session ?show_journal_tasks ?all_tasks_request ?show_notifications db f = let path = Filename.temp_file "outliner-workload" ".sqlite" in let checkpoint_path = path ^ ".checkpoint" in let host = Mobile_session.create (fun _ -> failwith "Unexpected crypto call in the plaintext fixture") in @@ -103,6 +103,7 @@ let with_session ?show_journal_tasks ?show_notifications db f = let session = Session.create_session ~journal_tasks {Session.default_options with outliner_projection_limit = options.outliner_projection_limit; show_journal_tasks = options.show_journal_tasks; + all_tasks_request; show_notifications; load_graph_catalog = Some (fun () -> Some {|{"graphs":[{"graph-id":"outliner-perf","graph-name":"Outliner benchmark","graph-e2ee?":false,"graph-ready-for-use?":true}]}|}); sync_cursor = options.sync_cursor; diff --git a/shared/src/logseq/core/journal_task_dates.ml b/shared/src/logseq/core/journal_task_dates.ml index 7a246eff..23615312 100644 --- a/shared/src/logseq/core/journal_task_dates.ml +++ b/shared/src/logseq/core/journal_task_dates.ml @@ -2,6 +2,7 @@ module Ds = Datascript module Read = Graph_read module Json = Yojson.Basic module Uuids = Set.Make (String) +module Task_rows = Map.Make (String) let scheduled = Task_recurrence.scheduled let deadline = Task_recurrence.deadline @@ -261,13 +262,20 @@ let rows ?actor ?on_comment_reference ?eids ~lookback ~include_all db today look else `Null in `List today, `List upcoming, all +type all_request = All_hidden | All_visible of int option + +type all_projection = { + revision : int; + rows_by_uuid : Json.t Task_rows.t; + delta : (int * Json.t) option; +} + type cached_projection = { day : int; timezone : string; actor : string option; lookback : lookback; - include_all : bool; - all_uuids : Uuids.t; + all : all_projection option; db : Ds.db Weak.t; result : Json.t; comment_references : Uuids.t; @@ -279,12 +287,65 @@ let create_cache () : cache = ref [] let remove_cached_graph cache graph = cache := List.remove_assoc graph !cache let clear_cache cache = cache := [] -let task_uuids = function - | `List rows -> List.filter_map (fun row -> match task_field "uuid" row with - | `String uuid -> Some uuid | _ -> None) rows |> Uuids.of_list - | _ -> Uuids.empty +let next_revision = Atomic.make 1 +let new_revision () = Atomic.fetch_and_add next_revision 1 +let row_uuid row = task_field "uuid" row +let rows_by_uuid = function + | `List rows -> List.fold_left (fun indexed row -> match row_uuid row with + | `String uuid -> Task_rows.add uuid row indexed + | _ -> indexed) Task_rows.empty rows + | _ -> Task_rows.empty + +let replace_rows uuids previous updated = + match previous, updated with + | `List previous, `List updated -> + let previous = List.filter (fun row -> match row_uuid row with + | `String uuid -> not (Uuids.mem uuid uuids) | _ -> true) previous in + `List (List.merge (fun left right -> compare (row_uuid left) (row_uuid right)) previous updated) + | _ -> updated + +let full_projection_fields projection = + let fields = Json.Util.to_assoc projection.result in + let all = match projection.all with + | None -> `Null + | Some all -> `List (Task_rows.bindings all.rows_by_uuid |> List.map snd) in + fields @ ["all", all] + +let projection_payload request projection = + match request, projection.all with + | All_visible (Some known), Some all when known = all.revision -> `Null + | All_visible known, Some all -> + let revision = "allRevision", `Int all.revision in + (match all.delta with + | Some (base, delta) when known = Some base -> + let metadata = Json.Util.to_assoc projection.result |> List.filter (fun (key, _) -> + key <> "today" && key <> "upcoming") in + `Assoc (revision :: ("allDelta", delta) :: metadata) + | _ -> `Assoc (revision :: full_projection_fields projection)) + | _ -> `Assoc (full_projection_fields projection) -let project ?read_rows ?actor ?(lookback = OneWeek) ?(include_all = false) cache ~graph ~now ~force db = +let projection_revision agenda = + match task_field "allRevision" agenda with `Int id -> Some id | _ -> None + +let delta_base agenda = + match task_field "from" (task_field "allDelta" agenda) with `Int id -> Some id | _ -> None + +let apply_delta previous incoming = + let previous_revision = projection_revision previous in + match delta_base incoming, projection_revision incoming with + | _, Some revision when Option.exists (fun known -> known > revision) previous_revision -> previous + | None, _ -> incoming + | Some base, _ when previous_revision = Some base -> + let delta = task_field "allDelta" incoming in + let uuids = match task_field "uuids" delta with + | `List ids -> List.filter_map (function `String uuid -> Some uuid | _ -> None) ids |> Uuids.of_list + | _ -> Uuids.empty in + let merged section = section, replace_rows uuids (task_field section previous) (task_field section delta) in + `Assoc (List.filter (fun (key, _) -> key <> "allDelta") (Json.Util.to_assoc incoming) + @ List.map merged ["today"; "upcoming"; "all"]) + | Some _, _ -> previous + +let read_projection ?read_rows ?actor ?(lookback = OneWeek) ~include_all cache ~graph ~now ~force db = let comment_references = ref Uuids.empty in let on_comment_reference uuid = comment_references := Uuids.add uuid !comment_references in let read_rows = Option.value ~default:(fun db day days -> @@ -299,30 +360,43 @@ let project ?read_rows ?actor ?(lookback = OneWeek) ?(include_all = false) cache let remaining = List.remove_assoc graph !cache in (* Keep up to four recently viewed graphs. *) cache := (graph, value) :: List.filteri (fun index _ -> index < 3) remaining; - value.result in + value in match previous with - | Some value when not force && value.include_all = include_all + | Some value when not force && Option.is_some value.all = include_all && Option.exists ((==) db) (Weak.get value.db 0) -> remember value | _ -> let range = "lookback", `String (lookback_to_string lookback) in - let result = + let result, all_rows = try let disabled, days = configuration db in let today, upcoming, all = read_rows db day (if disabled then None else Some days) in `Assoc ["graphId", `String graph; "day", `Int day; "error", `Bool false; "success", `Bool true; - "retained", `Bool false; range; "today", today; "upcoming", upcoming; "all", all] + "retained", `Bool false; range; "today", today; "upcoming", upcoming], rows_by_uuid all with error -> prerr_endline ("journal task query: " ^ Printexc.to_string error); let prior name = match previous with Some value -> member name value.result | None -> `List [] in `Assoc ["graphId", `String graph; "day", `Int day; "error", `Bool true; "retained", `Bool (Option.exists (fun value -> member "success" value.result = `Bool true || member "retained" value.result = `Bool true) previous); - range; "today", prior "today"; "upcoming", prior "upcoming"; - "all", (if include_all then prior "all" else `Null)] in + range; "today", prior "today"; "upcoming", prior "upcoming"], + (match Option.bind previous (fun projection -> projection.all) with + | Some all -> all.rows_by_uuid + | None -> Task_rows.empty) in + let all = if include_all then Some {revision = new_revision (); rows_by_uuid = all_rows; delta = None} + else None in let source = Weak.create 1 in Weak.set source 0 (Some db); - remember {day; timezone; actor; lookback; include_all; db = source; result; - all_uuids = task_uuids (member "all" result); comment_references = !comment_references} + remember {day; timezone; actor; lookback; db = source; result; all; + comment_references = !comment_references} + +let project ?read_rows ?actor ?lookback ?(include_all = false) cache ~graph ~now ~force db = + `Assoc (full_projection_fields (read_projection ?read_rows ?actor ?lookback ~include_all cache ~graph ~now ~force db)) + +let projection_task_is_visible projection ~section ~disclosed_groups ~group_by_page ~show_completed ~show_past uuid = + let agenda = if section <> "all" then projection.result else + let row = Option.bind projection.all (fun all -> Task_rows.find_opt uuid all.rows_by_uuid) in + `Assoc ["all", `List (Option.to_list row)] in + task_is_visible agenda ~section ~disclosed_groups ~group_by_page ~show_completed ~show_past uuid let refreshable_attr = function | "block/title" | "block/updated-at" | "block/tx-id" @@ -362,34 +436,34 @@ let refresh_blocks cache ~before ~after eids = conservative entries until the next full projection. *) let comment_references = ref cached.comment_references in let on_comment_reference uuid = comment_references := Uuids.add uuid !comment_references in - let result, all_uuids = if eids = [] then cached.result, cached.all_uuids else + let result, all = if eids = [] then cached.result, cached.all else let disabled, days = configuration after in let uuids = List.filter_map (Read.uuid_for_eid after) eids |> Uuids.of_list in let today, upcoming, all = rows ?actor:cached.actor ~on_comment_reference ~eids - ~lookback:cached.lookback ~include_all:cached.include_all + ~lookback:cached.lookback ~include_all:(Option.is_some cached.all) after cached.day (if disabled then None else Some days) in - let uuid row = task_field "uuid" row in - let compare_rows left right = compare (uuid left) (uuid right) in - let replace old updated = match old, updated with - | `List old, `List updated -> - let old = List.filter (fun row -> match uuid row with - | `String id -> not (Uuids.mem id uuids) | _ -> true) old in - `List (List.merge compare_rows old updated) - | _ -> updated in - let updated_all = task_uuids all in - (* A change to a non-task never needs to walk the All list. *) - let all_changed = not (Uuids.is_empty updated_all) - || Uuids.exists (fun id -> Uuids.mem id cached.all_uuids) uuids in - let all_uuids = if all_changed then Uuids.union (Uuids.diff cached.all_uuids uuids) updated_all - else cached.all_uuids in - `Assoc (List.map (function + let replace = replace_rows uuids in + let result = `Assoc (List.map (function | "today", old -> "today", replace old today | "upcoming", old -> "upcoming", replace old upcoming - | "all", old when all_changed -> "all", replace old all - | field -> field) fields), all_uuids in + | field -> field) fields) in + let all_projection = Option.map (fun previous -> + let updated = rows_by_uuid all in + let rows_by_uuid = Uuids.fold (fun uuid rows -> + Task_rows.update uuid (fun _ -> Task_rows.find_opt uuid updated) rows) uuids previous.rows_by_uuid in + let unchanged = Uuids.for_all (fun uuid -> + Task_rows.find_opt uuid rows_by_uuid = Task_rows.find_opt uuid previous.rows_by_uuid) uuids in + if unchanged && result = cached.result then previous + else + let revision = new_revision () in + let delta = `Assoc ["from", `Int previous.revision; + "uuids", `List (List.map (fun uuid -> `String uuid) (Uuids.elements uuids)); + "today", today; "upcoming", upcoming; "all", all] in + {revision; rows_by_uuid; delta = Some (previous.revision, delta)}) cached.all in + result, all_projection in let source = Weak.create 1 in Weak.set source 0 (Some after); - {cached with db = source; result; all_uuids; comment_references = !comment_references} + {cached with db = source; result; all; comment_references = !comment_references} | _ -> cached in (* An unreadable row can be handled by the normal full query and its retained-result fallback. The edit is already staged. *) diff --git a/shared/src/logseq/core/mobile_session.ml b/shared/src/logseq/core/mobile_session.ml index c1096b5f..87550b4f 100644 --- a/shared/src/logseq/core/mobile_session.ml +++ b/shared/src/logseq/core/mobile_session.ml @@ -146,12 +146,12 @@ let host_options ?journal_tasks ?show_journal_tasks (database : Database.mobile_ Some (fun day -> Graph.journal_page_uuid graph day); } -let create_rpc_session ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications database ring catalog = +let create_rpc_session ?show_journal_tasks ?all_tasks_request ?task_lookback ?show_notifications database ring catalog = let journal_tasks = Journal_task_dates.create_cache () in let options = host_options ~journal_tasks ?show_journal_tasks database ring catalog in - Rpc.create_session ~journal_tasks {options with show_all_tasks; task_lookback; show_notifications} + Rpc.create_session ~journal_tasks {options with all_tasks_request; task_lookback; show_notifications} -let create ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications crypto_call = +let create ?show_journal_tasks ?all_tasks_request ?task_lookback ?show_notifications crypto_call = let ring = Platform.create_keyring crypto_call Http.send in let graph = Graph.create @@ -166,7 +166,7 @@ let create ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notification } in let database = Database.create graph in - let session = create_rpc_session ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications database ring None in + let session = create_rpc_session ?show_journal_tasks ?all_tasks_request ?task_lookback ?show_notifications database ring None in session.Types.state := { !(session.Types.state) with Types.sidebar_deferred = true }; { database; keyring = ring; session = ref session } @@ -238,7 +238,7 @@ let call (host : mobile_session) request = let catalog = Database.open_catalog host.database path in let options = Types.host !(host.session) in let session = create_rpc_session ?show_journal_tasks:options.show_journal_tasks - ?show_all_tasks:options.show_all_tasks ?task_lookback:options.task_lookback + ?all_tasks_request:options.all_tasks_request ?task_lookback:options.task_lookback ?show_notifications:options.show_notifications host.database host.keyring (Some catalog) in session.Types.state := { !(session.Types.state) with Types.sidebar_deferred = true }; @@ -254,7 +254,7 @@ let call (host : mobile_session) request = | _ -> Rpc.dispatch session action payload) request -let start ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications crypto_call = - let host = create ?show_journal_tasks ?show_all_tasks ?task_lookback ?show_notifications crypto_call in +let start ?show_journal_tasks ?all_tasks_request ?task_lookback ?show_notifications crypto_call = + let host = create ?show_journal_tasks ?all_tasks_request ?task_lookback ?show_notifications crypto_call in Callback.register "logseq_mobile_call" (fun request -> call host request); host diff --git a/shared/src/logseq/core/mobile_session.mli b/shared/src/logseq/core/mobile_session.mli index ea702aff..4359c78f 100644 --- a/shared/src/logseq/core/mobile_session.mli +++ b/shared/src/logseq/core/mobile_session.mli @@ -19,7 +19,7 @@ val host_options : Session_types.host_options val create : ?show_journal_tasks:(unit -> bool) -> - ?show_all_tasks:(unit -> bool) -> + ?all_tasks_request:(unit -> Journal_task_dates.all_request) -> ?task_lookback:(unit -> Journal_task_dates.lookback) -> ?show_notifications:(unit -> bool) -> (string -> string) -> @@ -27,7 +27,7 @@ val create : val call : mobile_session -> string -> string val start : ?show_journal_tasks:(unit -> bool) -> - ?show_all_tasks:(unit -> bool) -> + ?all_tasks_request:(unit -> Journal_task_dates.all_request) -> ?task_lookback:(unit -> Journal_task_dates.lookback) -> ?show_notifications:(unit -> bool) -> (string -> string) -> diff --git a/shared/src/logseq/core/rpc_session.ml b/shared/src/logseq/core/rpc_session.ml index f8502ea7..e23fa86f 100644 --- a/shared/src/logseq/core/rpc_session.ml +++ b/shared/src/logseq/core/rpc_session.ml @@ -118,18 +118,24 @@ let collaboration_identity session = let tasks_visible session = Option.exists (fun show -> show ()) (host session).Types.show_journal_tasks -let journal_tasks_json ?(force = false) session = +let journal_tasks_projection ?(force = false) session = match (state session).config with | Some {graph_id; _} when graph_id <> "" -> - (match active_graph_db session graph_id with - | Some db -> - let cache = session.Types.journal_tasks in - let actor = Option.map snd (collaboration_identity session) in - let lookback = Option.map (fun read -> read ()) (host session).Types.task_lookback in - let include_all = Option.exists (fun read -> read ()) (host session).Types.show_all_tasks in - Journal_task_dates.project ?actor ?lookback ~include_all cache ~graph:graph_id ~now:(now_ms ()) ~force db - | None -> `Null) - | _ -> `Null + Option.map (fun db -> + let actor = Option.map snd (collaboration_identity session) in + let lookback = Option.map (fun read -> read ()) (host session).Types.task_lookback in + let request = Option.fold ~none:Journal_task_dates.All_hidden ~some:(fun read -> read ()) + (host session).Types.all_tasks_request in + let include_all = match request with Journal_task_dates.All_hidden -> false | All_visible _ -> true in + let projection = Journal_task_dates.read_projection ?actor ?lookback ~include_all + session.Types.journal_tasks ~graph:graph_id ~now:(now_ms ()) ~force db in + request, projection) (active_graph_db session graph_id) + | _ -> None + +let journal_tasks_json session = + match journal_tasks_projection session with + | Some (request, projection) -> Journal_task_dates.projection_payload request projection + | None -> `Null let current_summary db (summary : Model.entity_summary) = Option.value ~default:summary (Option.bind db (fun db -> @@ -2825,7 +2831,7 @@ let rec dispatch session action payload = else if Json.Util.member "action" input = `String "refreshJournalTasks" then ( let day = `Int (Model.journal_day_for_ms (now_ms ())) in if Json.Util.member "day" input = day then - ignore (journal_tasks_json ~force:true session); + ignore (journal_tasks_projection ~force:true session); snapshot_visible session) else if Json.Util.member "action" input = `String "saveTaskDates" then ( match editing_cursor session with @@ -2856,10 +2862,11 @@ let rec dispatch session action payload = let visible = match Json.Util.member "section" view with | `String ("today" | "upcoming" | "all" as section) -> - Journal_task_dates.task_is_visible (journal_tasks_json session) ~section - ~disclosed_groups:(List.filter_map (function `String key -> Some key | _ -> None) groups) - ~group_by_page:(boolean "groupByPage") ~show_completed:(boolean "showCompleted") - ~show_past:(boolean "showPast") uuid + Option.exists (fun (_, projection) -> + Journal_task_dates.projection_task_is_visible projection ~section + ~disclosed_groups:(List.filter_map (function `String key -> Some key | _ -> None) groups) + ~group_by_page:(boolean "groupByPage") ~show_completed:(boolean "showCompleted") + ~show_past:(boolean "showPast") uuid) (journal_tasks_projection session) | _ -> false in if not visible then session.state := {current with outliner_state = {current.outliner_state with editing = None; autocomplete = None}} diff --git a/shared/src/logseq/core/session_types.ml b/shared/src/logseq/core/session_types.ml index 6e12fe06..c12b042c 100644 --- a/shared/src/logseq/core/session_types.ml +++ b/shared/src/logseq/core/session_types.ml @@ -81,7 +81,7 @@ type host_options = ; storage : Datascript.storage option ; outliner_projection_limit : int option ; show_journal_tasks : (unit -> bool) option - ; show_all_tasks : (unit -> bool) option + ; all_tasks_request : (unit -> Journal_task_dates.all_request) option ; task_lookback : (unit -> Journal_task_dates.lookback) option ; show_notifications : (unit -> bool) option ; open_graph : (string -> (unit, string) result) option @@ -204,7 +204,7 @@ let default_options = storage = None; outliner_projection_limit = None; show_journal_tasks = None; - show_all_tasks = None; + all_tasks_request = None; task_lookback = None; show_notifications = None; open_graph = None; diff --git a/shared/src/logseq/core/session_types.mli b/shared/src/logseq/core/session_types.mli index 0a9fd9c3..1a73bd64 100644 --- a/shared/src/logseq/core/session_types.mli +++ b/shared/src/logseq/core/session_types.mli @@ -74,7 +74,7 @@ type host_options = ; storage : Datascript.storage option ; outliner_projection_limit : int option ; show_journal_tasks : (unit -> bool) option - ; show_all_tasks : (unit -> bool) option + ; all_tasks_request : (unit -> Journal_task_dates.all_request) option ; task_lookback : (unit -> Journal_task_dates.lookback) option ; show_notifications : (unit -> bool) option ; open_graph : (string -> (unit, string) result) option diff --git a/shared/src/logseq/entry/logseq_mobile_entry.ml b/shared/src/logseq/entry/logseq_mobile_entry.ml index ee5fee6b..bc9a8b7e 100644 --- a/shared/src/logseq/entry/logseq_mobile_entry.ml +++ b/shared/src/logseq/entry/logseq_mobile_entry.ml @@ -2,7 +2,7 @@ let () = if not (Native_bridge.linked ()) then failwith "OCaml/LUI native bridge failed to link"; let host = Mobile_session.start ~show_journal_tasks:Native_bridge.show_journal_tasks - ~show_all_tasks:Native_bridge.show_all_tasks ~task_lookback:Native_bridge.task_lookback + ~all_tasks_request:Native_bridge.all_tasks_request ~task_lookback:Native_bridge.task_lookback ~show_notifications:Native_bridge.show_notifications Native_crypto.call_raw in Native_bridge.set_search_index_source (fun () -> Mobile_graph.pending_search_index host.database.graph) diff --git a/shared/src/logseq/model.ml b/shared/src/logseq/model.ml index 79d3e4df..e937de8d 100644 --- a/shared/src/logseq/model.ml +++ b/shared/src/logseq/model.ml @@ -1201,6 +1201,12 @@ let tasks_selection_active current = && (current.tasks_selection_mode || current.outliner_selected_block_ids <> [] || List.exists selecting current.pending_effects || List.exists selecting current.in_flight_effects) +let task_group_toggle_allowed current group = + not (tasks_selection_active current) + || (current.tasks_view.tab = TasksAll + && String.starts_with ~prefix:(Journal_task_dates.task_group_key "all" "") group + && not (List.mem group (journal_task_disclosed_groups current))) + let graph_refresh_active_ current = graph_effect_active_ current "refresh" let graph_create_active_ current = graph_effect_active_ current "create" let graph_unlock_active_ current = graph_effect_active_ current "unlock" @@ -2419,7 +2425,7 @@ let rec update (current : logseq_model) action = | _ -> None in if field = "scheduled" || field = "deadline" then open_task_date_editor current [uuid] editing field else current - | ToggleJournalTaskSection _ when tasks_selection_active current -> current + | ToggleJournalTaskSection group when not (task_group_toggle_allowed current group) -> current | ToggleJournalTaskSection section -> let groups = journal_task_disclosed_groups current in let updated = set_journal_task_disclosed_groups current @@ -2523,6 +2529,22 @@ let rec update (current : logseq_model) action = let applied = if projection.is_pdf_patch || projection.is_collaboration_patch then current else apply_core_snapshot current projection in let graph_changed = applied.selected_graph_id <> current.selected_graph_id in + let applied = + match applied.destination, applied.tasks_view.tab, applied.selected_graph_id, + Journal_task_dates.delta_base projection.journal_tasks, + Journal_task_dates.projection_revision projection.journal_tasks with + | TasksDestination, TasksAll, Some graph, Some _, Some incoming + when not graph_changed && journal_task_field "graphId" projection.journal_tasks = `String graph + && Option.fold ~none:true ~some:(fun revision -> revision < incoming) + (Journal_task_dates.projection_revision applied.journal_tasks) -> + let key = "journal-tasks.refresh" in + let scheduled = List.exists (function NodePropertyEffect (_, name, _) -> name = key | _ -> false) + applied.pending_effects in + if scheduled then applied else + let request = `Assoc ["action", `String "refreshJournalTasks"; "graphId", `String graph; + "day", journal_task_field "day" projection.journal_tasks] in + update applied (SubmitNodeProperty (key, Yojson.Basic.to_string request)) + | _ -> applied in let applied = let lookback model = journal_task_field "lookback" model.journal_tasks in if not graph_changed && lookback applied <> lookback current @@ -3831,7 +3853,8 @@ and apply_core_snapshot (current : logseq_model) | `Assoc fields as tasks when (match List.assoc_opt "graphId" fields with | Some (`String graph) -> graph_id = Some graph - | _ -> true) -> tasks + | _ -> true) -> + Journal_task_dates.apply_delta (if same_graph then current.journal_tasks else `Null) tasks | _ when same_graph -> current.journal_tasks | _ -> `Null in if Option.is_some projection.reference_candidates_update then diff --git a/shared/src/logseq/model.mli b/shared/src/logseq/model.mli index abf3e6f9..e2dc8ea3 100644 --- a/shared/src/logseq/model.mli +++ b/shared/src/logseq/model.mli @@ -822,6 +822,7 @@ val string_vector_contains_ : string list -> string -> bool val graph_local_ : logseq_model -> string -> bool val remove_string : string list -> string -> string list val journal_task_disclosed_groups : logseq_model -> string list +val task_group_toggle_allowed : logseq_model -> string -> bool val journal_task_retry_available_ : logseq_model -> bool val outliner_task_selection_ : logseq_model -> bool val bounded_url_delimiter : int -> int -> int diff --git a/shared/src/logseq/native_bridge.ml b/shared/src/logseq/native_bridge.ml index f6e8140a..51cedb6f 100644 --- a/shared/src/logseq/native_bridge.ml +++ b/shared/src/logseq/native_bridge.ml @@ -41,9 +41,13 @@ let show_journal_tasks () = let current = App.model app in View_base.tasks_destination_ current && View_base.node_navigation_inactive_ current) !current_app -let show_all_tasks () = - show_journal_tasks () - && (App.model (app ())).Model.tasks_view.tab = Model.TasksAll +let all_tasks_request () = + if show_journal_tasks () then + let current = App.model (app ()) in + if current.Model.tasks_view.tab = Model.TasksAll then + Journal_task_dates.All_visible (Journal_task_dates.projection_revision current.journal_tasks) + else Journal_task_dates.All_hidden + else Journal_task_dates.All_hidden let show_notifications () = Option.exists (fun app -> diff --git a/shared/src/logseq/native_bridge.mli b/shared/src/logseq/native_bridge.mli index c72cba76..53ae0b1c 100644 --- a/shared/src/logseq/native_bridge.mli +++ b/shared/src/logseq/native_bridge.mli @@ -6,7 +6,7 @@ val app : unit -> (Model.logseq_model, Model.logseq_action) Lui_app.reducer_app val show_journal_tasks : unit -> bool -val show_all_tasks : unit -> bool +val all_tasks_request : unit -> Journal_task_dates.all_request val task_lookback : unit -> Journal_task_dates.lookback val show_notifications : unit -> bool diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index 587c964a..c864cdf6 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -2078,8 +2078,9 @@ let task_heading ~page context model_source send group (label, count) = let disabled = Signal.map View_base.outliner_selection_active_ model_source in box ~padding_horizontal:16 ~margin_top:12 (match count with | Some count -> + let disclosure_disabled = Signal.map (fun model -> not (Model.task_group_toggle_allowed model group)) model_source in [button ~variant:`ghost ~padding_horizontal:0 ~min_height:44 ~text:"" ~label - ~disabled_signal:disabled ~accessibility_identifier:group ~on_press:(fun _ -> toggle ()) [ + ~disabled_signal:disclosure_disabled ~accessibility_identifier:group ~on_press:(fun _ -> toggle ()) [ row ~grow:1.0 ~gap:8 ~cross:`center [ box ~grow:1.0 [title]; text ~value:(string_of_int count) ~style_class:"footnote" ~foreground:"muted-foreground" []; diff --git a/shared/test/logseq/app_test.ml b/shared/test/logseq/app_test.ml index 34f35ab5..463bcb91 100644 --- a/shared/test/logseq/app_test.ml +++ b/shared/test/logseq/app_test.ml @@ -7663,6 +7663,29 @@ let journal_agenda_is_retained_across_navigation () = check (all_task () <> -1); tap root all_group; check_eq (all_task ()) (-1); + let group_enabled () = property renderer (find root all_group) Lui_protocol.Enabled <> Some (Lui_protocol.BoolValue false) in + tap root "tasks.menu.select"; + check (App.model app).tasks_selection_mode; + check (group_enabled ()); + tap root all_group; + check (all_task () <> -1); + check (not (group_enabled ())); + let task_row = descendant_with_extension renderer app (all_task ()) "outliner-block-row" in + check (task_row <> -1); + dispatch app (Lui_protocol.ExtensionEvent (task_row, "outliner-block-row", "toggle-selection", + Lui_protocol.String_map.singleton "uuid" (Lui_protocol.StringValue "work-all-only"))); + flush app; + check (List.exists (function Model.EditorOutlinerEventEffect (_, payload) -> + Yojson.Basic.Util.member "type" (Yojson.Basic.from_string payload) = `String "toggleBlockSelection" + | _ -> false) (App.model app).pending_effects); + let selection = (App.model app).pending_effects |> List.find_map (function + | Model.EditorOutlinerEventEffect (id, _) -> Some id | _ -> None) in + let id = Option.get selection in + apply (Model.DequeueEffect id); + apply (Model.ResolveEffect (id, true, "")); + apply (Model.PerformOutlinerToolbarAction "unselect"); + tap root all_group; + check_eq (all_task ()) (-1); tap root "tasks.tab.today"; check_eq (chip_text "today") (Some (Lui_protocol.StringValue "Today")); check_eq (all_task ()) (-1); diff --git a/shared/test/logseq/editor_command_test.ml b/shared/test/logseq/editor_command_test.ml index f4dec6fc..7e61c76d 100644 --- a/shared/test/logseq/editor_command_test.ml +++ b/shared/test/logseq/editor_command_test.ml @@ -1611,6 +1611,12 @@ let all_tasks_include_undated_and_out_of_range_blocks () = R.with_runtime (fun _ check_eq (ids "all" all) (List.sort compare [`String Q.alpha; `String Q.beta; `String Q.definition; `String Q.owner]); List.iter (fun section -> check_eq (ids section all) (ids section agenda)) ["today"; "upcoming"]; + let payload known = Journal_task_dates.projection_payload (Journal_task_dates.All_visible known) + (Journal_task_dates.read_projection ~include_all:true cache ~graph:"tasks" + ~now:(Int64.to_int (local 20261123)) ~force:false (Graph_runtime.db runtime)) in + let full = payload None in + let revision = Journal_task_dates.projection_revision full in + check_eq (payload revision) `Null; let before = Graph_runtime.db runtime in rebase runtime conn [ Ds.Retract (Q.ref_uuid Q.beta, Journal_task_dates.scheduled, None); @@ -1623,6 +1629,15 @@ let all_tasks_include_undated_and_out_of_range_blocks () = R.with_runtime (fun _ check_eq (member "error" refreshed) (`Bool false); check_eq (ids "all" refreshed) (List.sort compare [`String Q.alpha; `String Q.definition; `String Q.owner; `String R.gamma]); + let delta = payload revision in + check_eq (Journal_task_dates.delta_base delta) revision; + check_eq (member "all" delta) `Null; + let merged = Journal_task_dates.apply_delta full delta in + List.iter (fun section -> check_eq (member section merged) (member section refreshed)) + ["today"; "upcoming"; "all"]; + check_eq (Journal_task_dates.apply_delta merged delta) merged; + check_eq (Journal_task_dates.apply_delta merged full) merged; + check_eq (member "all" (payload (Some 0))) (member "all" merged); let failed = project ~include_all:true ~force:true ~read_rows:(fun _ _ _ -> failwith "query failed") () in check_eq (ids "all" failed) (ids "all" refreshed); check_eq (member "all" (project ~include_all:false ())) `Null) From 66e1bfdb4ad14e1ab266423693487e9bc9beaa06 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 13:16:06 +0800 Subject: [PATCH 3/7] Animate task filters and add selection haptics --- .../logseq/ui/extensions/LogseqExtensions.kt | 1 + .../logseq/ui/extensions/TaskFilterStrip.kt | 58 ++++++++++ .../Sources/Logseq/LGPropertyExtension.swift | 26 +++++ shared/src/logseq/view.ml | 7 ++ shared/src/logseq/view_outliner.ml | 107 ++++++++++-------- shared/test/logseq/app_test.ml | 4 +- 6 files changed, 156 insertions(+), 47 deletions(-) create mode 100644 android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt diff --git a/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/LogseqExtensions.kt b/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/LogseqExtensions.kt index 54cab9b2..d906266d 100644 --- a/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/LogseqExtensions.kt +++ b/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/LogseqExtensions.kt @@ -110,6 +110,7 @@ fun logseqExtensionRegistry( val youtubeStarts = androidx.compose.runtime.mutableStateMapOf() registerNodeIcon() registerProperties() + registerTaskFilterStrip() registerTaskDateSheet() registerReactionSearchInput() registerFilterSearchField() diff --git a/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt b/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt new file mode 100644 index 00000000..f4b6e6d2 --- /dev/null +++ b/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt @@ -0,0 +1,58 @@ +package com.logseq.logseq.ui.extensions + +import androidx.compose.animation.animateContentSize +import androidx.compose.animation.core.CubicBezierEasing +import androidx.compose.animation.core.tween +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.key +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.unit.dp +import androidx.core.view.HapticFeedbackConstantsCompat +import androidx.core.view.ViewCompat +import dev.lui.LuiExtensionContext +import dev.lui.LuiExtensionProperty +import dev.lui.LuiExtensionRegistry +import dev.lui.LuiExtensionValueKind + +internal fun LuiExtensionRegistry.registerTaskFilterStrip() { + register( + "task-filter-strip", + "lui-extension-v1|17:task-filter-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:string:required:none|events:", + acceptsStandardChildren = true, + properties = listOf(LuiExtensionProperty("selected", LuiExtensionValueKind.STRING, required = true)), + ) { TaskFilterStrip(this) } +} + +private val filterEasing = CubicBezierEasing(0.23f, 1f, 0.32f, 1f) + +@Composable +private fun TaskFilterStrip(context: LuiExtensionContext) { + val selected = context.string("selected") + val view = LocalView.current + var previous by remember { mutableStateOf(selected) } + LaunchedEffect(selected) { + if (selected != previous) { + ViewCompat.performHapticFeedback(view, HapticFeedbackConstantsCompat.SEGMENT_TICK) + previous = selected + } + } + Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { + for (child in context.children) { + key(child) { + Box(Modifier.animateContentSize(animationSpec = tween(200, easing = filterEasing))) { + context.child(child) + } + } + } + } +} diff --git a/apple/Sources/Logseq/LGPropertyExtension.swift b/apple/Sources/Logseq/LGPropertyExtension.swift index 74e8c0a7..a63add0e 100644 --- a/apple/Sources/Logseq/LGPropertyExtension.swift +++ b/apple/Sources/Logseq/LGPropertyExtension.swift @@ -67,6 +67,12 @@ enum LGPropertyExtension { acceptsStandardChildren: true, properties: [.init(name: "collapsed", kind: .string, isRequired: true)] ) { AnyView(LGJournalTaskTransition(context: $0)) }) + try registry.register(LUIAppleExtension( + identifier: "task-filter-strip", + fingerprint: "lui-extension-v1|17:task-filter-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:string:required:none|events:", + acceptsStandardChildren: true, + properties: [.init(name: "selected", kind: .string, isRequired: true)] + ) { AnyView(LGTaskFilterStrip(context: $0)) }) try registry.register(LUIAppleExtension( identifier: "outliner-bottom-spacer", fingerprint: "lui-extension-v1|22:outliner-bottom-spacer|profiles:ios/swiftui|standard-children:0|children:|properties:6:height:int:required:none|events:", @@ -117,6 +123,26 @@ private struct LGJournalTaskTransition: View { } } +private struct LGTaskFilterStrip: View { + let context: LUIAppleExtensionViewContext + @Environment(\.accessibilityReduceMotion) private var reduceMotion + @Environment(\.dynamicTypeSize) private var dynamicTypeSize + + var body: some View { + let _ = context.revision + let selected = context.property("selected") + HStack(spacing: 8) { + ForEach(context.childIDs, id: \.self) { id in + context.content(for: id) + .fixedSize(horizontal: !dynamicTypeSize.isAccessibilitySize, vertical: false) + } + } + .animation(reduceMotion ? nil : journalDisclosureAnimation, value: selected) + .sensoryFeedback(.selection, trigger: selected) + .frame(maxWidth: .infinity, alignment: .leading) + } +} + private struct LGOutlinerBottomSpacer: View { let height: CGFloat @Environment(\.outlinerScrollRetention) private var scrollRetention diff --git a/shared/src/logseq/view.ml b/shared/src/logseq/view.ml index 10a4cd6b..ba77939d 100644 --- a/shared/src/logseq/view.ml +++ b/shared/src/logseq/view.ml @@ -361,6 +361,12 @@ let journal_task_transition_schema () = component "journal-task-transition" [profile IOS SwiftUIHost] true [] [property "collapsed" StringScalar true None] [] +let task_filter_strip_schema () = + let open Lui_protocol in + let open Lui_extension in + component "task-filter-strip" [profile IOS SwiftUIHost; profile AndroidOS KotlinHost] + true [] [property "selected" StringScalar true None] [] + let outliner_bottom_spacer_schema () = let open Lui_protocol in let open Lui_extension in @@ -444,6 +450,7 @@ let extension_registry () = Lui_extension.property "placeholder" Lui_extension.StringScalar true None] [Lui_extension.event "query-changed" [Lui_extension.event_field "query" Lui_extension.StringScalar true]]); Lui_extension.register_component registry (journal_task_transition_schema ()); + Lui_extension.register_component registry (task_filter_strip_schema ()); Lui_extension.register_component registry (outliner_bottom_spacer_schema ()); Lui_extension.register_component registry (journal_task_chevron_schema ()); Lui_extension.register_component registry (outliner_continuation_schema ()); diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index c864cdf6..71ee326b 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -2268,59 +2268,74 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par | Model.TasksToday -> "tasks-today" | Model.TasksUpcoming -> "calendar" | Model.TasksAll -> "toolbar-task" in - let tab_button active_tab value name = + let disabled = own (Signal.map View_base.outliner_selection_active_ model_source) in + let tab_button value name = let label = View_base.tr (Signal.sample model_source) name in - let selected = active_tab = value in - let background = if selected then "task-tab-selected-background" else "task-tab-background" in - let foreground = if selected then "link" else "foreground" in - let disabled = own (Signal.map View_base.outliner_selection_active_ model_source) in + let selected = own (Signal.map ((=) value) tab) in + let background = own (Signal.map (fun selected -> + if selected then "task-tab-selected-background" else "task-tab-background") selected) in + let foreground = own (Signal.map (fun selected -> if selected then "link" else "foreground") selected) in let identifier = "tasks.tab." ^ Model.tasks_view_section value in - let icon = `app (tab_icon value) in let on_press _ = update_tasks_view model_source send (fun options -> { options with tab = value }) in - box ~background ~corner_radius:22 [ - (if selected then - button ~text:label ~label ~icon ~variant:`ghost ~min_height:44 ~padding_horizontal:15 - ~corner_radius:22 ~selected ~disabled_signal:disabled ~foreground ~accessibility_identifier:identifier ~on_press [] - else - icon_button ~label ~icon ~variant:`ghost ~width:44 ~min_height:44 - ~corner_radius:22 ~selected ~disabled_signal:disabled ~foreground ~accessibility_identifier:identifier ~on_press []); + box ~background_signal:background ~corner_radius:22 [ + button ~text:"" ~label ~variant:`ghost + ~min_width:44 ~min_height:44 ~padding_horizontal:14 ~corner_radius:22 + ~selected_signal:selected ~disabled_signal:disabled ~foreground_signal:foreground + ~accessibility_identifier:identifier ~on_press [ + icon ~name:(`app (tab_icon value)) ~width:16 ~height:16 ~foreground_signal:foreground []; + if_ ~test:selected + (text ~value:label ~line_clamp:1 ~truncate:true ~foreground_signal:foreground + ?margin_left:(if Lui_ui.host mount_context = KotlinHost then None else Some 8) + ~accessibility_identifier:(identifier ^ ".label") []); + ]; ] in + let buttons = [tab_button Model.TasksToday "Today"; tab_button Model.TasksUpcoming "Upcoming"; + tab_button Model.TasksAll "All"] in + let filters = match Lui_ui.platform mount_context, Lui_ui.host mount_context with + | IOS, SwiftUIHost | AndroidOS, KotlinHost -> + custom (fun context parent -> + let node = Lui_ui.extension context "task-filter-strip" in + attach context parent node; + Lui_ui.extension_property_signal context node "selected" + (own (Signal.map (fun tab -> StringValue (Model.tasks_view_section tab)) tab)); + List.iter (fun button -> ignore (mount context ~parent:node button)) buttons; + node) + | _ -> row ~gap:8 ~cross:`center buttons in + let window = + keyed ~source:(own (Signal.map (fun tab -> [tab]) tab)) ~key:Fun.id ~cmp:compare + ~mount:(fun _ -> + View_rows.windowed_keyed ~identifier:"tasks.window" ~source:entries ~key:View_rows.page_entry_identifier ~cmp:compare + ~is_pinned:View_rows.page_entry_pinned_ + ~mount:(fun entry -> box [mount_journal_task_entry context model_source send entry]) ()) in + let list = with_journal_task_transition model_source + (virtual_list ~grow:1.0 ~gap:0 ~accessibility_identifier:"list.tasks" [ + column ~gap:12 ~padding_horizontal:16 ~padding_vertical:12 [ + heading ~value:(View_base.tr (Signal.sample model_source) "Tasks") + ~level:`h1 ~style_class:"semibold" ~accessibility_identifier:"tasks.title" []; + filters; + ]; + box ~height:16 []; + window; + outliner_bottom_spacer (); + ]) in + let title = View_base.tr (Signal.sample model_source) in + let empty_icon = own (Signal.map (fun tab -> `app (tab_icon tab)) tab) in + let empty_text = own (Signal.map (fun tab -> + title (if tab = Model.TasksUpcoming then "No upcoming tasks" else "No tasks to show")) tab) in mount mount_context ?parent (View_base.with_reading_insets (column ~grow:1.0 ~accessibility_identifier:"screen.tasks" [ - keyed ~source:(own (Signal.map2 (fun tab empty -> [tab, empty]) tab empty)) ~key:Fun.id ~cmp:compare - ~mount:(fun source -> - let active_tab, is_empty = Signal.sample source in - let list = with_journal_task_transition model_source - (virtual_list ~grow:1.0 ~gap:0 ~accessibility_identifier:"list.tasks" [ - column ~gap:12 ~padding_horizontal:16 ~padding_vertical:12 [ - heading ~value:(View_base.tr (Signal.sample model_source) "Tasks") - ~level:`h1 ~style_class:"semibold" ~accessibility_identifier:"tasks.title" []; - row ~gap:8 ~cross:`center [ - tab_button active_tab Model.TasksToday "Today"; - tab_button active_tab Model.TasksUpcoming "Upcoming"; - tab_button active_tab Model.TasksAll "All"; - ]; - ]; - box ~height:16 []; - View_rows.windowed_keyed ~identifier:"tasks.window" ~source:entries ~key:View_rows.page_entry_identifier ~cmp:compare - ~is_pinned:View_rows.page_entry_pinned_ - ~mount:(fun entry -> box [mount_journal_task_entry context model_source send entry]) (); - outliner_bottom_spacer (); - ]) in - if not is_empty then list - else overlay ~grow:1.0 ~alignment:`center [ - box ~grow:1.0 [list]; - if_ ~test:loading (spinner ~accessibility_identifier:"tasks.loading" []); - if_ ~test:(own (Signal.map not loading)) - (column ~gap:10 ~cross:`center ~padding_horizontal:16 [ - icon ~name:(`app (tab_icon active_tab)) ~width:25 ~height:25 ~foreground:"muted-foreground" - ~accessibility_identifier:"tasks.empty.icon" []; - text ~value:(View_base.tr (Signal.sample model_source) - (if active_tab = Model.TasksUpcoming then "No upcoming tasks" else "No tasks to show")) - ~text_alignment:`center ~foreground:"muted-foreground" - ~accessibility_identifier:"tasks.empty" []; - ]); + overlay ~grow:1.0 ~alignment:`center [ + box ~grow:1.0 [list]; + if_ ~test:(own (Signal.map2 ( && ) empty loading)) + (spinner ~accessibility_identifier:"tasks.loading" []); + if_ ~test:(own (Signal.map2 (fun empty loading -> empty && not loading) empty loading)) + (column ~gap:10 ~cross:`center ~padding_horizontal:16 [ + icon ~name_signal:empty_icon ~name:(`app (tab_icon Model.TasksToday)) + ~width:25 ~height:25 ~foreground:"muted-foreground" ~accessibility_identifier:"tasks.empty.icon" []; + text ~value_signal:empty_text ~text_alignment:`center ~foreground:"muted-foreground" + ~accessibility_identifier:"tasks.empty" []; ]); + ]; ])) let outliner_entries ?prefetch_history ?reset_key context model_source ~source send : t = diff --git a/shared/test/logseq/app_test.ml b/shared/test/logseq/app_test.ml index 463bcb91..c8449312 100644 --- a/shared/test/logseq/app_test.ml +++ b/shared/test/logseq/app_test.ml @@ -7636,10 +7636,12 @@ let journal_agenda_is_retained_across_navigation () = tap root "tasks.menu.compact"; check (App.model app).tasks_view.compact; tap root "tasks.menu.expanded"; + let all_chip = find root "tasks.tab.all" in tap root "tasks.tab.upcoming"; + check_eq (find root "tasks.tab.all") all_chip; check_eq (find root "tasks.menu.past") (-1); let chip_property section = property renderer (find root ("tasks.tab." ^ section)) in - let chip_text section = chip_property section Lui_protocol.TextValue in + let chip_text section = property renderer (find root ("tasks.tab." ^ section ^ ".label")) Lui_protocol.TextValue in check_eq (chip_text "upcoming") (Some (Lui_protocol.StringValue "Upcoming")); check_eq (chip_text "all") None; check_eq (chip_property "all" Lui_protocol.AccessibilityLabel) (Some (Lui_protocol.StringValue "All")); From 17dc18cbc58f3b4b9c9d3e98ef54f45edd798943 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 13:29:34 +0800 Subject: [PATCH 4/7] Widen task filters and coordinate label fades --- .../logseq/ui/extensions/TaskFilterStrip.kt | 61 +++++++++++++++-- .../Sources/Logseq/LGPropertyExtension.swift | 65 +++++++++++++++++++ shared/src/logseq/view.ml | 7 ++ shared/src/logseq/view_outliner.ml | 35 ++++++---- shared/test/logseq/app_test.ml | 12 ++-- 5 files changed, 154 insertions(+), 26 deletions(-) diff --git a/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt b/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt index f4b6e6d2..bc2e10d1 100644 --- a/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt +++ b/android/app/src/main/kotlin/com/logseq/logseq/ui/extensions/TaskFilterStrip.kt @@ -1,7 +1,7 @@ package com.logseq.logseq.ui.extensions -import androidx.compose.animation.animateContentSize import androidx.compose.animation.core.CubicBezierEasing +import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -15,7 +15,12 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clipToBounds +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.layout.Layout import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.semantics.clearAndSetSemantics +import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.dp import androidx.core.view.HapticFeedbackConstantsCompat import androidx.core.view.ViewCompat @@ -23,6 +28,7 @@ import dev.lui.LuiExtensionContext import dev.lui.LuiExtensionProperty import dev.lui.LuiExtensionRegistry import dev.lui.LuiExtensionValueKind +import kotlin.math.roundToInt internal fun LuiExtensionRegistry.registerTaskFilterStrip() { register( @@ -31,6 +37,12 @@ internal fun LuiExtensionRegistry.registerTaskFilterStrip() { acceptsStandardChildren = true, properties = listOf(LuiExtensionProperty("selected", LuiExtensionValueKind.STRING, required = true)), ) { TaskFilterStrip(this) } + register( + "task-filter-label", + "lui-extension-v1|17:task-filter-label|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:bool:required:none|events:", + acceptsStandardChildren = true, + properties = listOf(LuiExtensionProperty("selected", LuiExtensionValueKind.BOOLEAN, required = true)), + ) { TaskFilterLabel(this) } } private val filterEasing = CubicBezierEasing(0.23f, 1f, 0.32f, 1f) @@ -47,12 +59,47 @@ private fun TaskFilterStrip(context: LuiExtensionContext) { } } Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { - for (child in context.children) { - key(child) { - Box(Modifier.animateContentSize(animationSpec = tween(200, easing = filterEasing))) { - context.child(child) - } - } + for (child in context.children) key(child) { context.child(child) } + } +} + +@Composable +private fun TaskFilterLabel(context: LuiExtensionContext) { + val progress by animateFloatAsState( + targetValue = if (context.bool("selected") == true) 1f else 0f, + animationSpec = tween(200, easing = filterEasing), + label = "Task filter selection", + ) + val children = context.children + if (children.size != 2) return + Layout( + modifier = Modifier.clipToBounds(), + content = { + context.child(children[0]) + Box( + Modifier.clearAndSetSemantics {}.graphicsLayer { + alpha = ((progress - 0.32f) / 0.68f).coerceIn(0f, 1f) + }, + ) { context.child(children[1]) } + }, + ) { items, constraints -> + // The surrounding button adds 14 dp of horizontal padding per side. + val collapsedWidth = 44.dp.roundToPx() + val expandedMinimum = 76.dp.roundToPx() + val gap = 8.dp.roundToPx() + val icon = items[0].measure(Constraints(maxWidth = constraints.maxWidth, maxHeight = constraints.maxHeight)) + val label = items[1].measure(Constraints( + maxWidth = (constraints.maxWidth - icon.width - gap).coerceAtLeast(0), + maxHeight = constraints.maxHeight, + )) + val expandedWidth = maxOf(expandedMinimum, icon.width + gap + label.width) + val width = (collapsedWidth + (expandedWidth - collapsedWidth) * progress).roundToInt() + .coerceIn(constraints.minWidth, constraints.maxWidth) + val height = maxOf(icon.height, label.height).coerceIn(constraints.minHeight, constraints.maxHeight) + val iconInset = (((collapsedWidth - icon.width).coerceAtLeast(0) / 2f) * (1 - progress)).roundToInt() + layout(width, height) { + icon.placeRelative(iconInset, (height - icon.height) / 2) + label.placeRelative(iconInset + icon.width + gap, (height - label.height) / 2) } } } diff --git a/apple/Sources/Logseq/LGPropertyExtension.swift b/apple/Sources/Logseq/LGPropertyExtension.swift index a63add0e..a6d6c164 100644 --- a/apple/Sources/Logseq/LGPropertyExtension.swift +++ b/apple/Sources/Logseq/LGPropertyExtension.swift @@ -73,6 +73,15 @@ enum LGPropertyExtension { acceptsStandardChildren: true, properties: [.init(name: "selected", kind: .string, isRequired: true)] ) { AnyView(LGTaskFilterStrip(context: $0)) }) + try registry.register(LUIAppleExtension( + identifier: "task-filter-label", + fingerprint: "lui-extension-v1|17:task-filter-label|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:bool:required:none|events:", + acceptsStandardChildren: true, + properties: [.init(name: "selected", kind: .bool, isRequired: true)] + ) { context in + AnyView(LGTaskFilterLabel(context: context, + progress: context.property("selected") == .bool(true) ? 1 : 0)) + }) try registry.register(LUIAppleExtension( identifier: "outliner-bottom-spacer", fingerprint: "lui-extension-v1|22:outliner-bottom-spacer|profiles:ios/swiftui|standard-children:0|children:|properties:6:height:int:required:none|events:", @@ -143,6 +152,62 @@ private struct LGTaskFilterStrip: View { } } +private struct LGTaskFilterLabel: View, Animatable { + let context: LUIAppleExtensionViewContext + nonisolated var progress: CGFloat + + nonisolated var animatableData: CGFloat { + get { progress } + set { progress = newValue } + } + + var body: some View { + let _ = context.revision + let labelOpacity = Double(min(max((progress - 0.32) / 0.68, 0), 1)) + LGTaskFilterLabelLayout(progress: progress) { + ForEach(Array(context.childIDs.enumerated()), id: \.element) { index, id in + context.content(for: id) + .transaction { $0.animation = nil } + .opacity(index == 0 ? 1 : labelOpacity) + } + } + .clipped() + } +} + +private struct LGTaskFilterLabelLayout: Layout { + let progress: CGFloat + private let collapsedWidth: CGFloat = 44 + private let expandedMinimum: CGFloat = 76 + private let gap: CGFloat = 8 + + func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { + guard subviews.count == 2 else { return .zero } + let icon = subviews[0].sizeThatFits(.unspecified) + let label = subviews[1].sizeThatFits(.unspecified) + let expandedWidth = max(expandedMinimum, icon.width + gap + label.width) + let width = collapsedWidth + (expandedWidth - collapsedWidth) * progress + return CGSize(width: min(width, proposal.width ?? width), height: max(icon.height, label.height)) + } + + func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { + guard subviews.count == 2 else { return } + let icon = subviews[0].sizeThatFits(.unspecified) + let inset = max(0, (collapsedWidth - icon.width) / 2) * (1 - progress) + let layoutDirection = subviews.layoutDirection + let origin = layoutDirection == .leftToRight ? bounds.minX : bounds.maxX + let direction: CGFloat = layoutDirection == .leftToRight ? 1 : -1 + let anchor: UnitPoint = layoutDirection == .leftToRight ? .leading : .trailing + subviews[0].place(at: CGPoint(x: origin + direction * inset, y: bounds.midY), + anchor: anchor, proposal: ProposedViewSize(icon)) + let labelLeading = inset + icon.width + gap + let labelWidth = progress < 1 ? subviews[1].sizeThatFits(.unspecified).width + : max(0, bounds.width - labelLeading) + subviews[1].place(at: CGPoint(x: origin + direction * labelLeading, y: bounds.midY), + anchor: anchor, proposal: ProposedViewSize(width: labelWidth, height: bounds.height)) + } +} + private struct LGOutlinerBottomSpacer: View { let height: CGFloat @Environment(\.outlinerScrollRetention) private var scrollRetention diff --git a/shared/src/logseq/view.ml b/shared/src/logseq/view.ml index ba77939d..84250e06 100644 --- a/shared/src/logseq/view.ml +++ b/shared/src/logseq/view.ml @@ -367,6 +367,12 @@ let task_filter_strip_schema () = component "task-filter-strip" [profile IOS SwiftUIHost; profile AndroidOS KotlinHost] true [] [property "selected" StringScalar true None] [] +let task_filter_label_schema () = + let open Lui_protocol in + let open Lui_extension in + component "task-filter-label" [profile IOS SwiftUIHost; profile AndroidOS KotlinHost] + true [] [property "selected" BoolScalar true None] [] + let outliner_bottom_spacer_schema () = let open Lui_protocol in let open Lui_extension in @@ -451,6 +457,7 @@ let extension_registry () = [Lui_extension.event "query-changed" [Lui_extension.event_field "query" Lui_extension.StringScalar true]]); Lui_extension.register_component registry (journal_task_transition_schema ()); Lui_extension.register_component registry (task_filter_strip_schema ()); + Lui_extension.register_component registry (task_filter_label_schema ()); Lui_extension.register_component registry (outliner_bottom_spacer_schema ()); Lui_extension.register_component registry (journal_task_chevron_schema ()); Lui_extension.register_component registry (outliner_continuation_schema ()); diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index 71ee326b..d8723a76 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -2269,30 +2269,39 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par | Model.TasksUpcoming -> "calendar" | Model.TasksAll -> "toolbar-task" in let disabled = own (Signal.map View_base.outliner_selection_active_ model_source) in + let native_filters = match Lui_ui.platform mount_context, Lui_ui.host mount_context with + | IOS, SwiftUIHost | AndroidOS, KotlinHost -> true + | _ -> false in let tab_button value name = let label = View_base.tr (Signal.sample model_source) name in let selected = own (Signal.map ((=) value) tab) in let background = own (Signal.map (fun selected -> if selected then "task-tab-selected-background" else "task-tab-background") selected) in - let foreground = own (Signal.map (fun selected -> if selected then "link" else "foreground") selected) in let identifier = "tasks.tab." ^ Model.tasks_view_section value in let on_press _ = update_tasks_view model_source send (fun options -> { options with tab = value }) in + let glyph = icon ~name:(`app (tab_icon value)) ~width:16 ~height:16 ~foreground:"foreground" [] in + let title = text ~value:label ~line_clamp:1 ~truncate:true ~foreground:"link" [] in + let content = + if native_filters then + custom (fun context parent -> + let node = Lui_ui.extension context "task-filter-label" in + attach context parent node; + Lui_ui.extension_property_signal context node "selected" + (own (Signal.map (fun selected -> BoolValue selected) selected)); + ignore (mount context ~parent:node glyph); + ignore (mount context ~parent:node title); + node) + else row ~gap:8 ~cross:`center [glyph; if_ ~test:selected title] in box ~background_signal:background ~corner_radius:22 [ button ~text:"" ~label ~variant:`ghost - ~min_width:44 ~min_height:44 ~padding_horizontal:14 ~corner_radius:22 - ~selected_signal:selected ~disabled_signal:disabled ~foreground_signal:foreground - ~accessibility_identifier:identifier ~on_press [ - icon ~name:(`app (tab_icon value)) ~width:16 ~height:16 ~foreground_signal:foreground []; - if_ ~test:selected - (text ~value:label ~line_clamp:1 ~truncate:true ~foreground_signal:foreground - ?margin_left:(if Lui_ui.host mount_context = KotlinHost then None else Some 8) - ~accessibility_identifier:(identifier ^ ".label") []); - ]; + ~min_width:72 ~min_height:44 ~padding_horizontal:14 ~corner_radius:22 + ~selected_signal:selected ~disabled_signal:disabled + ~accessibility_identifier:identifier ~on_press [content]; ] in let buttons = [tab_button Model.TasksToday "Today"; tab_button Model.TasksUpcoming "Upcoming"; tab_button Model.TasksAll "All"] in - let filters = match Lui_ui.platform mount_context, Lui_ui.host mount_context with - | IOS, SwiftUIHost | AndroidOS, KotlinHost -> + let filters = + if native_filters then custom (fun context parent -> let node = Lui_ui.extension context "task-filter-strip" in attach context parent node; @@ -2300,7 +2309,7 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par (own (Signal.map (fun tab -> StringValue (Model.tasks_view_section tab)) tab)); List.iter (fun button -> ignore (mount context ~parent:node button)) buttons; node) - | _ -> row ~gap:8 ~cross:`center buttons in + else row ~gap:8 ~cross:`center buttons in let window = keyed ~source:(own (Signal.map (fun tab -> [tab]) tab)) ~key:Fun.id ~cmp:compare ~mount:(fun _ -> diff --git a/shared/test/logseq/app_test.ml b/shared/test/logseq/app_test.ml index c8449312..975c1637 100644 --- a/shared/test/logseq/app_test.ml +++ b/shared/test/logseq/app_test.ml @@ -7641,9 +7641,9 @@ let journal_agenda_is_retained_across_navigation () = check_eq (find root "tasks.tab.all") all_chip; check_eq (find root "tasks.menu.past") (-1); let chip_property section = property renderer (find root ("tasks.tab." ^ section)) in - let chip_text section = property renderer (find root ("tasks.tab." ^ section ^ ".label")) Lui_protocol.TextValue in - check_eq (chip_text "upcoming") (Some (Lui_protocol.StringValue "Upcoming")); - check_eq (chip_text "all") None; + let chip_selected section = chip_property section Lui_protocol.Selected = Some (Lui_protocol.BoolValue true) in + check (chip_selected "upcoming"); + check (not (chip_selected "all")); check_eq (chip_property "all" Lui_protocol.AccessibilityLabel) (Some (Lui_protocol.StringValue "All")); tap root "tasks.tab.all"; let refresh_id = match List.find_map (function @@ -7654,8 +7654,8 @@ let journal_agenda_is_retained_across_navigation () = apply (Model.DequeueEffect refresh_id); snapshot work; apply (Model.ResolveEffect (refresh_id, true, "")); - check_eq (chip_text "all") (Some (Lui_protocol.StringValue "All")); - check_eq (chip_text "upcoming") None; + check (chip_selected "all"); + check (not (chip_selected "upcoming")); check_eq (find root "tasks.menu.past") (-1); let all_group = Journal_task_dates.task_group_key "all" "project" in let all_task () = find root "journal-task.work-all-only" in @@ -7689,7 +7689,7 @@ let journal_agenda_is_retained_across_navigation () = tap root all_group; check_eq (all_task ()) (-1); tap root "tasks.tab.today"; - check_eq (chip_text "today") (Some (Lui_protocol.StringValue "Today")); + check (chip_selected "today"); check_eq (all_task ()) (-1); check (find root "tasks.menu.past" <> -1); let pane () = find root "screen.tasks" in From 72f389037497b79a8bdd489e716838d11f0a4930 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 13:33:57 +0800 Subject: [PATCH 5/7] Highlight icons for selected task filters --- shared/src/logseq/view_outliner.ml | 3 ++- shared/test/logseq/app_test.ml | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index d8723a76..38ea0d6e 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -2279,7 +2279,8 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par if selected then "task-tab-selected-background" else "task-tab-background") selected) in let identifier = "tasks.tab." ^ Model.tasks_view_section value in let on_press _ = update_tasks_view model_source send (fun options -> { options with tab = value }) in - let glyph = icon ~name:(`app (tab_icon value)) ~width:16 ~height:16 ~foreground:"foreground" [] in + let glyph_color = own (Signal.map (fun selected -> if selected then "link" else "foreground") selected) in + let glyph = icon ~name:(`app (tab_icon value)) ~width:16 ~height:16 ~foreground_signal:glyph_color [] in let title = text ~value:label ~line_clamp:1 ~truncate:true ~foreground:"link" [] in let content = if native_filters then diff --git a/shared/test/logseq/app_test.ml b/shared/test/logseq/app_test.ml index 975c1637..448de37d 100644 --- a/shared/test/logseq/app_test.ml +++ b/shared/test/logseq/app_test.ml @@ -7642,8 +7642,13 @@ let journal_agenda_is_retained_across_navigation () = check_eq (find root "tasks.menu.past") (-1); let chip_property section = property renderer (find root ("tasks.tab." ^ section)) in let chip_selected section = chip_property section Lui_protocol.Selected = Some (Lui_protocol.BoolValue true) in + let chip_icon_color section = + let glyph = descendant_with_node_kind renderer (find root ("tasks.tab." ^ section)) Lui_protocol.Icon in + property_string renderer glyph Lui_protocol.ForegroundValue in check (chip_selected "upcoming"); check (not (chip_selected "all")); + check_eq (chip_icon_color "upcoming") "link"; + check_eq (chip_icon_color "all") "foreground"; check_eq (chip_property "all" Lui_protocol.AccessibilityLabel) (Some (Lui_protocol.StringValue "All")); tap root "tasks.tab.all"; let refresh_id = match List.find_map (function @@ -7656,6 +7661,8 @@ let journal_agenda_is_retained_across_navigation () = apply (Model.ResolveEffect (refresh_id, true, "")); check (chip_selected "all"); check (not (chip_selected "upcoming")); + check_eq (chip_icon_color "all") "link"; + check_eq (chip_icon_color "upcoming") "foreground"; check_eq (find root "tasks.menu.past") (-1); let all_group = Journal_task_dates.task_group_key "all" "project" in let all_task () = find root "journal-task.work-all-only" in From a9c3844ea2c31a79a27b8bdfc83f4cf72fd57856 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 13:37:06 +0800 Subject: [PATCH 6/7] Use a checklist icon for All tasks --- .../src/main/kotlin/com/logseq/logseq/runtime/LogseqIcons.kt | 1 + apple/Sources/Logseq/LGRenderer.swift | 1 + shared/src/logseq/view_outliner.ml | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/kotlin/com/logseq/logseq/runtime/LogseqIcons.kt b/android/app/src/main/kotlin/com/logseq/logseq/runtime/LogseqIcons.kt index a1191e76..02bf37a1 100644 --- a/android/app/src/main/kotlin/com/logseq/logseq/runtime/LogseqIcons.kt +++ b/android/app/src/main/kotlin/com/logseq/logseq/runtime/LogseqIcons.kt @@ -220,6 +220,7 @@ internal val logseqAppIcons: Map = mapOf( "tab-tasks" to Icons.Outlined.CheckBox, "tab-tasks-selected" to Icons.Filled.CheckBox, "tasks-today" to Icons.Outlined.WbSunny, + "tasks-all" to Icons.Outlined.Checklist, "tab-notifications" to Icons.Outlined.Notifications, "tab-notifications-selected" to Icons.Filled.Notifications, "discussion-comment" to Icons.Outlined.ChatBubbleOutline, diff --git a/apple/Sources/Logseq/LGRenderer.swift b/apple/Sources/Logseq/LGRenderer.swift index 6f4d6153..ef458bc9 100644 --- a/apple/Sources/Logseq/LGRenderer.swift +++ b/apple/Sources/Logseq/LGRenderer.swift @@ -84,6 +84,7 @@ enum LGIconPolicy { "tab-tasks": .systemName("checkmark.square"), "tab-tasks-selected": .systemName("checkmark.square.fill"), "tasks-today": .systemName("sun.max"), + "tasks-all": .systemName("checklist"), "composer-file": .systemName("doc"), "arrow-up": .systemName("arrow.up"), "close": .assetName("close"), diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index 38ea0d6e..78e596c6 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -2267,7 +2267,7 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par let tab_icon = function | Model.TasksToday -> "tasks-today" | Model.TasksUpcoming -> "calendar" - | Model.TasksAll -> "toolbar-task" in + | Model.TasksAll -> "tasks-all" in let disabled = own (Signal.map View_base.outliner_selection_active_ model_source) in let native_filters = match Lui_ui.platform mount_context, Lui_ui.host mount_context with | IOS, SwiftUIHost | AndroidOS, KotlinHost -> true From 4eee26f56105a8636aeb35c225fd8651b86157c5 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 Nov 2026 13:51:21 +0800 Subject: [PATCH 7/7] Keep task filter motion continuous while All loads --- .../Sources/Logseq/LGPropertyExtension.swift | 58 ++++++++++++++----- shared/src/logseq/view_outliner.ml | 4 +- shared/src/logseq/view_rows.ml | 14 +++-- shared/src/logseq/view_rows.mli | 2 +- shared/test/logseq/app_test.ml | 10 +++- 5 files changed, 66 insertions(+), 22 deletions(-) diff --git a/apple/Sources/Logseq/LGPropertyExtension.swift b/apple/Sources/Logseq/LGPropertyExtension.swift index a6d6c164..cc45e70f 100644 --- a/apple/Sources/Logseq/LGPropertyExtension.swift +++ b/apple/Sources/Logseq/LGPropertyExtension.swift @@ -78,10 +78,7 @@ enum LGPropertyExtension { fingerprint: "lui-extension-v1|17:task-filter-label|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:bool:required:none|events:", acceptsStandardChildren: true, properties: [.init(name: "selected", kind: .bool, isRequired: true)] - ) { context in - AnyView(LGTaskFilterLabel(context: context, - progress: context.property("selected") == .bool(true) ? 1 : 0)) - }) + ) { AnyView(LGTaskFilterLabel(context: $0)) }) try registry.register(LUIAppleExtension( identifier: "outliner-bottom-spacer", fingerprint: "lui-extension-v1|22:outliner-bottom-spacer|profiles:ios/swiftui|standard-children:0|children:|properties:6:height:int:required:none|events:", @@ -136,38 +133,73 @@ private struct LGTaskFilterStrip: View { let context: LUIAppleExtensionViewContext @Environment(\.accessibilityReduceMotion) private var reduceMotion @Environment(\.dynamicTypeSize) private var dynamicTypeSize + @State private var animatedSelection: LUIExtensionValue? + + init(context: LUIAppleExtensionViewContext) { + self.context = context + _animatedSelection = State(initialValue: context.property("selected")) + } var body: some View { let _ = context.revision let selected = context.property("selected") - HStack(spacing: 8) { - ForEach(context.childIDs, id: \.self) { id in - context.content(for: id) - .fixedSize(horizontal: !dynamicTypeSize.isAccessibilitySize, vertical: false) + // The shared screen mounts the three filters in this order. + LGTaskFilterStripContent(context: context, fixedWidth: !dynamicTypeSize.isAccessibilitySize, + progress: AnimatablePair( + animatedSelection == .string("today") ? 1 : 0, + AnimatablePair(animatedSelection == .string("upcoming") ? 1 : 0, + animatedSelection == .string("all") ? 1 : 0))) + .onChange(of: selected) { _, selection in + withAnimation(reduceMotion ? nil : journalDisclosureAnimation) { + animatedSelection = selection } } - .animation(reduceMotion ? nil : journalDisclosureAnimation, value: selected) .sensoryFeedback(.selection, trigger: selected) .frame(maxWidth: .infinity, alignment: .leading) } } -private struct LGTaskFilterLabel: View, Animatable { +private extension EnvironmentValues { + @Entry var lgTaskFilterProgress: CGFloat? = nil +} + +private struct LGTaskFilterStripContent: View, Animatable { + typealias Progress = AnimatablePair> let context: LUIAppleExtensionViewContext - nonisolated var progress: CGFloat + let fixedWidth: Bool + nonisolated var progress: Progress - nonisolated var animatableData: CGFloat { + nonisolated var animatableData: Progress { get { progress } set { progress = newValue } } + var body: some View { + let progresses = [progress.first, progress.second.first, progress.second.second] + HStack(spacing: 8) { + ForEach(Array(context.childIDs.enumerated()), id: \.element) { index, id in + context.content(for: id) + .fixedSize(horizontal: fixedWidth, vertical: false) + .environment(\.lgTaskFilterProgress, progresses.indices.contains(index) ? progresses[index] : nil) + } + } + // The shared progress drives all positions and opacities. Do not animate + // each of their intermediate values again as a separate layout change. + .transaction { $0.animation = nil } + } +} + +private struct LGTaskFilterLabel: View { + let context: LUIAppleExtensionViewContext + @Environment(\.lgTaskFilterProgress) private var animatedProgress + var body: some View { let _ = context.revision + let progress = animatedProgress ?? (context.property("selected") == .bool(true) ? 1 : 0) let labelOpacity = Double(min(max((progress - 0.32) / 0.68, 0), 1)) LGTaskFilterLabelLayout(progress: progress) { ForEach(Array(context.childIDs.enumerated()), id: \.element) { index, id in context.content(for: id) - .transaction { $0.animation = nil } .opacity(index == 0 ? 1 : labelOpacity) } } diff --git a/shared/src/logseq/view_outliner.ml b/shared/src/logseq/view_outliner.ml index 78e596c6..0cef3c3d 100644 --- a/shared/src/logseq/view_outliner.ml +++ b/shared/src/logseq/view_outliner.ml @@ -2312,9 +2312,11 @@ let tasks_screen context model_source send : t = custom @@ fun mount_context par node) else row ~gap:8 ~cross:`center buttons in let window = + (* On SwiftUI, keep the same scroll stack and filter header while a tab has no rows yet. *) + let keep_empty = Lui_ui.host mount_context = SwiftUIHost in keyed ~source:(own (Signal.map (fun tab -> [tab]) tab)) ~key:Fun.id ~cmp:compare ~mount:(fun _ -> - View_rows.windowed_keyed ~identifier:"tasks.window" ~source:entries ~key:View_rows.page_entry_identifier ~cmp:compare + View_rows.windowed_keyed ~keep_empty ~identifier:"tasks.window" ~source:entries ~key:View_rows.page_entry_identifier ~cmp:compare ~is_pinned:View_rows.page_entry_pinned_ ~mount:(fun entry -> box [mount_journal_task_entry context model_source send entry]) ()) in let list = with_journal_task_transition model_source diff --git a/shared/src/logseq/view_rows.ml b/shared/src/logseq/view_rows.ml index d5a21347..a66e0b82 100644 --- a/shared/src/logseq/view_rows.ml +++ b/shared/src/logseq/view_rows.ml @@ -140,7 +140,7 @@ let paged_keyed ~identifier ~item_extent ~count ~offset ~on_visible_range ~sourc [Lui_elements.keyed ~source:(reactive (fun offset rows viewport -> snd (window offset rows viewport)) offset source (Signal.value viewport)) ~key ~cmp ~mount])) -let windowed_keyed ?scroll_target ?first_section ?reset_key +let windowed_keyed ?scroll_target ?first_section ?reset_key ?(keep_empty = false) ?(window_size = 32) ?(identifier = "outliner.window") ?(item_extent = 32) ?(on_visible_range = fun _ _ -> ()) ?(on_window = fun _ -> ()) ?(on_prefetch = fun _ -> ()) ?(is_pinned = fun _ -> false) @@ -216,9 +216,8 @@ let windowed_keyed ?scroll_target ?first_section ?reset_key let following = Array.sub items after (min 16 (Array.length items - after)) |> Array.to_list in preceding @ following) window))) in ignore (Signal.own context.ui_scope (Signal.observe adjacent on_prefetch)); - let content = - Lui_elements.if_ ~test:(own (Signal.cutoff Bool.equal (own (Signal.map (fun items -> Array.length items > 0) items)))) - (Lui_elements.list ~accessibility_identifier:identifier + let window_list = + Lui_elements.list ~accessibility_identifier:identifier ~data_attrs_signal:metadata ~track_visible_range:true ~on_visible_range:(function | Lui_elements.Range { first; last } -> @@ -245,7 +244,12 @@ let windowed_keyed ?scroll_target ?first_section ?reset_key Signal.set range (next_start, window_size) end | _ -> ()) - [Lui_elements.keyed ~source:visible ~key ~cmp ~mount]) in + [Lui_elements.keyed ~source:visible ~key ~cmp ~mount] in + let content = + if keep_empty then window_list + else + Lui_elements.if_ ~test:(own (Signal.cutoff Bool.equal (own (Signal.map (fun items -> Array.length items > 0) items)))) + window_list in Lui_elements.mount context ?parent content) type reference_entry = diff --git a/shared/src/logseq/view_rows.mli b/shared/src/logseq/view_rows.mli index cb07a4d9..d676c760 100644 --- a/shared/src/logseq/view_rows.mli +++ b/shared/src/logseq/view_rows.mli @@ -25,7 +25,7 @@ val paged_keyed : identifier:string -> item_extent:int -> count:int Signal.signa val windowed_keyed : ?scroll_target:string option Signal.signal -> ?first_section:int Signal.signal -> - ?reset_key:string Signal.signal -> ?window_size:int -> ?identifier:string -> ?item_extent:int -> + ?reset_key:string Signal.signal -> ?keep_empty:bool -> ?window_size:int -> ?identifier:string -> ?item_extent:int -> ?on_visible_range:(int -> int -> unit) -> ?on_window:('a list -> unit) -> ?on_prefetch:('a list -> unit) -> ?is_pinned:('a -> bool) -> ?item_equal:('a -> 'a -> bool) -> diff --git a/shared/test/logseq/app_test.ml b/shared/test/logseq/app_test.ml index 448de37d..af8a2598 100644 --- a/shared/test/logseq/app_test.ml +++ b/shared/test/logseq/app_test.ml @@ -7596,7 +7596,7 @@ let graph_switch_rearms_journal_pagination () = ) [ios_backend; kotlin_backend] let journal_agenda_is_retained_across_navigation () = - List.iter (fun backend -> + List.iter (fun (ios, backend) -> let app = App.create (backend ()) in let renderer = Lui_app.runtime app in let apply action = send app action; flush app in @@ -7640,6 +7640,7 @@ let journal_agenda_is_retained_across_navigation () = tap root "tasks.tab.upcoming"; check_eq (find root "tasks.tab.all") all_chip; check_eq (find root "tasks.menu.past") (-1); + if ios then check (find root "tasks.window" <> -1); let chip_property section = property renderer (find root ("tasks.tab." ^ section)) in let chip_selected section = chip_property section Lui_protocol.Selected = Some (Lui_protocol.BoolValue true) in let chip_icon_color section = @@ -7651,6 +7652,8 @@ let journal_agenda_is_retained_across_navigation () = check_eq (chip_icon_color "all") "foreground"; check_eq (chip_property "all" Lui_protocol.AccessibilityLabel) (Some (Lui_protocol.StringValue "All")); tap root "tasks.tab.all"; + let loading_window = find root "tasks.window" in + if ios then check (loading_window <> -1); let refresh_id = match List.find_map (function | Model.NodePropertyEffect (id, "journal-tasks.refresh", _) -> Some id | _ -> None) (App.model app).pending_effects with @@ -7659,6 +7662,9 @@ let journal_agenda_is_retained_across_navigation () = apply (Model.DequeueEffect refresh_id); snapshot work; apply (Model.ResolveEffect (refresh_id, true, "")); + if ios then + check_eq ~msg:"keep the SwiftUI list window mounted while All loads" + (find root "tasks.window") loading_window; check (chip_selected "all"); check (not (chip_selected "upcoming")); check_eq (chip_icon_color "all") "link"; @@ -7751,7 +7757,7 @@ let journal_agenda_is_retained_across_navigation () = apply (Model.ResolveEffect (id, true, "")); check_eq (retry ()) (-1); check_eq (due ()) (-1) - ) [ios_backend; kotlin_backend] + ) [true, ios_backend; false, kotlin_backend] let journal_task_results_edit_and_select_the_source_block () = List.iter (fun (ios, backend) ->