chore: fixing some initial re-renders (#10185)
Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
1 parent
2fd9ef2733
commit
628a29e89c
8 files changed
+144
-113
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { memo } from "react";
|
||||
|
||||
import { FilterCheckboxFieldsContainer } from "@calcom/features/filters/components/TeamsFilter";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { RouterOutputs } from "@calcom/trpc";
|
||||
@@ -14,7 +16,7 @@ const mapEventTypeToOption = (eventType: EventType): Option => ({
|
||||
label: eventType.teamId ? `${eventType.title} (${eventType.team?.name})` : eventType.title,
|
||||
});
|
||||
|
||||
export const EventTypeList = () => {
|
||||
export const EventTypeList = memo(() => {
|
||||
const { t } = useLocale();
|
||||
const { filter, setConfigFilters } = useFilterContext();
|
||||
const { selectedTeamId, selectedEventTypeId, selectedUserId, isAll } = filter;
|
||||
@@ -72,4 +74,6 @@ export const EventTypeList = () => {
|
||||
</FilterCheckboxFieldsContainer>
|
||||
</AnimatedPopover>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
EventTypeList.displayName = "EventTypeList";
|
||||
@@ -5,7 +5,7 @@ import Link from "next/link";
|
||||
import type { NextRouter } from "next/router";
|
||||
import { useRouter } from "next/router";
|
||||
import type { Dispatch, ReactNode, SetStateAction } from "react";
|
||||
import React, { Fragment, useEffect, useState, useRef } from "react";
|
||||
import React, { Fragment, useEffect, useState, useRef, useMemo } from "react";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -801,15 +801,18 @@ const getOrganizationUrl = (slug: string) =>
|
||||
|
||||
function SideBar({ bannersHeight, user }: SideBarProps) {
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
const router = useRouter();
|
||||
const orgBranding = useOrgBrandingValues();
|
||||
const publicPageUrl = orgBranding?.slug ? getOrganizationUrl(orgBranding?.slug) : "";
|
||||
|
||||
const publicPageUrl = useMemo(() => {
|
||||
if (!user?.organizationId) return `${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user?.username}`;
|
||||
const publicPageUrl = orgBranding?.slug ? getOrganizationUrl(orgBranding?.slug) : "";
|
||||
return publicPageUrl;
|
||||
}, [orgBranding?.slug, user?.organizationId, user?.username]);
|
||||
|
||||
const bottomNavItems: NavigationItemType[] = [
|
||||
{
|
||||
name: "view_public_page",
|
||||
href: !!user?.organizationId
|
||||
? publicPageUrl
|
||||
: `${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user?.username}`,
|
||||
href: publicPageUrl,
|
||||
icon: ExternalLink,
|
||||
target: "__blank",
|
||||
},
|
||||
@@ -818,9 +821,7 @@ function SideBar({ bannersHeight, user }: SideBarProps) {
|
||||
href: "",
|
||||
onClick: (e: { preventDefault: () => void }) => {
|
||||
e.preventDefault();
|
||||
navigator.clipboard.writeText(
|
||||
!!user?.organizationId ? publicPageUrl : `${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user?.username}`
|
||||
);
|
||||
navigator.clipboard.writeText(publicPageUrl);
|
||||
showToast(t("link_copied"), "success");
|
||||
},
|
||||
icon: Copy,
|
||||
@@ -898,6 +899,7 @@ function SideBar({ bannersHeight, user }: SideBarProps) {
|
||||
{bottomNavItems.map(({ icon: Icon, ...item }, index) => (
|
||||
<Tooltip side="right" content={t(item.name)} className="lg:hidden" key={item.name}>
|
||||
<ButtonOrLink
|
||||
id={item.name}
|
||||
href={item.href || undefined}
|
||||
aria-label={t(item.name)}
|
||||
target={item.target}
|
||||
@@ -908,11 +910,6 @@ function SideBar({ bannersHeight, user }: SideBarProps) {
|
||||
isLocaleReady ? "hover:bg-emphasis hover:text-emphasis" : "",
|
||||
index === 0 && "mt-3"
|
||||
)}
|
||||
aria-current={
|
||||
defaultIsCurrent && defaultIsCurrent({ item: { href: item.href }, router })
|
||||
? "page"
|
||||
: undefined
|
||||
}
|
||||
onClick={item.onClick}>
|
||||
{!!Icon && (
|
||||
<Icon
|
||||
@@ -921,11 +918,6 @@ function SideBar({ bannersHeight, user }: SideBarProps) {
|
||||
"me-3 md:ltr:mr-2 md:rtl:ml-2"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
aria-current={
|
||||
defaultIsCurrent && defaultIsCurrent({ item: { href: item.href }, router })
|
||||
? "page"
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{isLocaleReady ? (
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import { useState } from "react";
|
||||
import { useState, memo } from "react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
@@ -98,9 +97,7 @@ export const tips = [
|
||||
|
||||
const reversedTips = tips.slice(0).reverse();
|
||||
|
||||
export default function Tips() {
|
||||
const [animationRef] = useAutoAnimate<HTMLDivElement>();
|
||||
|
||||
function Tips() {
|
||||
const { t } = useLocale();
|
||||
|
||||
const [list, setList] = useState<typeof tips>(() => {
|
||||
@@ -175,3 +172,5 @@ export default function Tips() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default memo(Tips);
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useRef, useEffect } from "react";
|
||||
|
||||
export function useTraceUpdate(props: { [s: string]: unknown } | ArrayLike<unknown>) {
|
||||
const prev = useRef(props);
|
||||
useEffect(() => {
|
||||
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore TODO: fix this
|
||||
if (prev.current[k] !== v) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore TODO: fix this
|
||||
ps[k] = [prev.current[k], v];
|
||||
}
|
||||
return ps;
|
||||
}, {});
|
||||
if (Object.keys(changedProps).length > 0) {
|
||||
console.log("Changed props:", changedProps);
|
||||
}
|
||||
prev.current = props;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user