Add "Save to IPFS" to post actions menu
This commit is contained in:
parent
32278db436
commit
d8c0ed4737
1 changed files with 62 additions and 4 deletions
|
@ -81,6 +81,16 @@
|
||||||
<img :src="require('@/assets/forkawesome/thumbs-o-up.svg')">
|
<img :src="require('@/assets/forkawesome/thumbs-o-up.svg')">
|
||||||
<span>{{ post.favourites_count }}</span>
|
<span>{{ post.favourites_count }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a
|
||||||
|
v-if="ipfsUrl"
|
||||||
|
class="icon"
|
||||||
|
title="Saved to IPFS"
|
||||||
|
:href="ipfsUrl"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
<img :src="require('@/assets/ipfs.svg')">
|
||||||
|
</a>
|
||||||
<router-link
|
<router-link
|
||||||
v-if="isTokenized"
|
v-if="isTokenized"
|
||||||
class="icon tokenized"
|
class="icon tokenized"
|
||||||
|
@ -98,13 +108,23 @@
|
||||||
</a>
|
</a>
|
||||||
<div
|
<div
|
||||||
class="post-menu-wrapper"
|
class="post-menu-wrapper"
|
||||||
v-if="canMintToken()"
|
v-if="canSaveToIpfs() || canMintToken()"
|
||||||
v-click-away="hideMenu"
|
v-click-away="hideMenu"
|
||||||
>
|
>
|
||||||
<a class="icon" title="More" @click="toggleMenu()">
|
<a class="icon" title="More" @click="toggleMenu()">
|
||||||
<img :src="require('@/assets/feather/more-horizontal.svg')">
|
<img :src="require('@/assets/feather/more-horizontal.svg')">
|
||||||
</a>
|
</a>
|
||||||
<ul v-if="menuVisible" class="post-menu">
|
<ul v-if="menuVisible" class="post-menu">
|
||||||
|
<li v-if="canSaveToIpfs()">
|
||||||
|
<a
|
||||||
|
class="icon"
|
||||||
|
title="Save to IPFS"
|
||||||
|
@click="hideMenu(); saveToIpfs()"
|
||||||
|
>
|
||||||
|
<img :src="require('@/assets/ipfs.svg')">
|
||||||
|
<span>Save to IPFS</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li v-if="canMintToken()">
|
<li v-if="canMintToken()">
|
||||||
<a
|
<a
|
||||||
class="icon"
|
class="icon"
|
||||||
|
@ -267,6 +287,38 @@ export default class PostComponent extends Vue {
|
||||||
this.menuVisible = false
|
this.menuVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get ipfsUrl(): string | null {
|
||||||
|
const gatewayUrl = this.store.instance?.ipfs_gateway_url
|
||||||
|
if (
|
||||||
|
!gatewayUrl ||
|
||||||
|
this.post.ipfs_cid === null ||
|
||||||
|
this.isTokenized ||
|
||||||
|
this.isWaitingForToken
|
||||||
|
) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return `${gatewayUrl}/ipfs/${this.post.ipfs_cid}`
|
||||||
|
}
|
||||||
|
|
||||||
|
canSaveToIpfs(): boolean {
|
||||||
|
return (
|
||||||
|
!!this.store.instance?.ipfs_gateway_url &&
|
||||||
|
this.post.account.id === this.store.currentUser?.id &&
|
||||||
|
this.post.ipfs_cid === null &&
|
||||||
|
!this.isWaitingForToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveToIpfs() {
|
||||||
|
const { currentUser, instance } = this.store
|
||||||
|
if (!currentUser || !instance || !instance.ipfs_gateway_url) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const authToken = this.store.ensureAuthToken()
|
||||||
|
const { ipfs_cid } = await makePermanent(authToken, this.post.id)
|
||||||
|
this.post.ipfs_cid = ipfs_cid
|
||||||
|
}
|
||||||
|
|
||||||
getPaymentOptions(): PaymentOption[] {
|
getPaymentOptions(): PaymentOption[] {
|
||||||
const items = []
|
const items = []
|
||||||
for (const [code, name] of CRYPTOCURRENCIES) {
|
for (const [code, name] of CRYPTOCURRENCIES) {
|
||||||
|
@ -295,6 +347,7 @@ export default class PostComponent extends Vue {
|
||||||
|
|
||||||
canMintToken(): boolean {
|
canMintToken(): boolean {
|
||||||
return (
|
return (
|
||||||
|
!!this.store.instance?.nft_contract_address &&
|
||||||
this.post.account.id === this.store.currentUser?.id &&
|
this.post.account.id === this.store.currentUser?.id &&
|
||||||
!this.isTokenized &&
|
!this.isTokenized &&
|
||||||
!this.isWaitingForToken
|
!this.isWaitingForToken
|
||||||
|
@ -311,8 +364,11 @@ export default class PostComponent extends Vue {
|
||||||
}
|
}
|
||||||
const authToken = this.store.ensureAuthToken()
|
const authToken = this.store.ensureAuthToken()
|
||||||
this.isWaitingForToken = true
|
this.isWaitingForToken = true
|
||||||
const { ipfs_cid } = await makePermanent(authToken, this.post.id)
|
if (this.post.ipfs_cid === null) {
|
||||||
const tokenUri = `ipfs://${ipfs_cid}`
|
const { ipfs_cid } = await makePermanent(authToken, this.post.id)
|
||||||
|
this.post.ipfs_cid = ipfs_cid
|
||||||
|
}
|
||||||
|
const tokenUri = `ipfs://${this.post.ipfs_cid}`
|
||||||
console.info("token URI:", tokenUri)
|
console.info("token URI:", tokenUri)
|
||||||
let signature
|
let signature
|
||||||
try {
|
try {
|
||||||
|
@ -348,7 +404,6 @@ export default class PostComponent extends Vue {
|
||||||
clearInterval(intervalId)
|
clearInterval(intervalId)
|
||||||
this.isWaitingForToken = false
|
this.isWaitingForToken = false
|
||||||
// Update post
|
// Update post
|
||||||
this.post.ipfs_cid = post.ipfs_cid
|
|
||||||
this.post.token_id = post.token_id
|
this.post.token_id = post.token_id
|
||||||
this.post.token_tx_id = post.token_tx_id
|
this.post.token_tx_id = post.token_tx_id
|
||||||
}
|
}
|
||||||
|
@ -466,6 +521,9 @@ export default class PostComponent extends Vue {
|
||||||
background-color: $block-background-color;
|
background-color: $block-background-color;
|
||||||
border: 1px solid $separator-color;
|
border: 1px solid $separator-color;
|
||||||
border-radius: $btn-border-radius;
|
border-radius: $btn-border-radius;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: $block-inner-padding / 2;
|
||||||
padding: $block-inner-padding / 2;
|
padding: $block-inner-padding / 2;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
Loading…
Reference in a new issue