Skip to content

Commit

Permalink
🚀 Feature Request: Relevance for Courses based on Semester (#101)
Browse files Browse the repository at this point in the history
* add courseInfo to card

* add sort by date to non-community searches
  • Loading branch information
jcserv authored Sep 1, 2021
1 parent 9317b4c commit 34e939e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 24 deletions.
61 changes: 46 additions & 15 deletions client/components/Card.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { Box, Center, useColorModeValue } from "@chakra-ui/react";
import { Box, Center, Icon, useColorModeValue } from "@chakra-ui/react";
import Image from "next/image";
import { useRouter } from "next/router";
import React from "react";
import { FaDiscord, FaTree, FaWhatsapp } from "react-icons/fa";
import {
FaDiscord,
FaRegSnowflake,
FaSun,
FaTree,
FaWhatsapp,
} from "react-icons/fa";
import { GiChestnutLeaf } from "react-icons/gi";
import Tilt from "react-vanilla-tilt";

const Icon = ({ link, titleColor }) => (
const termToIcon = {
Fall: GiChestnutLeaf,
Winter: FaRegSnowflake,
Summer: FaSun,
};

const LinkIcon = ({ link, titleColor }) => (
<>
{link.includes("discord") && (
<FaDiscord color={titleColor} style={{ marginRight: "5px" }} />
Expand All @@ -19,7 +32,28 @@ const Icon = ({ link, titleColor }) => (
</>
);

export const Card = ({ name, description, image, links, id }) => {
const CourseInfo = ({ descriptionColor, campus, term, year }) => (
<>
<Box
mt="1"
color={descriptionColor}
fontWeight="semibold"
as="h2"
isTruncated
>
{campus} <Icon as={termToIcon[term]} /> {year}
</Box>
</>
);

export const Card = ({
name,
image,
links,
id,
isCommunity,
courseInformation,
}) => {
const { locale, defaultLocale, push } = useRouter();
const backgroundColor = useColorModeValue("#FFFFFF", "#181a1b");
const descriptionColor = useColorModeValue("gray.600", "gray.400");
Expand All @@ -45,6 +79,7 @@ export const Card = ({ name, description, image, links, id }) => {
<Box
bg={backgroundColor}
maxW="sm"
minHeight="100%"
borderWidth="1px"
borderRadius="lg"
overflow="hidden"
Expand All @@ -68,19 +103,15 @@ export const Card = ({ name, description, image, links, id }) => {
>
{name}
</Box>

<Box
mt="1"
color={descriptionColor}
fontWeight="semibold"
as="h2"
isTruncated
>
{description}
</Box>
{!isCommunity && (
<CourseInfo
descriptionColor={descriptionColor}
{...courseInformation}
/>
)}
<Box className="d-flex" mt="2">
{links.map((link, index) => (
<Icon key={index} color={titleColor} link={link} />
<LinkIcon key={index} color={titleColor} link={link} />
))}
</Box>
</Box>
Expand Down
12 changes: 12 additions & 0 deletions client/gql/GroupChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export const SEARCH_GROUPCHATS = gql`
links
id
isCommunity
courseInformation {
term
campus
code
year
}
}
totalPages
pageNumber
Expand All @@ -110,6 +116,12 @@ export const SEARCH_ALL_GROUPCHATS = gql`
links
id
isCommunity
courseInformation {
term
campus
code
year
}
}
totalPages
pageNumber
Expand Down
17 changes: 13 additions & 4 deletions server/dist/resolvers/GroupChatResolver.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/dist/resolvers/GroupChatResolver.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions server/resolvers/GroupChatResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,21 @@ export class GroupChatResolver {
if (type != undefined) {
queryObj = { ...queryObj, isCommunity: type };
}
const groupChats = await GroupChatModel.find(queryObj)
.sort({ views: -1, likes: -1 })
.skip(page * pageSize)
.limit(pageSize);

let groupChats;

if (type) {
groupChats = await GroupChatModel.find(queryObj)
.sort({ views: -1, likes: -1 })
.skip(page * pageSize)
.limit(pageSize);
} else {
groupChats = await GroupChatModel.find(queryObj)
.sort({ created: -1, views: -1, likes: -1 })
.skip(page * pageSize)
.limit(pageSize);
}

const totalCount = await GroupChatModel.find(queryObj).countDocuments();
if (totalCount === 0) {
return {
Expand Down

0 comments on commit 34e939e

Please sign in to comment.