fixing bug with not having any lines to show

This commit is contained in:
talksik
2022-05-05 09:38:54 -05:00
parent 2555ca3e89
commit 428e6f4582
6 changed files with 29 additions and 16 deletions
+11 -6
View File
@@ -128,7 +128,11 @@ async function getUserLines(req: Request, res: Response) {
); );
if (!userLineMembers?.length) { if (!userLineMembers?.length) {
res.status(400).json(); const resObj = new GetUserLinesResponse([]);
res.json(
new NirvanaResponse(resObj, undefined, "this user is not in any lines")
);
return; return;
} }
@@ -139,13 +143,14 @@ async function getUserLines(req: Request, res: Response) {
// this will include the current user lineMember association to the line // this will include the current user lineMember association to the line
const allLineMembers = await LineService.getLineMembersInLines(lineIds); const allLineMembers = await LineService.getLineMembersInLines(lineIds);
const allLinesUsers: ObjectId[] = []; const allLinesUsersIds: ObjectId[] = [];
allLineMembers?.map((currentLineMember) => { allLineMembers?.map((currentLineMember) => {
if (currentLineMember?._id) allLinesUsers.push(currentLineMember.userId); if (currentLineMember?.userId)
allLinesUsersIds.push(currentLineMember.userId);
}) ?? []; }) ?? [];
// get all users relevant here // get all users relevant here
const allRelevantUsers = await UserService.getUsersByIds(allLinesUsers); const allRelevantUsers = await UserService.getUsersByIds(allLinesUsersIds);
// get all lines from the list of relevant lines // get all lines from the list of relevant lines
const lines = (await LineService.getLinesByIds(lineIds)) ?? []; const lines = (await LineService.getLinesByIds(lineIds)) ?? [];
@@ -183,8 +188,8 @@ async function getUserLines(req: Request, res: Response) {
// get the user objects for all of the other members // get the user objects for all of the other members
const otherUsers: User[] = []; const otherUsers: User[] = [];
associatedLineMembersForLine.forEach((currentLineMember) => { associatedLineMembersForLine.forEach((currentLineMember) => {
const foundUserObject = allRelevantUsers?.find( const foundUserObject = allRelevantUsers?.find((currentUser) =>
(currentUser) => currentUser._id === currentLineMember.userId currentUser._id?.equals(currentLineMember.userId)
); );
if (foundUserObject) otherUsers.push(foundUserObject); if (foundUserObject) otherUsers.push(foundUserObject);
+4 -1
View File
@@ -9,9 +9,12 @@
export default class NirvanaResponse<T> { export default class NirvanaResponse<T> {
data?: T; data?: T;
error?: Error; error?: Error;
message?: string;
constructor(_data: T, _error?: Error) { constructor(_data: T, _error?: Error, _message?: string) {
this.data = _data; this.data = _data;
this.error = _error; this.error = _error;
this.message = _message;
} }
} }
@@ -33,8 +33,8 @@ export default function LineRow({
* */ * */
const renderActivityIcon = useMemo(() => { const renderActivityIcon = useMemo(() => {
// if there is someone or me broadcasting here // if there is someone or me broadcasting here
if (masterLineData.currentUserMember.lastVisitDate) // if (masterLineData.currentUserMember.lastVisitDate)
return <FiSun className="text-xs text-teal-500" />; return <FiSun className="text-xs text-teal-500" />;
// if there is new activity blocks for me // if there is new activity blocks for me
if (masterLineData.currentUserMember.lastVisitDate) if (masterLineData.currentUserMember.lastVisitDate)
@@ -95,7 +95,8 @@ export default function LineRow({
const profilePictures = useMemo(() => { const profilePictures = useMemo(() => {
const pictureSources: string[] = []; const pictureSources: string[] = [];
if (userData?.user?.picture) pictureSources.push(userData.user.picture); // ?don't add in my image as that's useless contextually?
// if (userData?.user?.picture) pictureSources.push(userData.user.picture);
masterLineData.otherUserObjects?.forEach((otherUser) => { masterLineData.otherUserObjects?.forEach((otherUser) => {
if (otherUser.picture) pictureSources.push(otherUser.picture); if (otherUser.picture) pictureSources.push(otherUser.picture);
+1 -4
View File
@@ -46,10 +46,7 @@ function NirvanaApp() {
<NirvanaRouter /> <NirvanaRouter />
</ProtectedRoute> </ProtectedRoute>
{/* <ReactQueryDevtools <ReactQueryDevtools initialIsOpen={true} position={"bottom-left"} />
initialIsOpen={false}
position={"bottom-left"}
/> */}
</RecoilRoot> </RecoilRoot>
<Toaster /> <Toaster />
</QueryClientProvider> </QueryClientProvider>
@@ -16,7 +16,7 @@ export default function NirvanaTerminal({
}: { }: {
allLines: ILineDetails[]; allLines: ILineDetails[];
}) { }) {
const [isModalVisible, setIsModalVisible] = useState<boolean>(true); const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
const setSelectedLineId = useSetRecoilState($selectedLineId); const setSelectedLineId = useSetRecoilState($selectedLineId);
const setDesktopMode = useSetRecoilState($desktopMode); const setDesktopMode = useSetRecoilState($desktopMode);
@@ -92,6 +92,13 @@ export default function NirvanaTerminal({
<Skeleton /> <Skeleton />
) : ( ) : (
<> <>
{" "}
{!userLinesRes?.data?.masterLines.length && (
<span className="text-gray-300 text-sm my-5 text-center">
You have no lines! <br /> Create one to connect to your team
instantly.
</span>
)}
{userLinesRes?.data?.masterLines?.map((masterLineData) => ( {userLinesRes?.data?.masterLines?.map((masterLineData) => (
<LineRow <LineRow
key={`terminalListLines-${masterLineData.lineDetails._id.toString()}`} key={`terminalListLines-${masterLineData.lineDetails._id.toString()}`}
@@ -98,7 +98,7 @@ export default function NewLineModal({
toast.success("created line!"); toast.success("created line!");
// handle close once the new line is created // handle close once the new line is created
handleClose(); // handleClose();
} catch (error) { } catch (error) {
toast.error(error); toast.error(error);
console.error(error); console.error(error);