-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from appwrite/fix-upvotes
fix: upvotes bug
- Loading branch information
Showing
9 changed files
with
125 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Signal } from "@builder.io/qwik"; | ||
import { useContext, useVisibleTask$ } from "@builder.io/qwik"; | ||
import { Query } from "appwrite"; | ||
import { AppwriteService } from "~/AppwriteService"; | ||
import { AccountContext, UpvotesContext } from "~/routes/layout"; | ||
|
||
export function useUpvotes(projectIds: Signal<string[]>) { | ||
const upvotes = useContext(UpvotesContext); | ||
const account = useContext(AccountContext); | ||
|
||
useVisibleTask$(async ({ track }) => { | ||
track(() => [account.value, projectIds.value]); | ||
if (!account.value) { | ||
return; | ||
} | ||
|
||
const newProjectIds = projectIds.value.filter( | ||
(projectId) => upvotes[projectId] === undefined | ||
); | ||
|
||
if (newProjectIds.length === 0) { | ||
return; | ||
} | ||
|
||
const projectUpvotes = await AppwriteService.listUserUpvotes( | ||
account.value.$id, | ||
[Query.equal("projectId", newProjectIds)] | ||
); | ||
|
||
projectUpvotes.forEach((upvote) => { | ||
upvotes[upvote.projectId] = true; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7fb0d84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
built-with-appwrite – ./
built-with-appwrite-appwrite.vercel.app
built-with-appwrite-git-main-appwrite.vercel.app
builtwith.appwrite.io
built-with-appwrite.vercel.app