Commit 7a685d64 authored by johnnyjoy's avatar johnnyjoy

fix: fetch user by username

parent 1ebe2e9a
...@@ -32,7 +32,7 @@ const UserProfile = () => { ...@@ -32,7 +32,7 @@ const UserProfile = () => {
} }
userStore userStore
.getOrFetchUserByName(username) .fetchUserByUsername(username)
.then((user) => { .then((user) => {
setUser(user); setUser(user);
loadingState.setFinish(); loadingState.setFinish();
......
...@@ -40,6 +40,19 @@ const userStore = (() => { ...@@ -40,6 +40,19 @@ const userStore = (() => {
return user; return user;
}; };
const fetchUserByUsername = async (username: string) => {
const user = await userServiceClient.getUser({
name: username,
});
state.setPartial({
userMapByName: {
...state.userMapByName,
[user.name]: user,
},
});
return user;
};
const getUserByName = (name: string) => { const getUserByName = (name: string) => {
return state.userMapByName[name]; return state.userMapByName[name];
}; };
...@@ -128,6 +141,7 @@ const userStore = (() => { ...@@ -128,6 +141,7 @@ const userStore = (() => {
return { return {
state, state,
getOrFetchUserByName, getOrFetchUserByName,
fetchUserByUsername,
getUserByName, getUserByName,
fetchUsers, fetchUsers,
updateUser, updateUser,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment