Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Liked first #31

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
83 changes: 76 additions & 7 deletions backend/graphql/resolvers/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
throw err;
}
},

singleNft: async args => {
try {
const nfts = await Nft.find();
Expand Down Expand Up @@ -122,6 +123,7 @@ module.exports = {
try {

const nfts = await Nft.find()

const likes = await LikeNft.find({
liker_collection_address: args.collectionAddress,
liker_token_id: args.tokenId
Expand All @@ -131,20 +133,87 @@ module.exports = {
disliker_token_id: args.tokenId
})

const us_like = await LikeNft.find({
liked_collection_address: args.collectionAddress,
liked_token_id: args.tokenId
})
const filtered = nfts
.filter(not_own)
.filter(n => {
const c = likes.find(l => {
return l.liked_collection_address == n.collectionAddress
&& l.liked_token_id == n.tokenId
})

// console.log(likes)

const d = dislikes.find(l=>{
return l.disliked_collection_address == n.collectionAddress
&& l.disliked_token_id == n.tokenId
})

return nfts
.filter(not_own)
.filter(n => { // TODO
return !likes.concat(dislikes).find(l => l.collectionAddress == n.collectionAddress && l.tokenId == n.tokenId)
return !c && !d;
})
.map(transformNft)

const liked = []

const other = []

filtered.forEach(n=>{

if (us_like.find(l=>l.liker_collection_address==n.collectionAddress
&&l.liker_token_id==n.tokenId)) {
liked.push(n)
} else {
other.push(n)
}
})

const all = liked.concat(other)

return all.map(transformNft)


} catch (err) {
throw err;
}

},

findMatch: async args => {

const is_match = my=>yours=> {
return my.liked_token_id == yours.liker_token_id
&& my.liked_collection_address == yours.liked_collection_address
Copy link
Member

Choose a reason for hiding this comment

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

похоже, тут должно быть == yours.likeR_collection_address

}

try {

const we_like = await LikeNft.find({
liker_collection_address: args.collectionAddress,
liker_token_id: args.tokenId
})
const us_like = await LikeNft.find({
liked_collection_address: args.collectionAddress,
liked_token_id: args.tokenId
})

const match = we_like.find(we=>{
return us_like.find(is_match(we));
})

if (!match) return ['','','','']

console.log('MATCH');
console.log(match);

return [
match.liker_collection_address,
match.liker_token_id,
match.liked_collection_address,
match.liked_token_id
]

} catch (err) {
throw err;
}
}
}
1 change: 1 addition & 0 deletions backend/graphql/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type RootQuery {
nfts: [Nft!]
singleNft(nftOwnId: ID!): Nft!
showLikeNfts(nftOwnId: ID!): [Nft!]
findMatch(collectionAddress: String!, tokenId: String!): [String!]
showUnseenNfts(user: String!, collectionAddress: String!, tokenId: String!): [Nft!]
}

Expand Down
40 changes: 35 additions & 5 deletions frontend/src/components/Slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export default {
async handleDecision(decision) {
if(decision === "like") {
await this.sendLike();

await this.fetchMatch();
}
else {
await this.sendDislike();
Expand All @@ -85,6 +87,30 @@ export default {
this.queue = this.queue.length > 1 ? this.queue.slice(1) : [];
},


async fetchMatch() {

const q=
`query{
findMatch(
collectionAddress:"${this.user_nft.collectionAddress}",
tokenId: "${this.user_nft.collectionTokenId}"
)
}`

const r = await this.sendQuery(q)

const res = await r.json()

const m = res.data.findMatch

if (m && m[0]!='') {
alert('WE HAVE A MATCH')
console.log(m)
}

},

async sendLike() {

const q =
Expand All @@ -95,12 +121,14 @@ export default {
liked_collection_address: "${this.current.collectionAddress}",
liked_token_id: "${this.current.tokenId}"
}) {
collectionName
picUrl
liker_collection_address
liker_token_id
liked_collection_address
liked_token_id
}
}`

// console.log(q)
console.log(q)
const r = await this.sendQuery(q)
// console.log(r)

Expand All @@ -119,8 +147,10 @@ export default {
disliked_collection_address: "${this.current.collectionAddress}",
disliked_token_id: "${this.current.tokenId}"
}) {
collectionName
picUrl
disliker_collection_address
disliker_token_id
disliked_collection_address
disliked_token_id
}
}`

Expand Down