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

109 follow button #114

Merged
merged 17 commits into from
Jan 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion components/CurateMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</template>

<script setup lang="ts">
import { CurationContractStates } from '@artbycity/sdk/dist/web/curations'
import { type CurationContractStates } from '@artbycity/sdk/dist/web/curations'
import ArdbTransaction from 'ardb/lib/models/transaction'
import { InjectedArweaveSigner } from 'warp-contracts-plugin-deploy'

Expand Down
8 changes: 6 additions & 2 deletions components/FeedItemCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<script setup lang="ts">
import { VImg } from 'vuetify/lib/components/index.mjs'
import {
CollaborativeWhitelistCurationState
type CollaborativeWhitelistCurationState
} from '@artbycity/sdk/dist/web/curations'

const img = ref<VImg>()
Expand All @@ -127,8 +127,12 @@ const { data, pending } = useLazyAsyncData(props.id, async () => {
const checkId = await abc.transactions.get(props.id)

if (checkId) {
if (checkId.tags.find(o => o.name === 'Entity-Type')?.value === 'curation'){
if (
checkId.tags.find(o => o.name === 'Entity-Type')?.value === 'curation'
) {

isCuration.value = true

try {
const curation = abc
.curations
Expand Down
108 changes: 108 additions & 0 deletions components/FollowButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>
<v-hover #="{ isHovering, props }">
<v-btn
v-bind="props"
variant="outlined"
density="compact"
elevation="2"
:color="textColor"
:disabled="pending || loading"
:loading="pending || loading"
:prepend-icon="followActionIcon(isHovering)"
@click="onFollowClick"
>
{{ followActionText(isHovering) }}
<template #loader>
<v-progress-circular
width="3"
size="15"
indeterminate
/>
{{ followActionText(isHovering) }}
</template>
</v-btn>
</v-hover>
</template>

<script setup lang="ts">
const props = defineProps<{ address: string, owner: string }>()
const abc = useArtByCity()
const errorFlag = ref(false)
const creatingContract = ref(false)
const loading = ref(false)

const resetErrorFlag = () => {
errorFlag.value = false
}

const {
data: following,
pending,
refresh
} = useLazyAsyncData(`follows-for-${props.owner}`, async () => {
return await abc.following.following(props.owner)
})

const isFollowing = computed(() => {
if (!following.value) { return false }

return following.value.includes(props.address)
})

const followActionIcon = (isHovering?: boolean) => {
if (errorFlag.value) { return 'mdi-alert' }
if (isHovering && isFollowing.value) { return 'mdi-account-minus' }

return isFollowing.value
? 'mdi-account-check' : 'mdi-account-plus'
}

const followActionText = (isHovering?: boolean) => {
if (pending.value) { return '' }
if (creatingContract.value) { return 'Creating Contract' }
if (loading.value) { return 'Submitting' }
if (errorFlag.value) { return 'ERROR' }
if (isHovering && isFollowing.value) { return 'Unfollow' }

return isFollowing.value
? 'Following' : 'Follow'
}

const textColor = computed(() => {
return errorFlag.value
? '#FF5252' : ''
})

const onFollowClick = debounce(async () => {
jim-toth marked this conversation as resolved.
Show resolved Hide resolved
loading.value = true
const contract = await abc.connect().following.getContract(props.owner)

if (!contract) {
try {
creatingContract.value = true
await abc.connect().following.create({ following: [] })
creatingContract.value = false
} catch (createContractError) {
errorFlag.value = true
console.log('Error on creating follow contract: ', createContractError)
}
}

try {
if (!isFollowing.value) {
await abc.connect().following.follow(props.address)
} else {
await abc.connect().following.unfollow(props.address)
}
await refresh()
} catch (error) {
errorFlag.value = true
console.log('Error when attempting to follow/unfollow.', error)
}

loading.value = false
if (errorFlag.value) {
setTimeout(resetErrorFlag, 2000)
}
})
</script>
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ export default defineNuxtConfig({
whitelist: 'N4JmgBHUu5ZHbcgaOUsKAydcVlQTSi5L7pwvq_NPZuA',
collaborative: 'KNrobEq1MzK7121Tzd-J61trXcxKZujqPQ_B3ojZeb8',
collaborativeWhitelist:
'06Llbzymx4RI8Y0Ygen1grv4hM7MwjmmcCdCqeU9mAI'
'06Llbzymx4RI8Y0Ygen1grv4hM7MwjmmcCdCqeU9mAI'
},
following: 'uPPmKBhY4L4MKAaGi2pCDU30nnEo9VtMb9Sw-zSApFY',
galleryHero: 'ZDIykujDgVmzKFtTcjx9pNoIi26Ew-eQTKzS02PU8kY'
}
}
Expand Down
Loading
Loading