Skip to content

Commit

Permalink
Merge pull request #180 from novaforgood/dev
Browse files Browse the repository at this point in the history
Deploy prod
  • Loading branch information
legitmaxwu committed Aug 22, 2023
2 parents ee19454 + 21b31ee commit e98f02b
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 20 deletions.
3 changes: 2 additions & 1 deletion hasura/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
/db_data
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ select_permissions:
- role: public
permission:
columns:
- deleted
- domainWhitelist
- name
- slug
- id
filter:
deleted:
_eq: false
filter: {}
- role: user
permission:
columns:
- id
- name
- slug
- id
filter:
deleted:
_eq: false
- deleted
- domainWhitelist
filter: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- DROP VIEW "public"."public_space";
--
-- CREATE OR REPLACE VIEW "public"."public_space" AS
-- SELECT space.id,
-- space.name,
-- space.slug,
-- space.deleted,
-- space.attributes->>'domainWhitelist' as "domainWhitelist"
-- FROM space;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP VIEW "public"."public_space";

CREATE OR REPLACE VIEW "public"."public_space" AS
SELECT space.id,
space.name,
space.slug,
space.deleted,
space.attributes->>'domainWhitelist' as "domainWhitelist"
FROM space;
8 changes: 8 additions & 0 deletions mobile/src/lib/gql/from-shared/hasura.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) {
first_name
email
}
profile_listing {
id
profile_listing_responses {
id
response_html
}
}
}
}
}
Expand Down Expand Up @@ -656,6 +663,7 @@ query PublicSpaceBySlug($slug: String!) {
public_space(where: { slug: { _eq: $slug } }) {
id
name
domainWhitelist
slug
}
}
8 changes: 8 additions & 0 deletions shared/graphql/hasura.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) {
first_name
email
}
profile_listing {
id
profile_listing_responses {
id
response_html
}
}
}
}
}
Expand Down Expand Up @@ -656,6 +663,7 @@ query PublicSpaceBySlug($slug: String!) {
public_space(where: { slug: { _eq: $slug } }) {
id
name
domainWhitelist
slug
}
}
1 change: 1 addition & 0 deletions web/components/admin/SetPrivacySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function SetPrivacySettings() {
});
}}
/>

<div className="h-8"></div>
<Button
disabled={!mustSave}
Expand Down
113 changes: 108 additions & 5 deletions web/components/space-homepage/SpaceLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useMemo, useState } from "react";

import { closestCenter, DndContext, MeasuringStrategy } from "@dnd-kit/core";
import { rectSortingStrategy, SortableContext } from "@dnd-kit/sortable";
import { getDayOfYear } from "date-fns";
import { addDays, format, getDayOfYear } from "date-fns";
import Fuse from "fuse.js";
import { useAtom } from "jotai";
import Link from "next/link";
import { useRouter } from "next/router";

import { useProfileByIdQuery } from "../../generated/graphql";
import { useAllProfilesOfUserQuery } from "../../generated/graphql";
import {
Profile_Role_Enum,
useProfileListingsInSpaceQuery,
Expand All @@ -16,6 +18,7 @@ import { useCurrentProfile } from "../../hooks/useCurrentProfile";
import { useCurrentSpace } from "../../hooks/useCurrentSpace";
import { usePrivacySettings } from "../../hooks/usePrivacySettings";
import { useQueryParam } from "../../hooks/useQueryParam";
import { useUserData } from "../../hooks/useUserData";
import {
adminBypassAtom,
searchQueryAtom,
Expand All @@ -28,6 +31,38 @@ import { ProfileCard } from "../ProfileCard";

import { FilterBar } from "./FilterBar";

const todayDateString = format(addDays(new Date(), 4), "yyyy-MM-dd");

class SeededRNG {
seed: number;
constructor(seed = 123456789) {
this.seed = seed;
}

nextFloat() {
this.seed = (this.seed * 16807) % 2147483647;
return (this.seed - 1) / 2147483646;
}
}

// Convert an array of strings to a number
function arrayToSeed(arr: string[]) {
let hash = 0;
const string = arr.join(",");
for (let i = 0; i < string.length; i++) {
const char = string.charCodeAt(i);
hash = (hash << 5) - hash + char;
hash |= 0; // Convert to 32bit integer
}
return Math.abs(hash);
}

function generateRandomVal(arr: string[]) {
const seed = arrayToSeed(arr);
const rng = new SeededRNG(seed);
return rng.nextFloat();
}

const FUSE_OPTIONS = {
// isCaseSensitive: false,
// includeScore: false,
Expand Down Expand Up @@ -106,7 +141,7 @@ export function SpaceLandingPage() {
});

const allProfileListings = useMemo(
() => profileListingData?.profile_listing ?? [],
() => [...(profileListingData?.profile_listing ?? [])],
[profileListingData?.profile_listing]
);

Expand All @@ -116,10 +151,77 @@ export function SpaceLandingPage() {

const searchQueryLower = searchQuery.toLowerCase();
const fuse = new Fuse(allProfileListings, FUSE_OPTIONS);

return fuse.search(searchQueryLower).map((result) => result.item);
}, [allProfileListings, searchQuery]);

const { userData } = useUserData();
const [{ data: profileData }] = useAllProfilesOfUserQuery({
variables: { user_id: userData?.id ?? "" },
});

// const idsToProfileScores = useMemo(() => {
// let tempCounter = 0;
// const tempIdsToProfileScores = new Map();

// for (let i = 0; i < filteredProfileListings.length; i++) {
// const profileListing =
// filteredProfileListings[i]?.profile?.profile_listing;

// if (profileListing && profileListing.profile_listing_responses) {
// for (
// let j = 0;
// j < profileListing.profile_listing_responses?.length;
// j++
// ) {
// const response = profileListing.profile_listing_responses[j];
// if (response && response.response_html) {
// const responseArray = response.response_html.split(" ");

// if (responseArray.length >= 10) {
// tempCounter += 4;
// } else if (responseArray.length >= 1) {
// tempCounter += 2;
// }
// }
// }
// }

// const profileHeadline = filteredProfileListings[i]?.headline;
// if (profileHeadline && profileHeadline.length > 0) {
// const headlineArray = profileHeadline.split(" ");

// if (headlineArray.length >= 3) {
// tempCounter += 5;
// } else if (headlineArray.length >= 1) {
// tempCounter += 3;
// }
// }

// if (filteredProfileListings[i].profile_listing_image != null) {
// tempCounter += 10;
// }

// tempCounter +=
// 15 *
// generateRandomVal([
// todayDateString,
// filteredProfileListings[i]?.id ?? "",
// ]);
// tempIdsToProfileScores.set(filteredProfileListings[i].id, tempCounter);
// tempCounter = 0;
// }
// return tempIdsToProfileScores;
// }, [filteredProfileListings]);

// const sortedProfileListings = filteredProfileListings.sort((a, b) => {
// if (idsToProfileScores.get(a.id) > idsToProfileScores.get(b.id)) {
// return -1;
// } else {
// return 1;
// }
// });
const sortedProfileListings = filteredProfileListings;

const [adminBypass, setAdminBypass] = useAtom(adminBypassAtom);

return (
Expand Down Expand Up @@ -177,17 +279,18 @@ export function SpaceLandingPage() {
}}
>
<SortableContext
items={filteredProfileListings}
items={sortedProfileListings}
strategy={rectSortingStrategy}
>
{filteredProfileListings.map((listing, idx) => {
{sortedProfileListings.map((listing, idx) => {
const fullName = getFullNameOfUser(listing.profile.user);

const sortedTags = listing.profile_listing_to_space_tags
.map((tag) => tag.space_tag)
.sort((a, b) => {
const aSelected = selectedTagIdsSet.has(a.id);
const bSelected = selectedTagIdsSet.has(b.id);

if (aSelected && !bSelected) return -1;
if (!aSelected && bSelected) return 1;
return 0;
Expand Down
Loading

1 comment on commit e98f02b

@vercel
Copy link

@vercel vercel bot commented on e98f02b Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.