Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channel): stop findbar previous from wrapping past most recent (#3310)

gbirman47ffbb190610
diff --git a/js/app/packages/block-pdf/component/SimpleSearch.tsx b/js/app/packages/block-pdf/component/SimpleSearch.tsx
index 3a57e82c25..1ef7160e7a 100644
--- a/js/app/packages/block-pdf/component/SimpleSearch.tsx
+++ b/js/app/packages/block-pdf/component/SimpleSearch.tsx
@@ -87,6 +87,8 @@ export function SimpleSearch() {
hasUnsubmittedChanges: () => searchText() !== submittedQuery(),
isPending,
resultsCount: total,
+ canNext: () => total() > 0,
+ canPrevious: () => total() > 0,
open: () => setIsOpen(true),
close,
submit,
diff --git a/js/app/packages/channel/Channel/create-channel-find-bar.ts b/js/app/packages/channel/Channel/create-channel-find-bar.ts
index e948bde0f0..700394203d 100644
--- a/js/app/packages/channel/Channel/create-channel-find-bar.ts
+++ b/js/app/packages/channel/Channel/create-channel-find-bar.ts
@@ -177,6 +177,10 @@ export function createChannelFindBar(
totalCount,
isFetching: () => searchQuery.isFetching,
validateText: validateSearchServiceText,
+ // Only wrap past the most recent result once every page is loaded —
+ // otherwise wrapping would jump to a "last" result that isn't truly
+ // the global oldest hit.
+ wrapPrevious: () => !searchQuery.hasNextPage,
navigate: (result) => {
if (result.threadId) {
options.goToMessage(result.threadId, result.messageId);
diff --git a/js/app/packages/core/component/FindBar.tsx b/js/app/packages/core/component/FindBar.tsx
index 3f1fdfadfe..717c0ad4e6 100644
--- a/js/app/packages/core/component/FindBar.tsx
+++ b/js/app/packages/core/component/FindBar.tsx
@@ -200,6 +200,11 @@ function FindBarPreviousButton() {
size="icon-sm"
variant="ghost"
aria-label={direction() === 'desc' ? 'Next match' : 'Previous match'}
+ disabled={
+ direction() === 'desc'
+ ? !controller.canNext()
+ : !controller.canPrevious()
+ }
onClick={() =>
direction() === 'desc' ? controller.next() : controller.previous()
}
@@ -216,6 +221,11 @@ function FindBarNextButton() {
size="icon-sm"
variant="ghost"
aria-label={direction() === 'desc' ? 'Previous match' : 'Next match'}
+ disabled={
+ direction() === 'desc'
+ ? !controller.canPrevious()
+ : !controller.canNext()
+ }
onClick={() =>
direction() === 'desc' ? controller.previous() : controller.next()
}
diff --git a/js/app/packages/core/component/createFindBarController.ts b/js/app/packages/core/component/createFindBarController.ts
index e6dc124a38..49cb27b97b 100644
--- a/js/app/packages/core/component/createFindBarController.ts
+++ b/js/app/packages/core/component/createFindBarController.ts
@@ -12,6 +12,10 @@ export type FindBarSource<T> = {
navigate: (result: T) => void;
validateText?: (text: string) => boolean;
totalCount?: Accessor<number | undefined>;
+ /** When false, `previous()` stops at index 1. Defaults to true. */
+ wrapPrevious?: Accessor<boolean>;
+ /** When false, `next()` stops at the last result. Defaults to true. */
+ wrapNext?: Accessor<boolean>;
};
export type FindBarController = {
@@ -23,6 +27,8 @@ export type FindBarController = {
hasUnsubmittedChanges: Accessor<boolean>;
isPending: Accessor<boolean>;
resultsCount: Accessor<number>;
+ canNext: Accessor<boolean>;
+ canPrevious: Accessor<boolean>;
open: () => void;
close: () => void;
submit: () => void;
@@ -68,9 +74,13 @@ export function createFindBarController<T>(
})
);
+ const wrapNext = () => source.wrapNext?.() ?? true;
+ const wrapPrevious = () => source.wrapPrevious?.() ?? true;
+
const next = () => {
const rs = source.results();
if (rs.length === 0) return;
+ if (activeIndex() >= rs.length && !wrapNext()) return;
const i = activeIndex() >= rs.length ? 1 : activeIndex() + 1;
setActiveIndex(i);
source.navigate(rs[i - 1]);
@@ -79,6 +89,7 @@ export function createFindBarController<T>(
const previous = () => {
const rs = source.results();
if (rs.length === 0) return;
+ if (activeIndex() <= 1 && !wrapPrevious()) return;
const i = activeIndex() <= 1 ? rs.length : activeIndex() - 1;
setActiveIndex(i);
source.navigate(rs[i - 1]);
@@ -119,6 +130,16 @@ export function createFindBarController<T>(
hasUnsubmittedChanges: () => query().trim() !== submittedQuery(),
isPending: () => !!submittedQuery() && source.isFetching(),
resultsCount: () => source.totalCount?.() ?? source.results().length,
+ canNext: () => {
+ const len = source.results().length;
+ if (len === 0) return false;
+ return wrapNext() || activeIndex() < len;
+ },
+ canPrevious: () => {
+ const len = source.results().length;
+ if (len === 0) return false;
+ return wrapPrevious() || activeIndex() > 1;
+ },
open,
close,
submit,