Skip to content

Commit

Permalink
fixed user advertisement page not showing current advert stats
Browse files Browse the repository at this point in the history
  • Loading branch information
its-me-sv committed Jul 20, 2023
1 parent daeefa7 commit 459dd75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/contexts/user.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {createContext, useContext, ReactNode, useState} from "react";
import React, {createContext, useContext, ReactNode, useState, useEffect} from "react";
import toast from "react-hot-toast";
import axios from "axios";
import {encodeAddress} from "@polkadot/util-crypto";
Expand Down Expand Up @@ -53,7 +53,7 @@ export const UserContextProvider: React.FC<{children: ReactNode}> = ({children})
const {
language, setNewAccount,
setLoggedIn, setLowBalance,
setOverlap
setOverlap, setAdvertId,
} = useAppContext();

const loginUser = async (acc: WalletAccount, cb: () => void) => {
Expand Down Expand Up @@ -186,6 +186,13 @@ export const UserContextProvider: React.FC<{children: ReactNode}> = ({children})
});
};

useEffect(() => {
if (!account?.address) return;
axios
.get(`${REST_API}/advert/user/${account.address}`)
.then(({ data }) => setAdvertId!(data || ""));
}, [account]);

return (
<UserContext.Provider value={{
account, setAccount,
Expand Down
16 changes: 1 addition & 15 deletions src/pages/advertise/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect } from "react";
import axios from "axios";

import { Container } from "./styles";
import { advertisemenstPage } from "../../translations/page-titles";
Expand All @@ -9,29 +8,16 @@ import UserAdvert from "../../components/user-advert";
import PostAdvert from "../../components/post-advert";

import { useAppContext } from "../../contexts/app";
import { useUserContext } from "../../contexts/user";
import { REST_API } from "../../utils/constants";

interface AdvertisePageProps {}

const AdvertisePage: React.FC<AdvertisePageProps> = () => {
const {language, dark, advertId, setAdvertId} = useAppContext();
const {account} = useUserContext();

const fetchData = () => {
if (!account?.address) return;
axios.get(`${REST_API}/advert/user/${account.address}`)
.then(({data}) => setAdvertId!(data || ""));
};
const {language, dark, advertId} = useAppContext();

useEffect(() => {
window.document.title = `${advertisemenstPage[language]} / Subdot`;
}, [language]);

useEffect(() => {
fetchData();
}, [account]);

return (
<Container dark={dark}>
{advertId.length > 0 ? (
Expand Down

0 comments on commit 459dd75

Please sign in to comment.