Skip to content

Commit

Permalink
Feat/wow region undercut (#276)
Browse files Browse the repository at this point in the history
* Add request for RegionUndercuts

* Make form for the input

* Add form action for new page

* Add tables for not_found and undercut

* Remove console.og

* Add links

* move index pages around

---------

Co-authored-by: cohenaj194 <cohenaj194@gmail.com>
  • Loading branch information
oldben87 and cohenaj194 authored Jul 1, 2023
1 parent 126a465 commit f5b9b64
Show file tree
Hide file tree
Showing 7 changed files with 1,005 additions and 797 deletions.
42 changes: 42 additions & 0 deletions app/components/form/TextArea/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ToolTip } from '~/components/Common/InfoToolTip'
import { classNames } from '~/utils'

export const TextArea = ({
label,
toolTip,
formName,
placeholder = 'Paste your data here...'
}: {
label?: string
formName?: string
toolTip?: string
placeholder?: string
}) => {
const inputClassnames = classNames(
'flex flex-1 items-center gap-1',
toolTip ? 'relative' : ''
)
return (
<div className="pt-2 flex-col">
{label && (
<div className={inputClassnames}>
<label
htmlFor={formName}
className="block text-sm font-medium text-gray-700 dark:text-gray-100">
{label}
</label>
{toolTip && <ToolTip data={toolTip} />}
</div>
)}
<div className="mt-1 flex rounded-md shadow-sm border border-gray-300 dark:border-gray-400">
<textarea
id={formName}
name={formName}
className="p-2 w-full border-0 rounded-md focus:ring-blue-500 focus:border-2 focus:border-blue-500 dark:border-gray-400 dark:text-gray-100 dark:bg-gray-600"
placeholder={placeholder}
rows={5}
/>
</div>
</div>
)
}
5 changes: 5 additions & 0 deletions app/components/navigation/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ const navGroups: Array<{
href: 'wow/price-alert',
icon: PencilAltIcon
},
{
name: 'Region Wide Undercut Checker',
href: 'wow/region-undercut',
icon: DocumentSearchIcon
},
{
name: 'Undercut Alerts Curseforge Addon',
icon: DocumentSearchIcon,
Expand Down
100 changes: 100 additions & 0 deletions app/requests/WoW/RegionUndercut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { address, UserAgent } from '~/requests/client/config'
import type { WoWServerRegion } from '../WOWScan'

interface PetAuction {
petID: number
price: number
auctionID: number
}
interface ItemAuction {
itemID: number
price: number
auctionID: number
}

interface AddOnData {
homeRealmName: string
region: string
user_auctions: Array<PetAuction | ItemAuction>
}

interface RegionUndercutProps {
region: WoWServerRegion
homeRealmId: number
addonData: Array<AddOnData>
}

interface ImportSearch {
ROI: number
avgPrice: number
connectedRealmIDs: Record<string, string>
homeRealmID: number
maxPurchasePrice: number
profitAmount: number
region: WoWServerRegion
salesPerDay: number
sortBy: string
}

export interface UndercutItems {
connectedRealmId: number
item_id: number
item_name: string
link: string
lowest_price: number
realmName: string
user_price: number
}

interface ResultByRealm {
not_found: Array<{
connectedRealmId: number
item_id: number
item_name: string
link: string
lowest_auction_id: number
lowest_price: number
price_found: boolean
realmName: string
undercut: boolean
user_auction_id: number
user_price: number
}>
realm_info: {
connectedRealmID: number
realmName: string
realmNames: Array<string>
region: string
}
not_undercut: Array<any>
undercuts: Array<any>
}

type RealmName = string

export interface RegionUndercutResponse {
import_search_json: ImportSearch
not_found_list: Array<UndercutItems>
undercut_list: Array<UndercutItems>
results_by_realm: Record<RealmName, ResultByRealm>
}

const RegionUndercutRequest = async ({
homeRealmId,
region,
addonData
}: RegionUndercutProps) =>
await fetch(`${address}/api/wow/regionundercut`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': UserAgent
},
body: JSON.stringify({
homeRealmID: homeRealmId,
region,
addonData
})
})

export default RegionUndercutRequest
34 changes: 9 additions & 25 deletions app/routes/allagan-data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type {
ErrorBoundaryComponent
} from '@remix-run/cloudflare'
import { json } from '@remix-run/cloudflare'
import { useActionData, useTransition } from '@remix-run/react'
import { useActionData, useNavigation } from '@remix-run/react'
import type { ReactNode } from 'react'
import { ContentContainer, PageWrapper, Title } from '~/components/Common'
import { ToolTip } from '~/components/Common/InfoToolTip'
import NoResults from '~/components/Common/NoResults'
import SmallTable from '~/components/WoWResults/FullScan/SmallTable'
import SmallFormContainer from '~/components/form/SmallFormContainer'
import { SubmitButton } from '~/components/form/SubmitButton'
import { TextArea } from '~/components/form/TextArea'
import type { ColumnList } from '~/components/types'
import { ErrorBoundary as ErrorBounds } from '~/components/utilities/ErrorBoundary'
import UniversalisBadgedLink from '~/components/utilities/UniversalisBadgedLink'
Expand Down Expand Up @@ -50,7 +50,7 @@ export const action: ActionFunction = async ({ request }) => {
quantity?: number
type?: string
}) => {
if (!current.id || !current.location) {
if (current.id === undefined || !current.location) {
throw new Error(
"Missing required fields 'id' or 'location' from allagan tools. Make sure those columns are enabled in your plugin!"
)
Expand Down Expand Up @@ -81,7 +81,7 @@ export const action: ActionFunction = async ({ request }) => {
type ActionResponse = AllaganResults | { exception: string } | {}

const Index = () => {
const transition = useTransition()
const transition = useNavigation()
const results = useActionData<ActionResponse>()
const isLoading = transition.state === 'submitting'

Expand Down Expand Up @@ -114,27 +114,11 @@ const Index = () => {
onClick={handleSubmit}
loading={isLoading}
error={error}>
<div className="pt-2 flex-col">
<div className="relative flex flex-1 items-center gap-1">
<label
htmlFor={formName}
className="block text-sm font-medium text-gray-700 dark:text-gray-100">
Allagan Data
</label>
<ToolTip
data={'Paste the data copied from the Allagan tool here.'}
/>
</div>
<div className="mt-1 flex rounded-md shadow-sm border border-gray-300 dark:border-gray-400">
<textarea
id={formName}
name={formName}
className="p-2 w-full border-0 rounded-md focus:ring-blue-500 focus:border-2 focus:border-blue-500 dark:border-gray-400 dark:text-gray-100 dark:bg-gray-600"
placeholder="Paste your data here..."
rows={5}
/>
</div>
</div>
<TextArea
formName={formName}
label="Allagan Data"
toolTip="Paste the data copied from the Allagan tool here."
/>
</SmallFormContainer>
</PageWrapper>
)
Expand Down
21 changes: 17 additions & 4 deletions app/routes/wow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ const recommendedQueries = [
href: 'https://github.com/ff14-advanced-market-search/mega-alerts',
external: true
},
{
name: 'Region Wide Undercut Checker',
description:
'Use our Addon with this search to check all of your undercuts on all your alts on one page!',
Icon: DocumentSearchIcon,
href: '/wow/region-undercut'
},
{
name: 'Undercut Alerts Curseforge Addon',
description: 'The addon for our Undercut Checks and Alerts!',
Icon: DocumentSearchIcon,
href: 'https://www.curseforge.com/wow/addons/saddlebag-exchange',
external: true
},
{
name: 'Dragonflight Marketshare Overview',
description:
Expand All @@ -41,11 +55,10 @@ const recommendedQueries = [
href: '/wow/legacy-marketshare'
},
{
name: 'Undercut Alerts Curseforge Addon',
description: 'The addon for our Undercut Alerts!',
name: 'Region wide undercuts',
description: 'Search for items region wide that you have been undercut on!',
Icon: DocumentSearchIcon,
href: 'https://www.curseforge.com/wow/addons/saddlebag-exchange',
external: true
href: '/wow/region-undercut'
},
{
name: 'Price Sniper and Price Spike Alerts',
Expand Down
Loading

0 comments on commit f5b9b64

Please sign in to comment.