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

Fix/profile not found errors #225

Merged
merged 24 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
83d2b69
fix(ui): use console.error instead of toast for 2 passive errors
mattyg Sep 8, 2023
c4cc672
fix(ui): follow users without profile data
mattyg Sep 8, 2023
400efb9
chore(ui): remove unused callZomes from profile
mattyg Sep 8, 2023
c84c41f
fix(ui): creators and followers lists still display agents with missi…
mattyg Sep 8, 2023
23f05c1
fix(ui): split agent profile & joined timestamp fetching in AgentProf…
mattyg Sep 8, 2023
7dc2ca3
Merge branch 'main' into fix/profile-not-found-errors
mattyg Sep 9, 2023
fa75ef7
fix(ui): split agent profile & joined timestamp fetching in AgentProf…
mattyg Sep 9, 2023
841efbd
revert(ui): remove profile placeholders
mattyg Sep 9, 2023
c884d1a
build(ui): bump tanstack deps
mattyg Sep 9, 2023
17c4270
fix(ui): ensure tanstack query key is reactively updated when agentPu…
mattyg Sep 9, 2023
94f9a87
fix(ui): extract list of random mews by tag into seperate component, …
mattyg Sep 9, 2023
f8f384c
fix(ui): wrap props in computed before using in tanstack queryKey to …
mattyg Sep 9, 2023
604dc93
fix(ui): avoid console error
mattyg Sep 9, 2023
3bd701a
fix(ui): more computeds
mattyg Sep 9, 2023
d46d1fe
Merge branch 'fix/profile-not-found-errors' into fix/profile-popup-da…
mattyg Sep 9, 2023
020d64b
chore(ui): rm console log
mattyg Sep 9, 2023
3885216
fix(ui): zome call payload incorrect
mattyg Sep 9, 2023
515ae86
Merge pull request #230 from GeekGene/fix/profile-popup-data-incorrect
mattyg Sep 11, 2023
2c7f9f8
Merge branch 'main' into fix/profile-not-found-errors
mattyg Sep 11, 2023
9428059
fix(ui): refetch followers / creators lists upon opening dialog
mattyg Sep 11, 2023
1fb4345
fix(ui): spacing between <name> followed you
mattyg Sep 11, 2023
de5b1db
fix(ui): do not abbreviate agentpubkey when used as primary displayed…
mattyg Sep 11, 2023
cb534ad
chore(ui): remove unnecessary filters
mattyg Sep 11, 2023
fb5a49a
chore(ui): fix ts lint
mattyg Sep 11, 2023
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
63 changes: 40 additions & 23 deletions ui/src/components/AgentProfileDetail.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<template>
<BaseAgentProfileDetail
v-if="profileWithContext"
:profile="profileWithContext.profile"
:profile="profile"
:agentPubKey="props.agentPubKey"
:joined-timestamp="profileWithContext.joinedTimestamp"
:joined-timestamp="joinedTimestamp"
:hide-edit-button="hideEditButton"
v-bind="$attrs"
/>
</template>

<script setup lang="ts">
import { useToasts } from "@/stores/toasts";
import { AgentPubKey, AppAgentClient } from "@holochain/client";
import { ComputedRef, inject, watch } from "vue";
import { ProfilesStore } from "@holochain-open-dev/profiles";
import BaseAgentProfileDetail from "@/components/BaseAgentProfileDetail.vue";
import { useQuery } from "@tanstack/vue-query";
import { encodeHashToBase64 } from "@holochain/client";

const props = withDefaults(
defineProps<{
Expand All @@ -30,38 +29,56 @@ const props = withDefaults(
const profilesStore = (inject("profilesStore") as ComputedRef<ProfilesStore>)
.value;
const client = (inject("client") as ComputedRef<AppAgentClient>).value;
const { showError } = useToasts();

const fetchProfileWithContext = async () => {
const fetchProfile = async () => {
const profile = await profilesStore.client.getAgentProfile(props.agentPubKey);
const joinedTimestamp = await client.callZome({
role_name: "mewsfeed",
zome_name: "profiles",
fn_name: "get_joining_timestamp_for_agent",
payload: props.agentPubKey,
});

if (profile) {
return {
profile,
joinedTimestamp,
};
return profile;
} else {
throw new Error("No profile found");
}
};

const {
data: profileWithContext,
data: profile,
error: errorProfile,
refetch,
refetch: refetchProfile,
} = useQuery({
queryKey: [
"profiles",
"getAgentProfile",
encodeHashToBase64(props.agentPubKey),
],
queryFn: fetchProfile,
refetchOnMount: true,
});
watch(errorProfile, console.error);

const fetchJoinedTimestamp = async () =>
client.callZome({
role_name: "mewsfeed",
zome_name: "profiles",
fn_name: "get_joining_timestamp_for_agent",
payload: props.agentPubKey,
});

const {
data: joinedTimestamp,
error: errorJoinedTimestamp,
refetch: refetchJoinedTimestamp,
} = useQuery({
queryKey: ["profiles", "getAgentProfile", props.agentPubKey],
queryFn: fetchProfileWithContext,
queryKey: [
"profiles",
"get_joining_timestamp_for_agent",
encodeHashToBase64(props.agentPubKey),
],
queryFn: fetchJoinedTimestamp,
refetchOnMount: true,
});
watch(errorProfile, showError);
watch(errorJoinedTimestamp, console.error);

watch(props, () => {
refetch();
refetchProfile();
refetchJoinedTimestamp();
});
</script>
1 change: 0 additions & 1 deletion ui/src/components/BaseAgentProfile.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div class="flex justify-start items-center space-x-2">
<agent-avatar
v-if="profile"
:agentPubKey="agentPubKey"
size="20"
disable-tooltip
Expand Down
11 changes: 4 additions & 7 deletions ui/src/components/BaseAgentProfileDetail.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<template>
<div
v-if="profile"
class="h-full w-full text-base-content font-content font-normal"
v-bind="$attrs"
>
<div class="flex space-x-6 h-full p-4">
<div class="flex flex-col justify-between">
<div
v-tooltip.bottom="{
disabled: !!profile.fields.avatar,
disabled: profile && !!profile.fields.avatar,
content: encodeHashToBase64(agentPubKey),
popperClass: 'text-xs',
triggers: ['hover'],
Expand Down Expand Up @@ -59,7 +58,7 @@
</div>

<div
v-if="profile.fields.avatar"
v-if="profile?.fields.avatar"
v-tooltip.bottom="{
content: encodeHashToBase64(agentPubKey),
popperClass: 'text-xs',
Expand Down Expand Up @@ -110,7 +109,7 @@
</div>

<div
v-if="profile.fields[PROFILE_FIELDS.BIO]"
v-if="profile?.fields[PROFILE_FIELDS.BIO]"
class="flex justify-start space-x-2 text-md mb-5"
>
{{ profile.fields[PROFILE_FIELDS.BIO] }}
Expand Down Expand Up @@ -157,7 +156,7 @@
class="flex justify-start items-center space-x-2 sm:space-x-16 text-xs mt-3"
>
<div
v-if="profile.fields[PROFILE_FIELDS.LOCATION]"
v-if="profile?.fields[PROFILE_FIELDS.LOCATION]"
class="flex justify-start items-center space-x-2 text-xs font-mono px-2"
>
<IconNavigateCircleOutline />
Expand All @@ -176,7 +175,6 @@
</div>
</div>
</div>
<BaseAgentProfileDetailSkeleton v-else />
</template>

<script setup lang="ts">
Expand All @@ -195,7 +193,6 @@ import IconNavigateCircleOutline from "~icons/ion/navigate-circle-outline";
import IconCalendarOutline from "~icons/ion/calendar-outline";
import IconPencilSharp from "~icons/ion/pencil-sharp";
import { Timestamp } from "@holochain/client";
import BaseAgentProfileDetailSkeleton from "@/components/BaseAgentProfileDetailSkeleton.vue";
import BaseCopyOnClick from "@/components/BaseCopyOnClick.vue";

const props = withDefaults(
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/BaseAgentProfileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
:is-loading="loading"
>
<BaseAgentProfileListItem
:agent-profile="item"
:agent-pub-key="item.agentPubKey"
:profile="item.profile"
:enable-popup="enablePopups"
class="cursor-pointer py-3"
@click="
Expand Down
13 changes: 8 additions & 5 deletions ui/src/components/BaseAgentProfileListItem.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
<template>
<div class="flex justify-start items-center space-x-4">
<BaseAgentProfileLinkAvatar
:agentPubKey="agentProfile.agentPubKey"
:agentPubKey="agentPubKey"
:size="50"
:enable-popup="enablePopup"
/>
<BaseAgentProfileName
class="text-lg"
:profile="agentProfile.profile"
:agentPubKey="agentProfile.agentPubKey"
:profile="profile"
:agentPubKey="agentPubKey"
/>
</div>
</template>

<script setup lang="ts">
import { AgentProfile } from "@/types/types";
import BaseAgentProfileLinkAvatar from "@/components/BaseAgentProfileLinkAvatar.vue";
import BaseAgentProfileName from "@/components/BaseAgentProfileName.vue";
import { AgentPubKey } from "@holochain/client";
import { Profile } from "@holochain-open-dev/profiles";

withDefaults(
defineProps<{
agentProfile: AgentProfile;
agentPubKey: AgentPubKey;
profile?: Profile;
enablePopup?: boolean;
}>(),
{
enablePopup: true,
profile: undefined,
}
);
</script>
56 changes: 32 additions & 24 deletions ui/src/components/ButtonFollow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const {
],
queryFn: fetchMyFollowing,
});
watch(errorMyFollowing, showError);
watch(errorMyFollowing, console.error);
watch(props, () => {
refetchMyFollowing();
});
Expand All @@ -90,37 +90,45 @@ const toggleFollow = async () => {
showCreateProfileDialog.value = false;

try {
const [profile] = await Promise.all([
profilesStore.client.getAgentProfile(props.agentPubKey),
isFollowing.value
? await client.callZome({
role_name: "mewsfeed",
zome_name: "follows",
fn_name: "unfollow",
payload: props.agentPubKey,
})
: await client.callZome({
role_name: "mewsfeed",
zome_name: "follows",
fn_name: "follow",
payload: props.agentPubKey,
}),
]);
isFollowing.value
? await client.callZome({
role_name: "mewsfeed",
zome_name: "follows",
fn_name: "unfollow",
payload: props.agentPubKey,
})
: await client.callZome({
role_name: "mewsfeed",
zome_name: "follows",
fn_name: "follow",
payload: props.agentPubKey,
});
await refetchMyFollowing();
if (isFollowing.value) {
setHomeRedirect(false);
}
emit("toggle-follow", isFollowing.value);
showSuccessMessage();
} catch (error) {
showError(error);
}
};

const name = `${profile?.fields[PROFILE_FIELDS.DISPLAY_NAME]} (@${
const showSuccessMessage = async () => {
let name;
try {
const profile = await profilesStore.client.getAgentProfile(
props.agentPubKey
);
name = `${profile?.fields[PROFILE_FIELDS.DISPLAY_NAME]} (@${
profile?.nickname
})`;
const message = isFollowing.value
? `Followed ${name}`
: `Unfollowed ${name}`;
showMessage(message);
emit("toggle-follow", isFollowing.value);
} catch (error) {
showError(error);
console.error(error);
name = encodeHashToBase64(props.agentPubKey);
}

const message = isFollowing.value ? `Followed ${name}` : `Unfollowed ${name}`;
showMessage(message);
};
</script>
10 changes: 7 additions & 3 deletions ui/src/components/CreatorsListDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ const fetchCreators = async (params: any) => {

const agentProfiles = await Promise.all(
agents.map(async (agentPubKey) => {
const profile = await profilesStore.client.getAgentProfile(agentPubKey);
if (!profile) return null;
let profile;
try {
profile = await profilesStore.client.getAgentProfile(agentPubKey);
} catch (error) {
console.error(error);
}

return {
agentPubKey,
profile: profile,
profile,
};
})
);
Expand Down
10 changes: 7 additions & 3 deletions ui/src/components/FollowersListDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ const fetchCreators = async (params: any) => {

const agentProfiles = await Promise.all(
agents.map(async (agentPubKey) => {
const profile = await profilesStore.client.getAgentProfile(agentPubKey);
if (!profile) return null;
let profile;
try {
profile = await profilesStore.client.getAgentProfile(agentPubKey);
} catch (error) {
console.error(error);
}

return {
agentPubKey,
profile: profile,
profile,
};
})
);
Expand Down
Loading
Loading