Skip to content

Commit

Permalink
Merge pull request #1235 from AletheiaFact/fix-home-feed-bugs
Browse files Browse the repository at this point in the history
Bug Fixing on Home Feed and Search Results.
  • Loading branch information
thesocialdev authored Jun 3, 2024
2 parents 2864543 + 08ef85c commit d2a179f
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 31 deletions.
3 changes: 2 additions & 1 deletion server/claim/claim-revision/claim-revision.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SpeechModule } from "../types/speech/speech.module";
import { ImageModule } from "../types/image/image.module";
import { DebateModule } from "../types/debate/debate.module";
import { ClaimRevisionController } from "./claim-revision.controller";
import { UtilService } from "../../util";

const ClaimRevisionModel = MongooseModule.forFeature([
{
Expand All @@ -39,6 +40,6 @@ const ClaimRevisionModel = MongooseModule.forFeature([
],
controllers: [ClaimRevisionController],
exports: [ClaimRevisionService],
providers: [ClaimRevisionService],
providers: [UtilService, ClaimRevisionService],
})
export class ClaimRevisionModule {}
21 changes: 19 additions & 2 deletions server/claim/claim-revision/claim-revision.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ContentModelEnum } from "../../types/enums";
import { ImageService } from "../types/image/image.service";
import { DebateService } from "../types/debate/debate.service";
import { FindAllOptions } from "../../personality/personality.service";
import { UtilService } from "../../util";

@Injectable()
export class ClaimRevisionService {
Expand All @@ -25,7 +26,8 @@ export class ClaimRevisionService {
private sourceService: SourceService,
private parserService: ParserService,
private imageService: ImageService,
private debateService: DebateService
private debateService: DebateService,
private util: UtilService
) {
this.optionsToUpdate = {
new: true,
Expand Down Expand Up @@ -75,7 +77,12 @@ export class ClaimRevisionService {
return newClaimRevision.save();
}

async findAll({ searchText, pageSize, skipedDocuments }: FindAllOptions) {
async findAll({
searchText,
pageSize,
skipedDocuments,
nameSpace,
}: FindAllOptions) {
const aggregationPipeline = [
{
$search: {
Expand All @@ -89,6 +96,14 @@ export class ClaimRevisionService {
},
},
},
{
$lookup: {
from: "claims",
localField: "claimId",
foreignField: "_id",
as: "claimContent",
},
},
{
$lookup: {
from: "personalities",
Expand All @@ -97,9 +112,11 @@ export class ClaimRevisionService {
as: "personality",
},
},
this.util.getVisibilityMatch(nameSpace),
{
$project: {
title: 1,
contentModel: 1,
"personality.slug": 1,
"personality.name": 1,
slug: 1,
Expand Down
3 changes: 2 additions & 1 deletion server/claim/types/sentence/sentence.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReportModule } from "../../../report/report.module";
import { Sentence, SentenceSchema } from "./schemas/sentence.schema";
import { SentenceController } from "./sentence.controller";
import { SentenceService } from "./sentence.service";
import { UtilService } from "../../../util";

const SentenceModel = MongooseModule.forFeature([
{
Expand All @@ -15,7 +16,7 @@ const SentenceModel = MongooseModule.forFeature([
@Module({
imports: [SentenceModel, ReportModule],
controllers: [SentenceController],
providers: [SentenceService],
providers: [UtilService, SentenceService],
exports: [SentenceService],
})
export class SentenceModule {}
22 changes: 21 additions & 1 deletion server/claim/types/sentence/sentence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import { Model } from "mongoose";
import { SentenceDocument, Sentence } from "./schemas/sentence.schema";
import { InjectModel } from "@nestjs/mongoose";
import { ReportService } from "../../../report/report.service";
import { UtilService } from "../../../util";

interface FindAllOptionsFilters {
searchText: string;
pageSize: number;
language?: string;
skipedDocuments?: number;
filter?: string | string[];
nameSpace?: string;
}

@Injectable()
export class SentenceService {
constructor(
@InjectModel(Sentence.name)
private SentenceModel: Model<SentenceDocument>,
private reportService: ReportService
private reportService: ReportService,
private util: UtilService
) {}

async create(sentenceBody) {
Expand Down Expand Up @@ -54,6 +57,7 @@ export class SentenceService {
pageSize,
skipedDocuments,
filter,
nameSpace,
}: FindAllOptionsFilters) {
let pipeline: object[] = [];

Expand Down Expand Up @@ -118,6 +122,14 @@ export class SentenceService {
as: "claim",
},
},
{
$lookup: {
from: "claims",
localField: "claim.claimId",
foreignField: "_id",
as: "claimContent",
},
},
{
$lookup: {
from: "personalities",
Expand All @@ -126,6 +138,14 @@ export class SentenceService {
as: "personality",
},
},
this.util.getVisibilityMatch(nameSpace),
// Logic made to filter sentences from debates
//TODO: Remove this when claim schema is changed
{
$match: {
claim: { $ne: [] },
},
},
{
$project: {
content: 1,
Expand Down
1 change: 1 addition & 0 deletions server/personality/personality.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface FindAllOptions {
pageSize: number;
language?: string;
skipedDocuments?: number;
nameSpace?: string;
}

@Injectable({ scope: Scope.REQUEST })
Expand Down
4 changes: 3 additions & 1 deletion server/search/search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class SearchController {
@Get("api/search")
@Header("Cache-Control", "max-age=60, must-revalidate")
async listAll(@Query() query, @Req() req) {
const { pageSize, searchText } = query;
const { pageSize, searchText, nameSpace } = query;
const parsedPageSize = parseInt(pageSize, 10);

if (this.configService.get<string>("db.atlas")) {
Expand All @@ -182,10 +182,12 @@ export class SearchController {
this.sentenceService.findAll({
searchText,
pageSize: parsedPageSize,
nameSpace: nameSpace,
}),
this.claimRevisionService.findAll({
searchText,
pageSize: parsedPageSize,
nameSpace: nameSpace,
}),
])
.then(([personalities, sentences, claims]) => {
Expand Down
16 changes: 16 additions & 0 deletions server/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ export class UtilService {

return (isSelectedSuperAdmin && editingSelf) || !isSelectedSuperAdmin;
}

getVisibilityMatch = (nameSpace) => ({
$match: {
$or: [
{
$and: [
{ "claimContent.isHidden": { $ne: true } },
{ "claimContent.isDeleted": { $ne: true } },
{ "claimContent.nameSpace": nameSpace },
{ "personality.isHidden": { $ne: true } },
{ "personality.isDeleted": { $ne: true } },
],
},
],
},
});
}
4 changes: 4 additions & 0 deletions src/api/searchApi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import axios from "axios";
import actions from "../store/actions";
import { ActionTypes, SearchTypes } from "../store/types";
import { NameSpaceEnum } from "../types/Namespace";

interface SearchOptions {
type?: SearchTypes;
searchText?: string;
page?: number;
pageSize?: number;
nameSpace?: string;
}

const request = axios.create({
Expand All @@ -20,6 +22,7 @@ const getResults = (dispatch, options: SearchOptions = {}) => {
searchText: options.searchText,
page: options.page ? options.page : 0,
pageSize: options.pageSize ? options.pageSize : 5,
nameSpace: options.nameSpace ? options.nameSpace : NameSpaceEnum.Main,
};

return request
Expand Down Expand Up @@ -50,6 +53,7 @@ const getFeedResults = (options: SearchOptions = {}): any => {
searchText: options.searchText,
page: options.page ? options.page : 0,
pageSize: options.pageSize ? options.pageSize : 5,
nameSpace: options.nameSpace ? options.nameSpace : NameSpaceEnum.Main,
};

return request
Expand Down
4 changes: 2 additions & 2 deletions src/components/Claim/ClaimCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const ClaimCard = ({
let href = `/${nameSpace !== NameSpaceEnum.Main ? `${nameSpace}/` : ""}`;

if (isDebate) {
href += `claim/${claim._id}/debate`;
href += `claim/${claim.claimId}/debate`;
} else if (personality && personality.slug) {
href += `personality/${personality.slug}/claim/${claim.slug}`;
} else {
Expand Down Expand Up @@ -185,7 +185,7 @@ const ClaimCard = ({
<Button
type={ButtonType.blue}
href={href}
data-cy={personality.name}
data-cy={personality?.name}
>
<span
style={{
Expand Down
4 changes: 2 additions & 2 deletions src/components/ClaimReview/ClaimReviewDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CollaborativeEditorProvider } from "../Collaborative/CollaborativeEdito
import { useAtom } from "jotai";
import { currentNameSpace } from "../../atoms/namespace";
import colors from "../../styles/colors";
import { generateContentPath } from "../../utils/GetContentHref";
import { generateClaimContentPath } from "../../utils/GetClaimContentHref";

const ClaimReviewDrawer = () => {
const [isLoading, setIsLoading] = useState<boolean>(true);
Expand Down Expand Up @@ -78,7 +78,7 @@ const ClaimReviewDrawer = () => {
</AletheiaButton>
<Col span={vw?.xs ? 8 : 14}>
<AletheiaButton
href={generateContentPath(
href={generateClaimContentPath(
nameSpace,
personality,
claim,
Expand Down
14 changes: 8 additions & 6 deletions src/components/ClaimReview/ReviewCardActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ const ClaimReviewCardActions = ({ href, content }) => {
width: "100%",
}}
>
<span>
{t("claimReview:claimReview")}
<ClassificationText
classification={content.props.classification}
/>
</span>
{content.props.classification && (
<span>
{t("claimReview:claimReview")}
<ClassificationText
classification={content.props.classification}
/>
</span>
)}
<AletheiaButton
type={ButtonType.blue}
href={href}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Home/HomeHeader/HomeHeaderSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import { ActionTypes } from "../../../store/types";
import { useDispatch } from "react-redux";
import AletheiaButton, { ButtonType } from "../../Button";
import HomeHeaderSearchStyled from "./HomeHeaderSearch.style";
import { useAtom } from "jotai";
import { currentNameSpace } from "../../../atoms/namespace";

const HomeHeaderSearch = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
const [isLoading, setIsLoading] = useState(false);
const [name, setName] = useState("");
const [nameSpace] = useAtom(currentNameSpace);

const { vw } = useAppSelector((state) => ({
vw: state.vw,
Expand All @@ -27,6 +30,7 @@ const HomeHeaderSearch = () => {
page: 1,
pageSize: 5,
searchText: name,
nameSpace: nameSpace,
});
dispatch({
type: ActionTypes.SEARCH_RESULTS,
Expand Down
4 changes: 4 additions & 0 deletions src/components/Search/OverlaySearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import SearchApi from "../../api/searchApi";
import { useAppSelector } from "../../store/store";
import { ActionTypes } from "../../store/types";
import InputSearch from "../Form/InputSearch";
import { useAtom } from "jotai";
import { currentNameSpace } from "../../atoms/namespace";

const OverlaySearchInput = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
const [nameSpace] = useAtom(currentNameSpace);

const { page, pageSize } = useAppSelector((state) => {
return {
Expand All @@ -28,6 +31,7 @@ const OverlaySearchInput = () => {
page,
pageSize,
searchText: name,
nameSpace: nameSpace,
});
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/Search/SearchPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import PaginationOptions from "./PaginationOptions";
import topicApi from "../../api/topicsApi";
import AdvancedSearch from "./AdvancedSearch";
import SearchIcon from "@mui/icons-material/Search";
import { useAtom } from "jotai";
import { currentNameSpace } from "../../atoms/namespace";

function SearchPageView({ searchText }) {
const dispatch = useDispatch();
const router = useRouter();
const [nameSpace] = useAtom(currentNameSpace);
const { t } = useTranslation();

const {
Expand Down Expand Up @@ -81,6 +84,7 @@ function SearchPageView({ searchText }) {
page: page,
pageSize: pageSize,
searchText: term,
nameSpace: nameSpace,
});
} catch (error) {
console.log(`Error: ${error.message}`);
Expand Down
Loading

0 comments on commit d2a179f

Please sign in to comment.