Skip to content

Commit 4675020

Browse files
committed
Adjust naming
1 parent ab0d9c0 commit 4675020

File tree

11 files changed

+88
-72
lines changed

11 files changed

+88
-72
lines changed

src/app/_components/AllProjects.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Filter, { Group } from "@/common/ui/components/Filter";
99
import InfiniteScroll from "@/common/ui/components/InfiniteScroll";
1010
import SearchBar from "@/common/ui/components/SearchBar";
1111
import SortSelect from "@/common/ui/components/SortSelect";
12-
import { UserState } from "@/modules/profile/models";
12+
import { Profile } from "@/modules/profile/models";
1313

1414
import Card from "../../modules/project/components/Card";
1515
import { categories, statuses } from "../../modules/project/constants";
@@ -76,20 +76,20 @@ const AllProjects = () => {
7676
}
7777
};
7878

79-
const registrationsProfile = useTypedSelector((state) => state.users);
79+
const registrationsProfile = useTypedSelector((state) => state.profiles);
8080

8181
// handle search & filter
8282
useEffect(() => {
8383
// Search
84-
const handleSearch = (registration: Registration, user: UserState) => {
84+
const handleSearch = (registration: Registration, profile: Profile) => {
8585
if (search === "") return true;
8686
const { registrant_id: registrantId } = registration;
87-
const { profile, tags, team } = user || {};
87+
const { socialData, tags, team } = profile || {};
8888
// registration fields to search in
8989
const fields = [
9090
registrantId,
91-
profile?.description,
92-
profile?.name,
91+
socialData?.description,
92+
socialData?.name,
9393
tags?.join(" "),
9494
team?.join(" "),
9595
];
@@ -104,27 +104,33 @@ const AllProjects = () => {
104104
return statusFilter.includes(registration.status);
105105
};
106106
// Filter by registration category
107-
const handleCategory = (user: UserState) => {
108-
const tags = user.tags || [];
107+
const handleCategory = (profile: Profile) => {
108+
const tags = profile.tags || [];
109109

110110
if (categoryFilter.length === 0) return true;
111111
return categoryFilter.some((tag: string) => tags.includes(tag));
112112
};
113113

114114
if (search || categoryFilter.length || statusFilter.length) {
115115
const filteredRegistrations = registrations.filter((registration) => {
116-
const user = registrationsProfile[registration.registrant_id] || {};
116+
const profile = registrationsProfile[registration.registrant_id] || {};
117117

118118
return (
119-
handleSearch(registration, user) &&
120-
handleCategory(user) &&
119+
handleSearch(registration, profile) &&
120+
handleCategory(profile) &&
121121
handleStatus(registration)
122122
);
123123
});
124124

125125
setFilteredRegistrations(filteredRegistrations);
126126
}
127-
}, [search, categoryFilter, statusFilter, registrations]);
127+
}, [
128+
search,
129+
categoryFilter,
130+
statusFilter,
131+
registrations,
132+
registrationsProfile,
133+
]);
128134

129135
// Fetch Registrations
130136
useEffect(() => {

src/app/_components/UserDropdown.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { Skeleton } from "@/common/ui/components/skeleton";
2020
import useWallet from "@/modules/auth/hooks/useWallet";
2121
import { statusesIcons } from "@/modules/core/constants";
2222
import useRegistration from "@/modules/core/hooks/useRegistration";
23-
import { fetchProfileImages } from "@/modules/core/services/fetchProfileImages";
24-
import { DEFAULT_USER } from "@/modules/profile/constants";
23+
import { fetchSocialImages } from "@/modules/core/services/socialImages";
24+
import { PROFILE_DEFAULTS } from "@/modules/profile/constants";
2525
import {
2626
updateAccountId,
2727
updateNadabotVerification,
@@ -46,7 +46,7 @@ const UserDropdown = () => {
4646

4747
useEffect(() => {
4848
const fetchProfileImage = async () => {
49-
const { image, profile } = await fetchProfileImages({
49+
const { image, profile } = await fetchSocialImages({
5050
accountId,
5151
});
5252
setProfileImg(image);
@@ -83,7 +83,7 @@ const UserDropdown = () => {
8383
width={size}
8484
height={size}
8585
onError={() => {
86-
setProfileImg(DEFAULT_USER.profileImages.image);
86+
setProfileImg(PROFILE_DEFAULTS.socialImages.image);
8787
}}
8888
className="rounded-full shadow-[0px_0px_0px_1px_rgba(199,199,199,0.22)_inset]"
8989
alt="profile-image"

src/app/_store/models.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Models } from "@rematch/core";
22

33
import { auth } from "@/modules/auth/state";
4-
import { navModel, usersModel } from "@/modules/profile/models";
4+
import { navModel, profilesModel } from "@/modules/profile/models";
55

66
export interface RootModel extends Models<RootModel> {
77
auth: typeof auth;
8-
users: typeof usersModel;
8+
profiles: typeof profilesModel;
99
nav: typeof navModel;
1010
}
1111

12-
export const models: RootModel = { auth, users: usersModel, nav: navModel };
12+
export const models: RootModel = {
13+
auth,
14+
profiles: profilesModel,
15+
nav: navModel,
16+
};

src/common/contracts/social/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ type NEARSocialGetResponse = {
112112
* Get User Profile Info from NEAR Social DB
113113
* @returns
114114
*/
115-
export const getUserProfile = async (input: { accountId: string }) => {
115+
export const getSocialProfile = async (input: { accountId: string }) => {
116116
const response = await nearSocialDbContractApi.view<
117117
NEARSocialUserProfileInput,
118118
NEARSocialGetResponse

src/common/lib/images.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { naxiosInstance } from "@/common/contracts/index";
2-
import { Image, getUserProfile } from "@/common/contracts/social";
2+
import { Image, getSocialProfile } from "@/common/contracts/social";
33

44
type Props = {
55
accountId?: string;
@@ -41,7 +41,7 @@ export const getImage = async ({
4141

4242
try {
4343
if (!socialImage && accountId) {
44-
const profile = await getUserProfile({ accountId });
44+
const profile = await getSocialProfile({ accountId });
4545
if (!profile) return console.log("error fetching social profile");
4646

4747
socialImage = profile[type || "image"];

src/modules/core/services/fetchProfileImages.ts src/modules/core/services/socialImages.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
NEARSocialUserProfile,
3-
getUserProfile,
3+
getSocialProfile,
44
} from "@/common/contracts/social";
55
import { getImage } from "@/common/lib/images";
66

77
type Props = {
8-
profile?: NEARSocialUserProfile;
8+
socialData?: NEARSocialUserProfile;
99
accountId: string;
1010
};
1111

@@ -14,11 +14,11 @@ type Props = {
1414
* @param
1515
* @returns
1616
*/
17-
export const fetchProfileImages = async ({ profile, accountId }: Props) => {
18-
let currentProfile = profile;
17+
export const fetchSocialImages = async ({ socialData, accountId }: Props) => {
18+
let currentProfile = socialData;
1919

2020
if (!currentProfile) {
21-
currentProfile = await getUserProfile({ accountId });
21+
currentProfile = await getSocialProfile({ accountId });
2222
}
2323

2424
const image = getImage({

src/modules/profile/components/ProfileBanner.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { Skeleton } from "@/common/ui/components/skeleton";
1414
import useIsHuman from "@/modules/core/hooks/useIsHuman";
1515
import useRegistration from "@/modules/core/hooks/useRegistration";
16-
import { fetchProfileImages } from "@/modules/core/services/fetchProfileImages";
16+
import { fetchSocialImages } from "@/modules/core/services/socialImages";
1717
import { projectStatusIcons } from "@/modules/project/components/ProjectStatusIcons";
1818

1919
import FollowStats from "./FollowStats";
@@ -37,7 +37,10 @@ const ProfileBanner = (props: Props) => {
3737

3838
useEffect(() => {
3939
(async () => {
40-
const imagesData = await fetchProfileImages({ profile, accountId });
40+
const imagesData = await fetchSocialImages({
41+
socialData: profile,
42+
accountId,
43+
});
4144

4245
setProfileImages({
4346
image: imagesData.image,

src/modules/profile/constants.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
export const DEFAULT_USER = {
2-
profile: {},
1+
import { Profile } from "./models";
2+
3+
export const PROFILE_DEFAULTS: Profile = {
4+
socialData: {},
35
tags: [],
6+
team: [],
47
totalAmountNear: "",
5-
profileImages: {
8+
9+
socialImages: {
610
image: "/assets/images/profile-image.png",
711
backgroundImage: "/assets/images/profile-banner.png",
812
},

src/modules/profile/models.ts

+25-28
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,43 @@ import { PayoutDetailed } from "@/common/contracts/potlock/interfaces/pot.interf
66
import { getDonationsForProject } from "@/common/contracts/potlock/pot";
77
import {
88
NEARSocialUserProfile,
9-
getUserProfile,
9+
getSocialProfile,
1010
} from "@/common/contracts/social";
1111
import { yoctosToUsdWithFallback } from "@/common/lib";
1212

13-
import { fetchProfileImages } from "../core/services/fetchProfileImages";
13+
import { fetchSocialImages } from "../core/services/socialImages";
1414
import {
1515
getTagsFromSocialProfileData,
1616
getTeamMembersFromProfile,
1717
getTotalAmountNear,
1818
} from "../project/utils";
1919

20-
export type UserState = {
21-
profile: NEARSocialUserProfile;
20+
export type Profile = {
21+
socialData: NEARSocialUserProfile;
2222
tags: string[];
2323
team: string[];
2424
totalAmountNear: string;
25-
profileImages: {
25+
26+
socialImages: {
2627
image: string;
2728
backgroundImage: string;
2829
};
2930
};
30-
type Users = Record<string, UserState>;
3131

32-
export const usersModel = createModel<RootModel>()({
33-
state: {} as Users,
32+
type ProfileIndex = Record<string, Profile>;
33+
34+
export const profilesModel = createModel<RootModel>()({
35+
state: {} as ProfileIndex,
3436
reducers: {
35-
update(state, payload: Users) {
37+
update(state, payload: ProfileIndex) {
3638
return {
3739
...state,
3840
...payload,
3941
};
4042
},
4143
},
4244
effects: {
43-
async loadUser({
45+
async loadProfile({
4446
projectId,
4547
potId,
4648
payoutDetails,
@@ -49,12 +51,12 @@ export const usersModel = createModel<RootModel>()({
4951
potId?: string;
5052
payoutDetails?: PayoutDetailed;
5153
}) {
52-
const profile = await getUserProfile({
54+
const socialData = await getSocialProfile({
5355
accountId: projectId,
5456
});
5557

56-
const profileImagesPromise = fetchProfileImages({
57-
profile,
58+
const socialImagesResponse = fetchSocialImages({
59+
socialData,
5860
accountId: projectId,
5961
});
6062

@@ -70,29 +72,24 @@ export const usersModel = createModel<RootModel>()({
7072
})
7173
: Promise.resolve([]);
7274

73-
const [profileImages, donations] = await Promise.all([
74-
profileImagesPromise,
75+
const [socialImages, donations] = await Promise.all([
76+
socialImagesResponse,
7577
donationsPromise,
7678
]);
7779

7880
const totalAmountNear = await yoctosToUsdWithFallback(
7981
getTotalAmountNear(donations, potId, payoutDetails),
8082
);
8183

82-
const tags = getTagsFromSocialProfileData(profile || {});
83-
const team = getTeamMembersFromProfile(profile);
84-
85-
const user = {
86-
[projectId]: {
87-
profile: profile ?? {},
88-
tags,
89-
team,
90-
totalAmountNear,
91-
profileImages,
92-
},
84+
const profile: Profile = {
85+
socialData: socialData ?? {},
86+
tags: getTagsFromSocialProfileData(socialData || {}),
87+
team: getTeamMembersFromProfile(socialData),
88+
totalAmountNear,
89+
socialImages,
9390
};
9491

95-
this.update(user);
92+
this.update({ [projectId]: profile });
9693
},
9794
},
9895
});
@@ -123,7 +120,7 @@ const updateList = (list: string[], item: string): string[] => {
123120

124121
export const navModel = createModel<RootModel>()({
125122
state: {
126-
// TODO: add is registery admin
123+
// TODO: add is registry admin
127124
accountId: "",
128125
isNadabotVerified: false,
129126
actAsDao: {

src/modules/profile/utils/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { dispatch, useTypedSelector } from "@/app/_store";
22

3-
import { DEFAULT_USER } from "../constants";
3+
import { PROFILE_DEFAULTS } from "../constants";
4+
import { Profile } from "../models";
45

5-
export const useUser = (projectId: string) =>
6-
useTypedSelector((state) => state.users[projectId] || DEFAULT_USER);
6+
export const useProfile = (projectId: string): Profile =>
7+
useTypedSelector((state) => state.profiles[projectId] || PROFILE_DEFAULTS);
78

89
export const toggleDao = (toggle: boolean) =>
910
dispatch.nav.update({

0 commit comments

Comments
 (0)