Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto refresh posting history on clicking post to tft #96

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useStashViewContext } from "@contexts/stash-view-context";
import { usePoeStackAuth } from "@contexts/user-context";
import { GeneralUtils } from "@utils/general-util";
import { TFT_CATEGORIES } from "@utils/tft-categories";
import { useMessagePostedContext } from "@contexts/post-message-events-context";

export function StashViewGenericTftExporterCard() {
const { profile } = usePoeStackAuth();
Expand All @@ -18,6 +19,8 @@ export function StashViewGenericTftExporterCard() {
const [error, setError] = useState<string | null>(null);
const [statusText, setStatusText] = useState<string | null>(null);

const { setMessagePosted } = useMessagePostedContext();

function generateInput() {
return {
league: stashViewSettings.league,
Expand Down Expand Up @@ -55,6 +58,7 @@ export function StashViewGenericTftExporterCard() {
onCompleted() {
setError(null);
setStatusText(null);
setMessagePosted(true);
},
onError(error) {
setError(error.message);
Expand Down
10 changes: 9 additions & 1 deletion src/components/tft-oneclick-message-history-card.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useEffect, useState } from "react";
import { useContext, useEffect, useState } from "react";

import { gql, useLazyQuery, useMutation, useQuery } from "@apollo/client";
import { OneClickMessageHistory } from "@generated/graphql";

import StyledButton from "./library/styled-button";
import { useMessagePostedContext } from "@contexts/post-message-events-context";

export default function TftOneClickMessageHistoryCard() {
const { messagePosted, setMessagePosted } = useMessagePostedContext();
const [messages, setMessages] = useState<OneClickMessageHistory[] | null>(
null
);
Expand All @@ -31,6 +33,12 @@ export default function TftOneClickMessageHistoryCard() {
}
);

useEffect(() => {
if (messagePosted) {
fetch().finally(() => setMessagePosted(false));
}
}, [messagePosted, setMessagePosted, fetch])

const [deleteMessage] = useMutation(
gql`
mutation DeleteTftOneClickMessage($messageId: String!) {
Expand Down
23 changes: 23 additions & 0 deletions src/contexts/post-message-events-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createContext, useContext, useEffect, useState } from "react";

const initalContext: {
messagePosted: boolean;
setMessagePosted: (messagePosted: boolean) => void;
} = {
messagePosted: false,
setMessagePosted: (messagePosted: boolean) => {},
};

export const MessagePostedContext = createContext(initalContext);

export function MessagePostedProvider({ children }) {
const [messagePosted, setMessagePosted] = useState(false);

return (
<MessagePostedContext.Provider value={{ messagePosted, setMessagePosted }}>
{children}
</MessagePostedContext.Provider>
);
}

export const useMessagePostedContext = () => useContext(MessagePostedContext);
58 changes: 31 additions & 27 deletions src/pages/tft/bulk-tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { StashViewContextProvider } from "@contexts/stash-view-context";
import { usePoeStackAuth } from "@contexts/user-context";

import TftGuardPanel from "../../components/item-table/tft-guard-panel";
import { createContext, useState } from "react";
import { MessagePostedProvider } from "@contexts/post-message-events-context";

export default function BulkTool() {
const router = useRouter();
Expand All @@ -26,34 +28,36 @@ export default function BulkTool() {
<div>
<TftGuardPanel>
<div className="flex flex-col space-y-4">
<StyledCard title="Tool">
<StashViewContextProvider
cacheId={`bulk_tool_page_${profile?.userId}_${league}_v_1`}
>
<TftBulkToolPanel />
</StashViewContextProvider>
</StyledCard>
<StyledCard>
<TftOneClickMessageHistoryCard />
</StyledCard>
<TftOneClickInstructions />
<StyledCard>
<div className="flex flex-col space-y-2 w-fit">
<div>Settings (Optional)</div>
<div>
{profile?.discordUsername ? `Current Discord: {${profile?.discordUsername}} (${profile?.discordUserId})` : `Discord account not connected yet`}
<MessagePostedProvider>
<StyledCard title="Tool">
<StashViewContextProvider
cacheId={`bulk_tool_page_${profile?.userId}_${league}_v_1`}
>
<TftBulkToolPanel />
</StashViewContextProvider>
</StyledCard>
<StyledCard>
<TftOneClickMessageHistoryCard />
</StyledCard>
<TftOneClickInstructions />
<StyledCard>
<div className="flex flex-col space-y-2 w-fit">
<div>Settings (Optional)</div>
<div>
{profile?.discordUsername ? `Current Discord: {${profile?.discordUsername}} (${profile?.discordUserId})` : `Discord account not connected yet`}
</div>
<StyledButton
text={`Connect a ${profile?.discordUsername ? 'different ' : ''}Discord`}
onClick={() => {
localStorage.setItem("variable-redirect", router.asPath);
router.push(
"https://discord.com/api/oauth2/authorize?client_id=1075074940275019836&redirect_uri=https%3A%2F%2Fpoestack.com%2Fdiscord%2Fconnected&response_type=code&scope=identify"
);
}}
/>
</div>
<StyledButton
text={`Connect a ${profile?.discordUsername ? 'different ' : ''}Discord`}
onClick={() => {
localStorage.setItem("variable-redirect", router.asPath);
router.push(
"https://discord.com/api/oauth2/authorize?client_id=1075074940275019836&redirect_uri=https%3A%2F%2Fpoestack.com%2Fdiscord%2Fconnected&response_type=code&scope=identify"
);
}}
/>
</div>
</StyledCard>
</StyledCard>
</MessagePostedProvider>
</div>
</TftGuardPanel>
</div>
Expand Down