Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use || instead of ?? #4187

Merged
merged 1 commit into from
Dec 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const CollectForm: FC<CollectFormProps> = ({ setShowModal }) => {
);

const { SimpleCollectOpenActionModule } = CollectOpenActionModuleType;
const recipients = collectModule.recipients ?? [];
const recipients = collectModule.recipients || [];
const splitTotal = recipients.reduce((acc, curr) => acc + curr.split, 0);
const hasEmptyRecipients = recipients.some(
(recipient) => !recipient.recipient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const SplitConfig: FC<SplitConfigProps> = ({
const currentProfile = useProfileStore((state) => state.currentProfile);
const collectModule = useCollectModuleStore((state) => state.collectModule);

const recipients = collectModule.recipients ?? [];
const hasRecipients = (recipients ?? []).length > 0;
const recipients = collectModule.recipients || [];
const hasRecipients = (recipients || []).length > 0;
const splitTotal = recipients?.reduce((acc, curr) => acc + curr.split, 0);

const splitEvenly = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Home/Highlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Highlights: FC = () => {
// Variables
const request: FeedHighlightsRequest = {
limit: LimitType.TwentyFive,
where: { for: seeThroughProfile?.id ?? currentProfile?.id }
where: { for: seeThroughProfile?.id || currentProfile?.id }
};

const { data, error, fetchMore, loading } = useFeedHighlightsQuery({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Home/SeeThroughLens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SeeThroughLens: FC = () => {
setRecommendedProfilesToSeeThrough(profiles?.slice(0, 5));
};

const profile = seeThroughProfile ?? currentProfile;
const profile = seeThroughProfile || currentProfile;
const request: FeedRequest = { where: { for: profile?.id } };

const [searchUsers, { data: searchUsersData, loading: searchUsersLoading }] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const RecommendedProfiles: FC = () => {

const { data, error, loading } = useProfileRecommendationsQuery({
variables: {
request: { for: seeThroughProfile?.id ?? currentProfile?.id }
request: { for: seeThroughProfile?.id || currentProfile?.id }
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Combined: FC<CombinedProps> = ({ feedItem }) => {
const mirrorsLength = mirrors.length;
const actedLength = acted.length;
const reactionsLength = reactions.length;
const commentsLength = comments?.length ?? 0;
const commentsLength = comments?.length || 0;

const getAllProfiles = () => {
let profiles = [...mirrors, ...acted, ...reactions, ...comments].map(
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/components/Home/Timeline/EventType/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ interface ActionTypeProps {
const ActionType: FC<ActionTypeProps> = ({ feedItem }) => {
const { acted, comments, mirrors, reactions, root } = feedItem;
const isComment = root.__typename === 'Comment';
const showThread = isComment || (comments?.length ?? 0) > 0;
const showThread = isComment || (comments?.length || 0) > 0;

const canCombined = getCanCombined([
mirrors?.length ?? 0,
reactions?.length ?? 0,
acted?.length ?? 0,
comments?.length ?? 0
mirrors?.length || 0,
reactions?.length || 0,
acted?.length || 0,
comments?.length || 0
]);

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Home/Timeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Timeline: FC = () => {
const request: FeedRequest = {
where: {
feedEventItemTypes: getFeedEventItems(),
for: seeThroughProfile?.id ?? currentProfile?.id
for: seeThroughProfile?.id || currentProfile?.id
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const MutualFollowers: FC<MutualFollowersProps> = ({
});

const profiles =
(data?.mutualFollowers?.items.slice(0, 4) as Profile[]) ?? [];
(data?.mutualFollowers?.items.slice(0, 4) as Profile[]) || [];

const Wrapper = ({ children }: { children: ReactNode }) => (
<div
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Publication/Poll/Choices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const Choices: FC<ChoicesProps> = ({ poll, refetch }) => {
<div className="flex items-center space-x-2 text-xs text-gray-500">
<Bars3BottomLeftIcon className="h-4 w-4" />
<span>
{humanize(totalResponses ?? 0)} {plur('vote', totalResponses || 0)}
{humanize(totalResponses || 0)} {plur('vote', totalResponses || 0)}
</span>
<span>·</span>
{new Date(endsAt) > new Date() ? (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Settings/Interests/Interests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Interests: FC = () => {
});

const interestsData = data?.profileInterestsOptions as ProfileInterestTypes[];
const selectedTopics = data?.profile?.interests ?? [];
const selectedTopics = data?.profile?.interests || [];

const onSelectTopic = (topic: ProfileInterestTypes) => {
const request: ProfileInterestsRequest = {
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Settings/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ const ProfileSettingsForm: FC<ProfileSettingsFormProps> = ({ profile }) => {

const form = useZodForm({
defaultValues: {
bio: profile?.metadata?.bio ?? '',
bio: profile?.metadata?.bio || '',
location: getProfileAttribute('location', profile?.metadata?.attributes),
name: profile?.metadata?.displayName ?? '',
name: profile?.metadata?.displayName || '',
website: getProfileAttribute('website', profile?.metadata?.attributes),
x: getProfileAttribute('x', profile?.metadata?.attributes)?.replace(
/(https:\/\/)?x\.com\//,
Expand Down Expand Up @@ -236,7 +236,7 @@ const ProfileSettingsForm: FC<ProfileSettingsFormProps> = ({ profile }) => {
key,
type: MetadataAttributeType[type] as any,
value
})) ?? [];
})) || [];

const preparedProfileMetadata: ProfileOptions = {
...(data.name && { name: data.name }),
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Audio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const Audio: FC<AudioProps> = ({
<>
<h5 className="truncate text-lg text-white">{title}</h5>
<h6 className="truncate text-white/70">
{artist ??
{artist ||
getProfile(publication?.by as Profile).displayName}
</h6>
</>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/FeedFocusType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const FeedFocusType: FC<FeedFocusTypeProps> = ({ focus, setFocus }) => {
onClick={() => {
setFocus(type as PublicationMetadataMainFocusType);
Leafwatch.track(EXPLORE.SWITCH_EXPLORE_FEED_FOCUS, {
explore_feed_focus: (type ?? 'all_posts').toLowerCase()
explore_feed_focus: (type || 'all_posts').toLowerCase()
});
}}
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class MentionNode extends TextNode {
__mention: string;

constructor(mentionName: string, text?: string, key?: NodeKey) {
super(text ?? `@${mentionName}`, key);
super(text || `@${mentionName}`, key);
this.__mention = `@${mentionName}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const MentionsPlugin: FC = () => {
.map(({ displayHandle, handle, id, name, picture }) => {
return new MentionTypeaheadOption(
id,
name ?? handle,
name || handle,
handle,
displayHandle,
picture
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Login/WalletSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const WalletSelector: FC<WalletSelectorProps> = ({
{error?.message ? (
<div className="flex items-center space-x-1 text-red-500">
<XCircleIcon className="h-5 w-5" />
<div>{error?.message ?? 'Failed to connect'}</div>
<div>{error?.message || 'Failed to connect'}</div>
</div>
) : null}
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Modal/Invites/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Invites: FC = () => {
return (
<div className="max-h-[80vh] overflow-y-auto p-5">
<Invite
invitesLeft={currentProfile?.invitesLeft ?? 0}
invitesLeft={currentProfile?.invitesLeft || 0}
refetch={refetch}
/>
<div className="divider my-5" />
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/UserPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const UserPreview: FC<UserPreviewProps> = ({
<div />
</div>
<div className="flex p-3">
<div>{handle ?? `#${id}`}</div>
<div>{handle || `#${id}`}</div>
</div>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/StaffTools/Panels/Publication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ const PublicationStaffTool: FC<PublicationStaffToolProps> = ({
noFlex
title="Open action modules"
>
{(targetPublication?.openActionModules ?? []).map((module) => (
{(targetPublication?.openActionModules || []).map((module) => (
<div key={module.__typename}>{module.__typename}</div>
))}
</MetaDetails>
) : null}
{(targetPublication?.metadata.tags ?? []).length > 0 ? (
{(targetPublication?.metadata.tags || []).length > 0 ? (
<MetaDetails
icon={<TagIcon className="ld-text-gray-500 h-4 w-4" />}
noFlex
title="Tags"
>
{(targetPublication?.metadata?.tags ?? []).map((tag) => (
{(targetPublication?.metadata?.tags || []).map((tag) => (
<div key={tag}>{tag}</div>
))}
</MetaDetails>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Support/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Support: NextPage = () => {
if (data.success) {
setSubmitted(true);
} else {
toast.error(data?.message ?? Errors.SomethingWentWrong);
toast.error(data?.message || Errors.SomethingWentWrong);
}
} finally {
setSubmitting(false);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/errorToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const errorToast = (error: any) => {
}

toast.error(
error?.data?.message ?? error?.message ?? Errors.SomethingWentWrong
error?.data?.message || error?.message || Errors.SomethingWentWrong
);
};

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/lib/uploadToIPFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ const uploadToIPFS = async (
params
});
task.on('httpUploadProgress', (e) => {
const loaded = e.loaded ?? 0;
const total = e.total ?? 0;
const loaded = e.loaded || 0;
const total = e.total || 0;
const progress = (loaded / total) * 100;
onProgress?.(Math.round(progress));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getEnvConfig from './utils/getEnvConfig';
export const IS_PRODUCTION = process.env.NEXT_PUBLIC_IS_PRODUCTION === 'true';

// Lens and Hey Env Config
export const LENS_NETWORK = process.env.NEXT_PUBLIC_LENS_NETWORK ?? 'mainnet';
export const LENS_NETWORK = process.env.NEXT_PUBLIC_LENS_NETWORK || 'mainnet';

export const LENS_API_URL = getEnvConfig().lensApiEndpoint;
export const HEY_API_URL = IS_PRODUCTION
Expand Down
4 changes: 2 additions & 2 deletions packages/lens/apollo/lib/cursorBasedPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const cursorBasedPagination = <T extends CursorBasedPagination>(
return incoming;
}

const existingItems = existing.items ?? [];
const incomingItems = incoming.items ?? [];
const existingItems = existing.items || [];
const incomingItems = incoming.items || [];

return {
...incoming,
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/getAssetSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TOKEN_SYMBOLS: TokenSymbolMap = {
* @returns The symbol of the token.
*/
const getAssetSymbol = (symbol: string): string => {
return TOKEN_SYMBOLS[symbol] ?? 'MATIC';
return TOKEN_SYMBOLS[symbol] || 'MATIC';
};

export default getAssetSymbol;
10 changes: 5 additions & 5 deletions packages/lib/getAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import sanitizeDStorageUrl from './sanitizeDStorageUrl';
const getAvatar = (profile: any, namedTransform = AVATAR): string => {
const avatarUrl =
// Group Avatar fallbacks
profile?.avatar ??
profile?.avatar ||
// Lens NFT Avatar fallbacks
profile?.metadata?.picture?.image?.optimized?.uri ??
profile?.metadata?.picture?.image?.raw?.uri ??
profile?.metadata?.picture?.image?.optimized?.uri ||
profile?.metadata?.picture?.image?.raw?.uri ||
// Lens Profile Avatar fallbacks
profile?.metadata?.picture?.optimized?.uri ??
profile?.metadata?.picture?.raw?.uri ??
profile?.metadata?.picture?.optimized?.uri ||
profile?.metadata?.picture?.raw?.uri ||
// Stamp.fyi Avatar fallbacks
getLennyURL(profile.id);

Expand Down
2 changes: 1 addition & 1 deletion packages/lib/getFollowModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const FOLLOW_MODULE_MAP: Record<string, FollowModule> = {
* @returns The follow module object.
*/
const getFollowModule = (name?: string): FollowModule => {
return FOLLOW_MODULE_MAP[name ?? ''] ?? { description: 'Anyone can follow' };
return FOLLOW_MODULE_MAP[name || ''] || { description: 'Anyone can follow' };
};

export default getFollowModule;
2 changes: 1 addition & 1 deletion packages/lib/getProfileAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getProfileAttribute = (
attributes: Maybe<MetadataAttribute[]> = []
): string => {
const attribute = attributes?.find((attr) => attr.key === key);
return attribute?.value ?? '';
return attribute?.value || '';
};

export default getProfileAttribute;
2 changes: 1 addition & 1 deletion packages/lib/getPublicationAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getPublicationAttribute = (
key: string
): string => {
const attribute = attributes?.find((attr) => attr.key === key);
return attribute?.value ?? '';
return attribute?.value || '';
};

export default getPublicationAttribute;
2 changes: 1 addition & 1 deletion packages/lib/getTokenImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { STATIC_IMAGES_URL } from '@hey/data/constants';
* @returns The token image URL.
*/
const getTokenImage = (symbol: string): string => {
const symbolLowerCase = symbol?.toLowerCase() ?? '';
const symbolLowerCase = symbol?.toLowerCase() || '';
return `${STATIC_IMAGES_URL}/tokens/${symbolLowerCase}.svg`;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/LightBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const LightBox: FC<LightBoxProps> = ({ onClose, show, url }) => {
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<img
alt={url ?? ''}
alt={url || ''}
className="max-h-screen"
height={1000}
onClick={onClose}
src={url ?? ''}
src={url || ''}
width={1000}
/>
{url ? (
Expand Down
Loading