fixing fixing bug changing the query data

This commit is contained in:
talksik
2022-05-07 13:13:47 -05:00
parent 19abc4b9fa
commit d8ece9eb51
4 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -208,7 +208,7 @@ async function getUserLines(req: Request, res: Response) {
const resObj = new GetUserLinesResponse(masterLines); const resObj = new GetUserLinesResponse(masterLines);
res.json(new NirvanaResponse(resObj)); res.json(new NirvanaResponse<GetUserLinesResponse>(resObj));
} catch (error) { } catch (error) {
res.status(500).json(error); res.status(500).json(error);
} }
+1 -1
View File
@@ -20,7 +20,7 @@ export class LineMember {
public lineId: ObjectId, public lineId: ObjectId,
public userId: ObjectId, public userId: ObjectId,
public state: LineMemberState = LineMemberState.INBOX, public state: LineMemberState,
public createdDate: Date = new Date(), public createdDate: Date = new Date(),
public _id?: ObjectId public _id?: ObjectId
@@ -207,18 +207,18 @@ function useSocketHandler(linesData: MasterLineData[]) {
// ?are prolly looking to do a full app refresh and connection refresh // ?are prolly looking to do a full app refresh and connection refresh
const newMap = { ...prevMappings }; const newMap = { ...prevMappings };
linesData.map((masterLine) => { linesData.forEach((masterLine) => {
const lineId = masterLine.lineDetails._id.toString(); const lineId = masterLine.lineDetails._id.toString();
newMap[lineId] = masterLine; newMap[lineId] = masterLine;
console.log(masterLine);
handleConnectToLine(lineId); handleConnectToLine(lineId);
// tune into lines that I should be // tune into lines that I should be
if (masterLine.currentUserMember.state === LineMemberState.TUNED) { if (masterLine.currentUserMember.state === LineMemberState.TUNED) {
// don't need to turn toggle on, it's already on // 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? // ?just do simple synchronous axios/fetch in useEffect and manage isLoading ourselves?
const { data: basicUserLinesData } = useUserLines(); const { data: basicUserLinesData } = useUserLines();
console.log(basicUserLinesData?.data?.masterLines);
const { linesMap, ...handlers } = useSocketHandler( const { linesMap, ...handlers } = useSocketHandler(
basicUserLinesData?.data?.masterLines basicUserLinesData?.data?.masterLines
); );
@@ -355,7 +353,7 @@ export function LineDataProvider({ children }) {
} }
const value: ILineDataContext & ReturnType<typeof useSocketHandler> = { const value: ILineDataContext & ReturnType<typeof useSocketHandler> = {
linesMap: {}, // TODO send the updated map instead of this array linesMap, // TODO send the updated map instead of this array
relevantUsers: [], relevantUsers: [],
$ws, $ws,
...handlers, ...handlers,
@@ -18,7 +18,7 @@ export default class NirvanaApi {
// auth token from google that our backend will use // auth token from google that our backend will use
static _jwtToken?: string; static _jwtToken?: string;
static async fetch( static async fetch<T>(
url: string, url: string,
method: Method, method: Method,
privateRoute = false, privateRoute = false,
@@ -88,7 +88,11 @@ async function userSearch(searchQuery: string): Promise<UserSearchResponse> {
} }
async function getUserLines(): Promise<NirvanaResponse<GetUserLinesResponse>> { async function getUserLines(): Promise<NirvanaResponse<GetUserLinesResponse>> {
return await NirvanaApi.fetch(`/lines`, "GET", true); return await NirvanaApi.fetch<NirvanaResponse<GetUserLinesResponse>>(
`/lines`,
"GET",
true
);
} }
async function getDmByUserId(otherUserId: string): Promise<Line> { async function getDmByUserId(otherUserId: string): Promise<Line> {