Get courses by members data
This commit is contained in:
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "sapper dev",
|
"dev": "sapper dev",
|
||||||
"build": "sapper build --legacy",
|
"build": "sapper build --legacy",
|
||||||
"export": "sapper export --legacy --entry \"/ api auth login signup courses dashboard discussions people timetable profile discussions\"",
|
"export": "sapper export --legacy --entry \"/ login signup courses dashboard discussions people timetable profile discussions\"",
|
||||||
"start": "node __sapper__/build"
|
"start": "node __sapper__/build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -58,4 +58,4 @@
|
|||||||
"tslib": "^2.3.1",
|
"tslib": "^2.3.1",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
import { supabase } from '../../utils/functions/supabase';
|
import { supabase } from '../../utils/functions/supabase';
|
||||||
|
|
||||||
export async function fetchCourses(userId) {
|
export async function fetchCourses(profileId) {
|
||||||
const { data: orgMember } = await supabase
|
if (!profileId) return;
|
||||||
.from('organizationmember')
|
|
||||||
.select(`organization_id`)
|
|
||||||
.eq('profile_id', userId)
|
|
||||||
.single();
|
|
||||||
|
|
||||||
const { data: allCourses } = await supabase
|
const { data: allCourses } = await supabase
|
||||||
.from('course')
|
.rpc('get_courses')
|
||||||
.select(`id, title, description`)
|
.eq('profile_id', profileId);
|
||||||
.eq('organization_id', orgMember.organization_id);
|
|
||||||
|
|
||||||
return { allCourses, organizationId: orgMember.organization_id };
|
console.log(`allCourses`, allCourses);
|
||||||
|
|
||||||
|
return { allCourses };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if $user.isLoggedIn}
|
{#if $user.isLoggedIn}
|
||||||
<li>
|
<li class="hidden">
|
||||||
<a
|
<a
|
||||||
class="block"
|
class="block"
|
||||||
aria-current={segment === undefined || segment === 'dashboard'
|
aria-current={segment === undefined || segment === 'dashboard'
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li class="hidden">
|
||||||
<a
|
<a
|
||||||
class="block"
|
class="block"
|
||||||
aria-current={segment === 'discussions' || segment === 'discussion'
|
aria-current={segment === 'discussions' || segment === 'discussion'
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li class="hidden">
|
||||||
<a
|
<a
|
||||||
class="block"
|
class="block"
|
||||||
aria-current={segment === 'people' ? 'page' : undefined}
|
aria-current={segment === 'people' ? 'page' : undefined}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script context="module">
|
<script context="module">
|
||||||
export function preload(page, { config }) {
|
export function preload(page, { config }) {
|
||||||
console.log(`page`, page);
|
|
||||||
return { config, isMvpUser: !!page.query.mvp };
|
return { config, isMvpUser: !!page.query.mvp };
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
export async function preload(page, params) {
|
export async function preload(page, params) {
|
||||||
const parsedUser = JSON.parse(params.user);
|
const parsedUser = JSON.parse(params.user);
|
||||||
|
|
||||||
if (parsedUser && parsedUser.id) {
|
// if (parsedUser && parsedUser.id) {
|
||||||
return fetchCourses(parsedUser.id);
|
// return fetchCourses(parsedUser.id);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
allCourses: [],
|
allCourses: [],
|
||||||
organizationId: null,
|
organizationId: null,
|
||||||
cantFetch: !parsedUser,
|
cantFetch: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
group_id,
|
group_id,
|
||||||
organization_id: organizationId,
|
// organization_id: organizationId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get profile of author and add as member
|
// Get profile of author and add as member
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getCourses(userId) {
|
async function getCourses(userId) {
|
||||||
console.log(`getCourses process.browser`, process.browser);
|
console.log(`getCourses process.browser`, process.browser, cantFetch);
|
||||||
if (process.browser) {
|
if (process.browser) {
|
||||||
if (cantFetch && typeof cantFetch === 'boolean' && !allCourses.length) {
|
if (cantFetch && typeof cantFetch === 'boolean' && !allCourses.length) {
|
||||||
const coursesResult = await fetchCourses(userId);
|
const coursesResult = await fetchCourses(userId);
|
||||||
@@ -113,7 +113,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
console.log(`onMount cantFetch`, cantFetch);
|
|
||||||
courses.set(allCourses);
|
courses.set(allCourses);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,21 +5,23 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import Overview from '../../../components/Course/index.svelte';
|
import Overview from '../../../components/Course/index.svelte';
|
||||||
import CourseContainer from '../../../components/CourseContainer/index.svelte';
|
import CourseContainer from '../../../components/CourseContainer/index.svelte';
|
||||||
import { setCourseData, course } from '../../../components/Course/store';
|
import { setCourseData } from '../../../components/Course/store';
|
||||||
import { fetchCourse } from '../../../utils/services/courses';
|
import { fetchCourse } from '../../../utils/services/courses';
|
||||||
|
|
||||||
export let courseId;
|
export let courseId;
|
||||||
|
|
||||||
onMount(async () => {
|
async function onCourseIdChange(courseId) {
|
||||||
|
if (!courseId) return;
|
||||||
console.log(`overview courseId`, courseId);
|
console.log(`overview courseId`, courseId);
|
||||||
if ($course.id) return;
|
|
||||||
|
|
||||||
const { data } = await fetchCourse(courseId);
|
const { data } = await fetchCourse(courseId);
|
||||||
|
|
||||||
setCourseData(data);
|
setCourseData(data);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
$: onCourseIdChange(courseId);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CourseContainer>
|
<CourseContainer>
|
||||||
|
|||||||
@@ -75,10 +75,15 @@
|
|||||||
<p
|
<p
|
||||||
class="bg-yellow-500 w-1/4 text-sm text-center rounded-xl text-white"
|
class="bg-yellow-500 w-1/4 text-sm text-center rounded-xl text-white"
|
||||||
>
|
>
|
||||||
Pending confirmation
|
Pending Invite
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
<p class="text-lg w-1/4 break-all">{person.email}</p>
|
<a
|
||||||
|
href="mailto:{person.email}"
|
||||||
|
class="text-md w-1/4 mx-2 text-blue-600"
|
||||||
|
>
|
||||||
|
{person.email}
|
||||||
|
</a>
|
||||||
<p class="text-lg w-1/4 ">{ROLE_LABEL[person.role_id]}</p>
|
<p class="text-lg w-1/4 ">{ROLE_LABEL[person.role_id]}</p>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@
|
|||||||
This are the organizations you work at
|
This are the organizations you work at
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="my-3 py-2 px-4 border shadow-sm rounded-md">
|
<div class="hidden my-3 py-2 px-4 border shadow-sm rounded-md">
|
||||||
<h4 class="m-0 font-normal">
|
<h4 class="m-0 font-normal">
|
||||||
<a class="text-blue-700 font-bold" href="/courses"> CitiBim </a>
|
<a class="text-blue-700 font-bold" href="/courses"> CitiBim </a>
|
||||||
</h4>
|
</h4>
|
||||||
@@ -156,7 +156,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="my-2 py-2 px-4 border shadow-sm rounded-md">
|
<div class="hidden my-2 py-2 px-4 border shadow-sm rounded-md">
|
||||||
<h4 class="m-0 font-normal">
|
<h4 class="m-0 font-normal">
|
||||||
<a class="text-blue-700 font-bold" href="/courses">
|
<a class="text-blue-700 font-bold" href="/courses">
|
||||||
Climate Change Group
|
Climate Change Group
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isUUID } from '../../functions/isUUID';
|
|||||||
import { QUESTION_TYPE } from '../../../components/Question/constants';
|
import { QUESTION_TYPE } from '../../../components/Question/constants';
|
||||||
|
|
||||||
export async function fetchCourse(courseId, session) {
|
export async function fetchCourse(courseId, session) {
|
||||||
|
console.log(`courseId`, courseId);
|
||||||
let jsonUser;
|
let jsonUser;
|
||||||
|
|
||||||
if (!process.browser) {
|
if (!process.browser) {
|
||||||
|
|||||||
Reference in New Issue
Block a user