mirror of
https://github.com/thepeacockproject/Peacock
synced 2025-02-10 05:24:28 +01:00
Favorite contracts rework (#163)
* favIcon+UI fix for contract lookup * Fix favorite status for retrieved contracts * Support all fav functionalities binded to "P"
This commit is contained in:
parent
992c77af0d
commit
3c25f20174
components
@ -187,6 +187,12 @@ export function generateUserCentric(
|
||||
? undefined
|
||||
: new Date(played[id]?.LastPlayedAt).toISOString(),
|
||||
// relevant for contracts
|
||||
// Favorite contracts
|
||||
PlaylistData: {
|
||||
IsAdded:
|
||||
userData.Extensions?.PeacockFavoriteContracts?.includes(id),
|
||||
AddedTime: "0001-01-01T00:00:00Z",
|
||||
},
|
||||
Completed: played[id] === undefined ? false : played[id]?.Completed,
|
||||
LocationId: subLocation.Id,
|
||||
ParentLocationId: subLocation.Properties.ParentLocation!,
|
||||
|
@ -223,9 +223,10 @@ export class HitsCategoryService {
|
||||
)
|
||||
controller.storeIdToPublicId(hits.map((hit) => hit.UserCentricContract))
|
||||
|
||||
// Fix completion status for retrieved contracts
|
||||
// Fix completion and favorite status for retrieved contracts
|
||||
const userProfile = getUserData(userId, gameVersion)
|
||||
const played = userProfile?.Extensions.PeacockPlayedContracts
|
||||
const favorites = userProfile?.Extensions.PeacockFavoriteContracts
|
||||
|
||||
hits.forEach((hit) => {
|
||||
if (Object.keys(played).includes(hit.Id)) {
|
||||
@ -240,6 +241,9 @@ export class HitsCategoryService {
|
||||
delete hit.UserCentricContract.Data.LastPlayedAt
|
||||
hit.UserCentricContract.Data.Completed = false
|
||||
}
|
||||
|
||||
hit.UserCentricContract.Data.PlaylistData.IsAdded =
|
||||
favorites.includes(hit.Id)
|
||||
})
|
||||
|
||||
return resp.data.data
|
||||
|
@ -81,7 +81,11 @@ import {
|
||||
} from "./menus/playnext"
|
||||
import { randomUUID } from "crypto"
|
||||
import { planningView } from "./menus/planning"
|
||||
import { directRoute, withLookupDialog } from "./menus/favoriteContracts"
|
||||
import {
|
||||
deleteMultiple,
|
||||
directRoute,
|
||||
withLookupDialog,
|
||||
} from "./menus/favoriteContracts"
|
||||
import { swapToBrowsingMenusStatus } from "./discordRp"
|
||||
import axios from "axios"
|
||||
import { getFlag } from "./flags"
|
||||
@ -1861,10 +1865,16 @@ menuDataRouter.get(
|
||||
|
||||
menuDataRouter.get(
|
||||
// this one is sane Kappa
|
||||
"/contractplaylist/addordelete/{contractId}",
|
||||
"/contractplaylist/addordelete/:contractId",
|
||||
directRoute,
|
||||
)
|
||||
|
||||
menuDataRouter.post(
|
||||
"/contractplaylist/deletemultiple",
|
||||
jsonMiddleware(),
|
||||
deleteMultiple,
|
||||
)
|
||||
|
||||
menuDataRouter.get("/GetPlayerProfileXpData", (req: RequestWithJwt, res) => {
|
||||
const userData = getUserData(req.jwt.unique_name, req.gameVersion)
|
||||
|
||||
|
@ -66,6 +66,13 @@ export function withLookupDialog(
|
||||
false,
|
||||
).find((entry) => entry.Id === contract.Metadata.Location)
|
||||
|
||||
// Must toggle before generating the user centric contract.
|
||||
const flag = toggleFavorite(
|
||||
req.jwt.unique_name,
|
||||
req.query.contractId,
|
||||
req.gameVersion,
|
||||
)
|
||||
|
||||
const result: Result = {
|
||||
template: lookupFavoriteTemplate,
|
||||
data: {
|
||||
@ -77,14 +84,9 @@ export function withLookupDialog(
|
||||
req.gameVersion,
|
||||
),
|
||||
},
|
||||
...(flag && { AddedSuccessfully: true }),
|
||||
}
|
||||
|
||||
result.data.AddedSuccessfully = toggleFavorite(
|
||||
req.jwt.unique_name,
|
||||
req.query.contractId,
|
||||
req.gameVersion,
|
||||
)
|
||||
|
||||
res.json(result)
|
||||
}
|
||||
|
||||
@ -147,3 +149,34 @@ export function directRoute(req: RequestWithJwt, res: Response): void {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array of contract IDs and deletes them from the user's favorites.
|
||||
* @param req The request.
|
||||
* @param res The response.
|
||||
*/
|
||||
export function deleteMultiple(
|
||||
req: RequestWithJwt<{ mode?: string }, string[]>,
|
||||
res: Response,
|
||||
): void {
|
||||
const userProfile = getUserData(req.jwt.unique_name, req.gameVersion)
|
||||
|
||||
// Perform some verification
|
||||
const success = req.body?.every((id) =>
|
||||
userProfile.Extensions.PeacockFavoriteContracts.includes(id),
|
||||
)
|
||||
|
||||
if (success) {
|
||||
req.body?.forEach((id) =>
|
||||
toggleFavorite(req.jwt.unique_name, id, req.gameVersion),
|
||||
)
|
||||
}
|
||||
|
||||
res.json({
|
||||
template: null,
|
||||
data: {
|
||||
ContractIds: req.body,
|
||||
Success: success,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -659,6 +659,12 @@ export interface UserCentricContract {
|
||||
ElusiveContractState: string
|
||||
LastPlayedAt?: string
|
||||
IsFeatured?: boolean
|
||||
// For favorite contracts
|
||||
PlaylistData?: {
|
||||
IsAdded: boolean
|
||||
// Not sure if this is important
|
||||
AddedTime: string
|
||||
}
|
||||
Completed?: boolean
|
||||
LocationId: string
|
||||
ParentLocationId: string
|
||||
|
Loading…
Reference in New Issue
Block a user