Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/webapp/app/components/primitives/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Ariakit from "@ariakit/react";
import { type SelectProps as AriaSelectProps } from "@ariakit/react";
import { SelectValue } from "@ariakit/react-core/select/select-value";
import { useStoreState } from "@ariakit/react-core/utils/store";
import { Link } from "@remix-run/react";
import * as React from "react";
import { Fragment, useMemo, useState } from "react";
Expand Down Expand Up @@ -484,7 +485,7 @@ export function SelectItem({
const render = combobox ? <Ariakit.ComboboxItem render={props.render} /> : props.render;
const ref = React.useRef<HTMLDivElement>(null);
const select = Ariakit.useSelectContext();
const selectValue = select?.useState("value");
const selectValue = useStoreState(select, "value");
Comment thread
carderne marked this conversation as resolved.

const isChecked = React.useMemo(() => {
if (!props.value || selectValue == null) return false;
Expand Down Expand Up @@ -692,8 +693,8 @@ export function ComboBox({
...props
}: ComboBoxProps) {
const combobox = Ariakit.useComboboxContext();
const open = combobox?.useState("open");
const input = combobox?.useState("baseElement");
const open = useStoreState(combobox, "open");
const input = useStoreState(combobox, "baseElement");

React.useEffect(() => {
if (!open || !input) return;
Expand Down
3 changes: 1 addition & 2 deletions apps/webapp/app/hooks/useChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { useEffect, useRef } from "react";

/** Call a function when the id of the item changes */
export function useChanged<T extends { id: string }>(
getItem: () => T | undefined,
item: T | undefined,
action: (item: T | undefined) => void,
sendInitialUndefined = true
) {
const previousItemId = useRef<string | undefined>();
const isInitialRender = useRef(true);
const actionRef = useRef(action);
const itemRef = useRef<T | undefined>();
const item = getItem();
const itemId = item?.id;

actionRef.current = action;
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/app/hooks/useOrganizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export function useOrganization(matches?: UIMatch[]) {
}

export const useOrganizationChanged = (action: (org: MatchedOrganization | undefined) => void) => {
useChanged(useOptionalOrganization, action);
const organization = useOptionalOrganization();
useChanged(organization, action);
};

export function useIsImpersonating(matches?: UIMatch[]) {
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/app/hooks/useProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export function useProject(matches?: UIMatch[]) {
}

export const useProjectChanged = (action: (org: MatchedProject | undefined) => void) => {
useChanged(useOptionalProject, action);
const project = useOptionalProject();
useChanged(project, action);
};
3 changes: 2 additions & 1 deletion apps/webapp/app/hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function useUser(matches?: UIMatch[]): User {
}

export function useUserChanged(callback: (user: User | undefined) => void) {
useChanged(useOptionalUser, callback);
const user = useOptionalUser();
useChanged(user, callback);
}

/**
Expand Down