Directory: replace studios fetch and members fetch with server proxy when DevConnect
cgen-e229611af07146159337a17779d10239
This commit is contained in:
parent
0759aa4358
commit
cd353acca3
1 changed files with 28 additions and 31 deletions
|
|
@ -119,38 +119,35 @@ export default function Directory() {
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
client
|
if (client === devconnect) {
|
||||||
.from<any>(studiosTable as any)
|
const sel = encodeURIComponent(
|
||||||
.select(
|
"id,name,description,type,is_recruiting,recruiting_roles,tags,slug,created_at, collective_members:collective_members(count)",
|
||||||
client === devconnect
|
);
|
||||||
? "id,name,description,type,is_recruiting,recruiting_roles,tags,slug,created_at, collective_members:collective_members(count)"
|
fetch(`/api/devconnect/rest/${studiosTable}?select=${sel}&limit=200`)
|
||||||
: "id,name,description,visibility,created_at, team_memberships:team_memberships(count)",
|
.then((r) => r.json())
|
||||||
)
|
.then((data) => Array.isArray(data) && setStudios(data.map(mapStudio)))
|
||||||
.limit(200)
|
.catch(() => setStudios([]));
|
||||||
.then(({ data, error }) => {
|
} else {
|
||||||
if (!error && Array.isArray(data)) setStudios(data.map(mapStudio));
|
client
|
||||||
else if (client !== supabase) {
|
.from<any>(studiosTable as any)
|
||||||
supabase
|
.select(
|
||||||
.from<any>("teams" as any)
|
"id,name,description,visibility,created_at, team_memberships:team_memberships(count)",
|
||||||
.select(
|
)
|
||||||
"id,name,description,visibility,created_at, team_memberships:team_memberships(count)",
|
.limit(200)
|
||||||
)
|
.then(({ data }) => setStudios((data || []).map(mapStudio)));
|
||||||
.limit(200)
|
}
|
||||||
.then(({ data: d2 }) => setStudios((d2 || []).map(mapStudio)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Fetch member avatars for studios (DevConnect only)
|
// Fetch member avatars for studios (DevConnect only)
|
||||||
if (client === devconnect) {
|
if (client === devconnect) {
|
||||||
const ids = studios.map((s) => s.id).slice(0, 30);
|
const ids = studios.map((s) => s.id).slice(0, 30);
|
||||||
if (ids.length) {
|
if (ids.length) {
|
||||||
devconnect
|
const list = encodeURIComponent(ids.join(","));
|
||||||
?.from<any>("collective_members" as any)
|
fetch(
|
||||||
.select("collective_id, profile_id")
|
`/api/devconnect/rest/collective_members?select=collective_id,profile_id&collective_id=in.(${list})&limit=200`,
|
||||||
.in("collective_id", ids)
|
)
|
||||||
.limit(200)
|
.then((r) => r.json())
|
||||||
.then(async ({ data }) => {
|
.then(async (rows) => {
|
||||||
const byCollective: Record<string, string[]> = {};
|
const byCollective: Record<string, string[]> = {};
|
||||||
(data || []).forEach((row: any) => {
|
(rows || []).forEach((row: any) => {
|
||||||
const cid = String(row.collective_id);
|
const cid = String(row.collective_id);
|
||||||
if (!byCollective[cid]) byCollective[cid] = [];
|
if (!byCollective[cid]) byCollective[cid] = [];
|
||||||
if (byCollective[cid].length < 5)
|
if (byCollective[cid].length < 5)
|
||||||
|
|
@ -160,10 +157,10 @@ export default function Directory() {
|
||||||
new Set(Object.values(byCollective).flat()),
|
new Set(Object.values(byCollective).flat()),
|
||||||
);
|
);
|
||||||
if (profileIds.length) {
|
if (profileIds.length) {
|
||||||
const { data: profs } = await devconnect
|
const pids = encodeURIComponent(profileIds.join(","));
|
||||||
?.from<any>("profiles" as any)
|
const profs = await fetch(
|
||||||
.select("id, display_name, avatar_url")
|
`/api/devconnect/rest/profiles?select=id,display_name,avatar_url&id=in.(${pids})`,
|
||||||
.in("id", profileIds);
|
).then((r) => r.json());
|
||||||
const map: Record<string, StudioMember> = {};
|
const map: Record<string, StudioMember> = {};
|
||||||
(profs || []).forEach((p: any) => {
|
(profs || []).forEach((p: any) => {
|
||||||
map[String(p.id)] = {
|
map[String(p.id)] = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue