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

[USERS SUB-PR] Changes profile loading logic #1081

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 12 additions & 1 deletion src/hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WithId } from "utils/id";
import { authSelector, profileSelector } from "utils/selectors";

import { useSelector } from "hooks/useSelector";
import { useFirestoreConnect } from "hooks/useFirestoreConnect";

type UseUserResult = {
user: FirebaseReducer.AuthState | undefined;
Expand All @@ -17,9 +18,19 @@ export const useUser = (): UseUserResult => {
const auth = useSelector(authSelector);
const profile = useSelector(profileSelector);

useFirestoreConnect(
auth.uid
? {
collection: "users",
doc: auth.uid,
storeAs: "profile",
}
: undefined
);

return {
user: !auth.isEmpty ? auth : undefined,
profile: !profile.isEmpty ? profile : undefined,
profile: profile && !profile.isEmpty ? profile : undefined,
userWithId: auth && profile ? { ...profile, id: auth.uid } : undefined,
};
};
57 changes: 20 additions & 37 deletions src/hooks/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,35 @@ import { WithId } from "utils/id";

import { useSelector } from "./useSelector";
import { useUserLastSeenThreshold } from "./useUserLastSeenThreshold";
import { useConnectCurrentVenueNG } from "./useConnectCurrentVenueNG";
import { useVenueId } from "./useVenueId";
import { useFirestoreConnect, isLoaded } from "./useFirestoreConnect";

import { User } from "types/User";

export const useConnectWorldUsers = () => {
const venueId = useVenueId();

const { isCurrentVenueLoaded, currentVenue } = useConnectCurrentVenueNG(
venueId!
);

// useFirestoreConnect(() => {
// if (!isCurrentVenueLoaded || !currentVenue) return [];

// console.log(currentVenue.parentId, currentVenue.id);

// return [
// {
// collection: "users",
// where: ["enteredVenueIds", "array-contains", venueId],
// storeAs: "worldUsers",
// },
// ];
// });

useFirestoreConnect(
isCurrentVenueLoaded && currentVenue
? {
collection: "users",
where: ["enteredVenueIds", "array-contains", venueId],
storeAs: "worldUsers",
}
: undefined
);
import { Venue } from "types/Venue";

export const useConnectWorldUsers = (venue?: WithId<Venue>) => {
useFirestoreConnect(() => {
const venueId = venue?.id;

if (!venueId) return [];

return [
{
collection: "users",
where: [
"enteredVenueIds",
"array-contains",
venue?.parentId || venueId,
],
storeAs: "worldUsers",
},
];
});
};

export const useWorldUsers = (): {
worldUsers: readonly WithId<User>[];
isWorldUsersLoaded: boolean;
} => {
// useConnectWorldUsers();

const selectedUniverseUsers = useSelector(worldUsersSelector);

console.log("users", selectedUniverseUsers);
Expand Down Expand Up @@ -82,8 +67,6 @@ export const useRecentWorldUsers = (): {
};

export const useWorldUsersById = () => {
// useConnectWorldUsers();

const worldUsersById = useSelector(usersByIdSelector);

return useMemo(() => worldUsersById, [worldUsersById]);
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ if (LOGROCKET_APP_ID) {
const stripePromise = loadStripe(STRIPE_PUBLISHABLE_KEY ?? "");

const rrfConfig = {
userProfile: "users",
useFirestoreForProfile: true,
// userProfile: "user",
// useFirestoreForProfile: true,
oneListenerPerPath: true,
allowMultipleListeners: false,
};
Expand Down
35 changes: 26 additions & 9 deletions src/pages/VenuePage/VenuePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import {
useLocationUpdateEffect,
} from "utils/useLocationUpdateEffect";
import { venueEntranceUrl } from "utils/url";
import { isCompleteProfile, updateProfileEnteredVenueIds } from "utils/profile";
import { isTruthy } from "utils/types";
import { showZendeskWidget } from "utils/zendesk";

import { updateTheme } from "./helpers";
import { updateUserProfile } from "pages/Account/helpers";

import { useConnectCurrentEvent } from "hooks/useConnectCurrentEvent";
import { useConnectUserPurchaseHistory } from "hooks/useConnectUserPurchaseHistory";
Expand All @@ -36,21 +42,32 @@ import { useSelector } from "hooks/useSelector";
import { useUser } from "hooks/useUser";
import { useVenueId } from "hooks/useVenueId";
import { useFirestoreConnect } from "hooks/useFirestoreConnect";
import { useConnectWorldUsers, useWorldUsers } from "hooks/users";
import { useConnectCurrentVenueNG } from "hooks/useConnectCurrentVenueNG";
import useConnectCurrentVenue from "hooks/useConnectCurrentVenue";

import { updateUserProfile } from "pages/Account/helpers";
import Login from "pages/Account/Login";

import { CountDown } from "components/molecules/CountDown";
import { LoadingPage } from "components/molecules/LoadingPage/LoadingPage";
import TemplateWrapper from "./TemplateWrapper";

import { updateTheme } from "./helpers";

import "./VenuePage.scss";
import useConnectCurrentVenue from "hooks/useConnectCurrentVenue";
import { isCompleteProfile, updateProfileEnteredVenueIds } from "utils/profile";
import { isTruthy } from "utils/types";
import Login from "pages/Account/Login";
import { showZendeskWidget } from "utils/zendesk";

const VenueDataWrapper = () => {
const venueId = useVenueId();
const { currentVenue, isCurrentVenueLoaded } = useConnectCurrentVenueNG(
venueId!
);
useConnectWorldUsers(currentVenue);

const { isWorldUsersLoaded } = useWorldUsers();

if (!isCurrentVenueLoaded || !currentVenue || !isWorldUsersLoaded)
return <LoadingPage />;

return <VenuePage />;
};

const hasPaidEvents = (template: VenueTemplate) => {
return template === VenueTemplate.jazzbar;
Expand Down Expand Up @@ -296,4 +313,4 @@ const VenuePage: React.FC = () => {
return <TemplateWrapper venue={venue} />;
};

export default VenuePage;
export default VenueDataWrapper;
3 changes: 3 additions & 0 deletions src/types/Firestore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FirebaseReducer } from "react-redux-firebase";

import { AdminRole } from "hooks/roles";

import { PrivateChatMessage, RestrictedChatMessage } from "store/actions/Chat";
Expand Down Expand Up @@ -77,6 +79,7 @@ export interface FirestoreData {
venueChats?: Record<string, RestrictedChatMessage>;
venueEvents?: Record<string, VenueEvent>;
venues?: Record<string, AnyVenue>;
profile: FirebaseReducer.Profile<User>;
}

// note: these entries should be sorted alphabetically
Expand Down
2 changes: 1 addition & 1 deletion src/utils/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const authSelector: SparkleSelector<FirebaseReducer.AuthState> = (
*/
export const profileSelector: SparkleSelector<FirebaseReducer.Profile<User>> = (
state
) => state.firebase.profile;
) => state.firestore.data.profile;

/**
* Selector to retrieve currentVenue?.[0] from the Redux Firestore.
Expand Down