Skip to content

Commit

Permalink
Prevent refreshing when going back to proposals (#4283)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuveth authored Oct 14, 2023
1 parent 8ca08dd commit ddb66e5
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/views/SpaceProposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ useMeta({
}
});
const {
store,
userVotedProposalIds,
addSpaceProposals,
resetSpaceProposals,
setSpaceProposals
} = useProposals();
const loading = ref(false);
const route = useRoute();
const router = useRouter();
const { loadBy, loadingMore, stopLoadingMore, loadMore } = useInfiniteLoader();
const { emitUpdateLastSeenProposal } = useUnseenProposals();
const { profiles, loadProfiles } = useProfiles();
const { apolloQuery } = useApolloQuery();
const { web3Account } = useWeb3();
const { isFollowing } = useFollowSpace(props.space.id);
const {
store,
userVotedProposalIds,
addSpaceProposals,
resetSpaceProposals,
setSpaceProposals
} = useProposals();
const spaceMembers = computed(() =>
props.space.members.length < 1
Expand All @@ -48,7 +48,7 @@ const spaceMembers = computed(() =>
);
const subSpaces = computed(
() => props.space.children?.map(space => space.id) ?? []
() => props.space.children?.map(space => space.id.toLowerCase()) ?? []
);
const spaceProposals = computed(() => {
Expand Down Expand Up @@ -92,7 +92,7 @@ async function loadMoreProposals(skip: number) {
useInfiniteScroll(
document,
() => {
if (loadingMore.value) return;
if (loadingMore.value || spaceProposals.value.length < 6) return;
loadMore(() => loadMoreProposals(spaceProposals.value.length));
},
{ distance: 400 }
Expand All @@ -101,6 +101,9 @@ useInfiniteScroll(
watch(web3Account, () => emitUpdateLastSeenProposal(props.space.id));
async function loadProposals() {
if (!needToRefreshProposals()) return;
resetSpaceProposals();
loading.value = true;
const proposals = await getProposals();
stopLoadingMore.value = proposals?.length < loadBy;
Expand All @@ -109,10 +112,27 @@ async function loadProposals() {
loading.value = false;
}
function needToRefreshProposals() {
const preventRefreshWhenLeaving = route.fullPath.includes('proposal');
if (preventRefreshWhenLeaving) return false;
if (spaceProposals.value.length < 1) return true;
const lastVisitedPath = router.options.history.state.forward;
if (typeof lastVisitedPath !== 'string') return true;
const lastPathContainedSubSpace = subSpaces.value.some(space => {
return lastVisitedPath.toLowerCase().includes(space);
});
return !(
lastVisitedPath.toLowerCase().includes(props.space.id.toLowerCase()) ||
lastPathContainedSubSpace
);
}
watch(
[stateFilter, showOnlyCore, showFlagged],
() => {
resetSpaceProposals();
loadProposals();
},
{ immediate: true }
Expand All @@ -121,7 +141,6 @@ watch(
watchDebounced(
titleSearch,
() => {
resetSpaceProposals();
loadProposals();
},
{ debounce: 300 }
Expand Down

1 comment on commit ddb66e5

@vercel
Copy link

@vercel vercel bot commented on ddb66e5 Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.