From d8ece9eb51d0f6e64af50f244e85a87c45811eb0 Mon Sep 17 00:00:00 2001 From: talksik Date: Sat, 7 May 2022 13:13:47 -0500 Subject: [PATCH] fixing fixing bug changing the query data --- packages/api/routes/line.ts | 2 +- packages/core/models/line.model.ts | 2 +- packages/desktop/src/controller/lineDataProvider.tsx | 12 +++++------- packages/desktop/src/controller/nirvanaApi.ts | 8 ++++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/api/routes/line.ts b/packages/api/routes/line.ts index bbfd089..d50d99c 100644 --- a/packages/api/routes/line.ts +++ b/packages/api/routes/line.ts @@ -208,7 +208,7 @@ async function getUserLines(req: Request, res: Response) { const resObj = new GetUserLinesResponse(masterLines); - res.json(new NirvanaResponse(resObj)); + res.json(new NirvanaResponse(resObj)); } catch (error) { res.status(500).json(error); } diff --git a/packages/core/models/line.model.ts b/packages/core/models/line.model.ts index 14cc8d2..e4cc0e6 100644 --- a/packages/core/models/line.model.ts +++ b/packages/core/models/line.model.ts @@ -20,7 +20,7 @@ export class LineMember { public lineId: ObjectId, public userId: ObjectId, - public state: LineMemberState = LineMemberState.INBOX, + public state: LineMemberState, public createdDate: Date = new Date(), public _id?: ObjectId diff --git a/packages/desktop/src/controller/lineDataProvider.tsx b/packages/desktop/src/controller/lineDataProvider.tsx index e26d63a..84fc062 100644 --- a/packages/desktop/src/controller/lineDataProvider.tsx +++ b/packages/desktop/src/controller/lineDataProvider.tsx @@ -207,18 +207,18 @@ function useSocketHandler(linesData: MasterLineData[]) { // ?are prolly looking to do a full app refresh and connection refresh const newMap = { ...prevMappings }; - linesData.map((masterLine) => { + linesData.forEach((masterLine) => { const lineId = masterLine.lineDetails._id.toString(); newMap[lineId] = masterLine; - console.log(masterLine); - handleConnectToLine(lineId); // tune into lines that I should be if (masterLine.currentUserMember.state === LineMemberState.TUNED) { // don't need to turn toggle on, it's already on - handleTuneToLine(lineId, false); + // ! CHANGE PARADIGM TO NOT INCLUDING TOGGLING IN REQUESTS WITH THE SAME AS TUNING IN + // right now, writing just because of later logic + handleTuneToLine(lineId, true); } }); @@ -344,8 +344,6 @@ export function LineDataProvider({ children }) { // ?just do simple synchronous axios/fetch in useEffect and manage isLoading ourselves? const { data: basicUserLinesData } = useUserLines(); - console.log(basicUserLinesData?.data?.masterLines); - const { linesMap, ...handlers } = useSocketHandler( basicUserLinesData?.data?.masterLines ); @@ -355,7 +353,7 @@ export function LineDataProvider({ children }) { } const value: ILineDataContext & ReturnType = { - linesMap: {}, // TODO send the updated map instead of this array + linesMap, // TODO send the updated map instead of this array relevantUsers: [], $ws, ...handlers, diff --git a/packages/desktop/src/controller/nirvanaApi.ts b/packages/desktop/src/controller/nirvanaApi.ts index f959174..4b74806 100644 --- a/packages/desktop/src/controller/nirvanaApi.ts +++ b/packages/desktop/src/controller/nirvanaApi.ts @@ -18,7 +18,7 @@ export default class NirvanaApi { // auth token from google that our backend will use static _jwtToken?: string; - static async fetch( + static async fetch( url: string, method: Method, privateRoute = false, @@ -88,7 +88,11 @@ async function userSearch(searchQuery: string): Promise { } async function getUserLines(): Promise> { - return await NirvanaApi.fetch(`/lines`, "GET", true); + return await NirvanaApi.fetch>( + `/lines`, + "GET", + true + ); } async function getDmByUserId(otherUserId: string): Promise {