Skip to content

Commit

Permalink
Merge pull request #1299 from Coflnet/add-player-bought-any-auction-s…
Browse files Browse the repository at this point in the history
…ubscription-type

add "player bought any auction" subscription type
  • Loading branch information
matthias-luger authored Aug 16, 2024
2 parents 727a19e + e8becf7 commit a532028
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion api/ApiTypes.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export enum SubscriptionType {
BIN = 16,
USE_SELL_NOT_BUY = 32,
AUCTION = 64,
PLAYER_CREATES_AUCTION = 128
PLAYER_CREATES_AUCTION = 128,
BOUGHT_ANY_AUCTION = 1024
}

export interface ApiRequest {
Expand Down
7 changes: 7 additions & 0 deletions components/SubscribeButton/SubscribeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function SubscribeButton(props: Props) {
let [isPlayerAuctionCreation, setIsPlayerAuctionCreation] = useState(
props.prefill?.listener?.types?.includes(SubscriptionType.PLAYER_CREATES_AUCTION) ?? false
)
let [hasPlayerBoughtAnyAuction, setHasPlayerBoughtAnyAuction] = useState(
props.prefill?.listener?.types?.includes(SubscriptionType.BOUGHT_ANY_AUCTION) ?? false
)
let [isLoggedIn, setIsLoggedIn] = useState(false)
let [itemFilter, setItemFilter] = useState<ItemFilter | undefined>(props.prefill?.listener?.filter || undefined)
let [isItemFilterValid, setIsItemFilterValid] = useState(true)
Expand Down Expand Up @@ -109,6 +112,9 @@ function SubscribeButton(props: Props) {
if (isPlayerAuctionCreation) {
types.push(SubscriptionType.PLAYER_CREATES_AUCTION)
}
if (hasPlayerBoughtAnyAuction) {
types.push(SubscriptionType.BOUGHT_ANY_AUCTION)
}
}
if (props.type === 'auction') {
types.push(SubscriptionType.AUCTION)
Expand Down Expand Up @@ -198,6 +204,7 @@ function SubscribeButton(props: Props) {
onGotOutbidChange={setGotOutbid}
onIsSoldChange={setIsSold}
onIsPlayerAuctionCreation={setIsPlayerAuctionCreation}
onBoughtAnyAuctionChange={setHasPlayerBoughtAnyAuction}
prefill={props.prefill?.listener}
/>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Props {
onGotOutbidChange(value: boolean)
onIsSoldChange(value: boolean)
onIsPlayerAuctionCreation(value: boolean)
onBoughtAnyAuctionChange(value: boolean)
prefill?: NotificationListener
}

Expand Down Expand Up @@ -46,6 +47,18 @@ function SubscribePlayerContent(props: Props) {
/>
<label htmlFor="isSoldCheckbox">if an auction of the player has ended</label>
</div>
<div className="input-data">
<input
defaultChecked={
props.prefill && (props.prefill.types as unknown as string[]).includes(SubscriptionType[SubscriptionType.BOUGHT_ANY_AUCTION])
}
type="checkbox"
className={styles.checkBox}
id="hasBoughtAnyAuction"
onChange={e => props.onBoughtAnyAuctionChange((e.target as HTMLInputElement).checked)}
/>
<label htmlFor="hasBoughtAnyAuction">if the player bought any auction</label>
</div>
</div>
</>
)
Expand Down
19 changes: 10 additions & 9 deletions components/SubscriptionList/SubscriptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ function SubscriptionList() {
let [isLoading, setIsLoading] = useState(false)
let wasAlreadyLoggedIn = useWasAlreadyLoggedIn()

let forceUpdate = useForceUpdate()

useEffect(() => {
mounted = true
})
Expand Down Expand Up @@ -103,16 +101,16 @@ function SubscriptionList() {
function getSubTypesAsList(subTypes: SubscriptionType[], price: number): JSX.Element {
return (
<ul>
{subTypes.map(subType => {
{subTypes.map((subType, i) => {
let result
switch (SubscriptionType[subType].toString()) {
case SubscriptionType.BIN.toString():
result = <li key="1">Notify only for instant buy</li>
result = <li key={i}>Notify only for instant buy</li>
break
case SubscriptionType.PRICE_HIGHER_THAN.toString():
result =
price > 0 ? (
<li key="2">
<li key={i}>
Notify if price is higher than{' '}
<b>
<Number number={price} /> Coins
Expand All @@ -124,7 +122,7 @@ function SubscriptionList() {
break
case SubscriptionType.PRICE_LOWER_THAN.toString():
result = (
<li key="3">
<li key={i}>
Notify if price is lower than{' '}
<b>
<Number number={price} /> Coins
Expand All @@ -133,13 +131,16 @@ function SubscriptionList() {
)
break
case SubscriptionType.OUTBID.toString():
result = <li key="4">Notify if player outbid something</li>
result = <li key={i}>Notify if player outbid something</li>
break
case SubscriptionType.SOLD.toString():
result = <li key="5">Notify if player sold something</li>
result = <li key={i}>Notify if player sold something</li>
break
case SubscriptionType.PLAYER_CREATES_AUCTION.toString():
result = <li key="5">Notify if player creates an auction</li>
result = <li key={i}>Notify if player creates an auction</li>
break
case SubscriptionType.BOUGHT_ANY_AUCTION.toString():
result = <li key={i}>Notify if player bought any auction</li>
break
}
return result
Expand Down
1 change: 1 addition & 0 deletions utils/Parser/APIResponseParser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ function _getTypeFromSubTypes(subTypes: SubscriptionType[]): 'item' | 'player' |
case SubscriptionType.OUTBID:
case SubscriptionType.SOLD:
case SubscriptionType.PLAYER_CREATES_AUCTION:
case SubscriptionType.BOUGHT_ANY_AUCTION:
type = 'player'
break
case SubscriptionType.AUCTION:
Expand Down

0 comments on commit a532028

Please sign in to comment.