Skip to content

Commit

Permalink
Merge pull request #12 from ecency/bugfix/final-review
Browse files Browse the repository at this point in the history
Bugfix/final review
  • Loading branch information
feruzm authored Sep 12, 2024
2 parents 3bc9d09 + 93103d3 commit e9d3cfa
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 132 deletions.
136 changes: 71 additions & 65 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/sw.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/api/mutations/account-claiming.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { PrivateKey } from "@hiveio/dhive";
import { claimAccount, claimAccountByKeychain } from "../operations";
import { FullAccount } from "@/entities";
import { getQueryClient, QueryIdentifiers } from "@/core/react-query";
import { QueryIdentifiers } from "@/core/react-query";

export function useAccountClaiming(account: FullAccount) {
const queryClient = useQueryClient();

return useMutation({
mutationKey: ["account-claiming", account.name],
mutationFn: async ({ isKeychain, key }: { key?: PrivateKey; isKeychain?: boolean }) => {
Expand All @@ -23,7 +25,7 @@ export function useAccountClaiming(account: FullAccount) {
}
},
onSuccess: () => {
getQueryClient().setQueryData<FullAccount>(
queryClient.setQueryData<FullAccount>(
[QueryIdentifiers.GET_ACCOUNT_FULL, account.name],
(data) => {
if (!data) {
Expand Down
10 changes: 6 additions & 4 deletions src/api/mutations/bookmarks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { error, success } from "@/features/shared";
import { Entry } from "@/entities";
import { addBookmark } from "@/api/private-api";
Expand All @@ -7,10 +7,11 @@ import { appAxios } from "@/api/axios";
import { apiBase } from "@/api/helper";
import { useGlobalStore } from "@/core/global-store";
import i18next from "i18next";
import { getQueryClient, QueryIdentifiers } from "@/core/react-query";
import { QueryIdentifiers } from "@/core/react-query";

export function useBookmarkAdd(entry: Entry) {
const activeUser = useGlobalStore((s) => s.activeUser);
const queryClient = useQueryClient();

return useMutation({
mutationKey: ["bookmarks", "addBookmark"],
Expand All @@ -29,7 +30,7 @@ export function useBookmarkAdd(entry: Entry) {
},
onSuccess: () => {
success(i18next.t("bookmark-btn.added"));
getQueryClient().invalidateQueries({
queryClient.invalidateQueries({
queryKey: [QueryIdentifiers.BOOKMARKS, activeUser?.username]
});
},
Expand All @@ -39,6 +40,7 @@ export function useBookmarkAdd(entry: Entry) {

export function useBookmarkDelete(bookmarkId?: string) {
const activeUser = useGlobalStore((s) => s.activeUser);
const queryClient = useQueryClient();

return useMutation({
mutationKey: ["bookmarks", "deleteBookmark"],
Expand All @@ -53,7 +55,7 @@ export function useBookmarkDelete(bookmarkId?: string) {
},
onSuccess: () => {
success(i18next.t("bookmark-btn.deleted"));
getQueryClient().invalidateQueries({
queryClient.invalidateQueries({
queryKey: [QueryIdentifiers.BOOKMARKS, activeUser?.username]
});
},
Expand Down
9 changes: 5 additions & 4 deletions src/api/mutations/delete-comment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { broadcastPostingOperations, formatError } from "@/api/operations";
import { useGlobalStore } from "@/core/global-store";
import { Entry } from "@/entities";
import { error } from "@/features/shared";
import { Operation } from "@hiveio/dhive";
import { getQueryClient, QueryIdentifiers } from "@/core/react-query";
import { QueryIdentifiers } from "@/core/react-query";

export function useDeleteComment(entry: Entry, onSuccess: () => void, parent?: Entry) {
const activeUser = useGlobalStore((state) => state.activeUser);
const queryClient = useQueryClient();

return useMutation({
mutationKey: ["deleteComment", activeUser?.username, entry?.id],
Expand All @@ -29,12 +30,12 @@ export function useDeleteComment(entry: Entry, onSuccess: () => void, parent?: E
onSuccess: () => {
if (parent) {
const previousReplies =
getQueryClient().getQueryData<Entry[]>([
queryClient.getQueryData<Entry[]>([
QueryIdentifiers.FETCH_DISCUSSIONS,
parent?.author,
parent?.permlink
]) ?? [];
getQueryClient().setQueryData(
queryClient.setQueryData(
[QueryIdentifiers.FETCH_DISCUSSIONS, parent?.author, parent?.permlink],
[
...previousReplies.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { saveNotificationsSettings } from "@/api/private-api";
import { useGlobalStore } from "@/core/global-store";
import { NotifyTypes } from "@/enums";
import { getQueryClient, QueryIdentifiers } from "@/core/react-query";
import { QueryIdentifiers } from "@/core/react-query";
import * as ls from "@/utils/local-storage";
import { error, success } from "@/features/shared";
import i18next from "i18next";
import { formatError } from "@/api/operations";

export function useUpdateNotificationsSettings() {
const activeUser = useGlobalStore((state) => state.activeUser);
const queryClient = useQueryClient();

return useMutation({
mutationKey: ["notifications", "update-settings"],
Expand All @@ -23,7 +24,7 @@ export function useUpdateNotificationsSettings() {
onError: (e) => error(...formatError(e)),
onSuccess: (settings) => {
success(i18next.t("preferences.updated"));
getQueryClient().setQueryData(
queryClient.setQueryData(
[QueryIdentifiers.NOTIFICATIONS_SETTINGS, activeUser?.username],
settings
);
Expand Down
8 changes: 5 additions & 3 deletions src/api/mutations/update-profile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { updateProfile } from "@/api/operations";
import { AccountProfile, FullAccount } from "@/entities";
import { error, success } from "@/features/shared";
import i18next from "i18next";
import { getQueryClient, QueryIdentifiers } from "@/core/react-query";
import { QueryIdentifiers } from "@/core/react-query";

export function useUpdateProfile(account: FullAccount) {
const queryClient = useQueryClient();

return useMutation({
mutationKey: ["update-profile", account],
mutationFn: async ({ nextProfile }: { nextProfile: AccountProfile }) => {
Expand All @@ -16,7 +18,7 @@ export function useUpdateProfile(account: FullAccount) {
onSuccess: (profile) => {
success(i18next.t("g.success"));

getQueryClient().setQueryData<FullAccount>(
queryClient.setQueryData<FullAccount>(
[QueryIdentifiers.GET_ACCOUNT_FULL, account.name],
(data) => {
if (!data) {
Expand Down
11 changes: 8 additions & 3 deletions src/api/queries/get-account-posts-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EcencyQueriesManager, QueryIdentifiers } from "@/core/react-query";
import { bridgeApiCall, resolvePost } from "@/api/bridge";
import { Entry } from "@/entities";

type PageParam = { author: string | undefined; permlink: string | undefined };
type PageParam = { author: string | undefined; permlink: string | undefined; hasNextPage: boolean };

export const getAccountPostsQuery = (
username: string | undefined,
Expand All @@ -14,6 +14,10 @@ export const getAccountPostsQuery = (
EcencyQueriesManager.generateClientServerInfiniteQuery({
queryKey: [QueryIdentifiers.GET_POSTS, username, filter, limit],
queryFn: async ({ pageParam }) => {
if (!pageParam.hasNextPage) {
return [];
}

const resp = await bridgeApiCall<Entry[] | null>("get_account_posts", {
sort: filter,
account: username,
Expand All @@ -30,12 +34,13 @@ export const getAccountPostsQuery = (
},
enabled: !!username && enabled,
initialData: { pages: [], pageParams: [] },
initialPageParam: { author: undefined, permlink: undefined } as PageParam,
initialPageParam: { author: undefined, permlink: undefined, hasNextPage: true } as PageParam,
getNextPageParam: (lastPage: Entry[]) => {
const last = lastPage?.[lastPage!.length - 1];
return {
author: last?.author,
permlink: last?.permlink
permlink: last?.permlink,
hasNextPage: (lastPage?.length ?? 0) > 0
};
}
});
Loading

0 comments on commit e9d3cfa

Please sign in to comment.