Skip to content

Commit b827987

Browse files
committed
[Client] Minor integration
1 parent c4f0c5a commit b827987

File tree

14 files changed

+196
-95
lines changed

14 files changed

+196
-95
lines changed

client/src/components/AddPost.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import { getContext } from 'svelte';
4949
import { fly } from 'svelte/transition';
5050
51-
import PostDialog from './ClassDialog.svelte';
51+
import PostDialog from './PostDialog.svelte';
5252
import CloseButton from './CloseButton.svelte';
5353
5454
const { open } = getContext('simple-modal');
@@ -58,7 +58,7 @@
5858
let closing = false;
5959
let closed = false;
6060
61-
export let link, icon, label;
61+
export let link, icon, label, classId;
6262
6363
let post_text;
6464
let status = 0;
@@ -80,8 +80,9 @@
8080
{
8181
message: "Enter Post Details",
8282
hasForm: true,
83+
classId: classId,
8384
onCancel,
84-
onOkay
85+
onOkay,
8586
},
8687
{
8788
closeButton: true,

client/src/components/Card.svelte

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,38 +66,38 @@
6666
export let title, subtext, link, styleNumber, data, ispost = true, acc = false;
6767
import { slide } from 'svelte/transition';
6868
let visible = true;
69-
export let sections = [
70-
{
71-
id: 1,
72-
title: "Section 1",
73-
content: ["comment 1", "comment 2", "comment 3"],
74-
active: false,
75-
},
76-
{
77-
id: 2,
78-
title: "Section 2",
79-
content: ["comment 1"],
80-
active: false,
81-
},
82-
{
83-
id: 3,
84-
title: "Section 3",
85-
content: ["comment 1"],
86-
active: false,
87-
}
88-
]
69+
// export let sections = [
70+
// {
71+
// id: 1,
72+
// title: "Section 1",
73+
// content: ["comment 1", "comment 2", "comment 3"],
74+
// active: false,
75+
// },
76+
// {
77+
// id: 2,
78+
// title: "Section 2",
79+
// content: ["comment 1"],
80+
// active: false,
81+
// },
82+
// {
83+
// id: 3,
84+
// title: "Section 3",
85+
// content: ["comment 1"],
86+
// active: false,
87+
// }
88+
// ]
8989
90-
const expand = (section) => {
91-
sections = sections.map(s => {
92-
// s.active = false
90+
// const expand = (section) => {
91+
// sections = sections.map(s => {
92+
// // s.active = false
9393
94-
if (s.id === section.id) {
95-
if (s.active == false) s.active = true
96-
else s.active = false
97-
}
98-
return s
99-
})
100-
}
94+
// if (s.id === section.id) {
95+
// if (s.active == false) s.active = true
96+
// else s.active = false
97+
// }
98+
// return s
99+
// })
100+
// }
101101
</script>
102102

103103
{#if !acc}
@@ -133,30 +133,33 @@
133133
{/if}
134134
</a>
135135

136-
136+
<!--
137137
{:else}
138138
<a>
139139
{#each sections as section}
140140
141141
<section class="card style-{styleNumber}" on:click={() => expand(section) }>
142142
<div class="left">
143-
<h1 class="title">{title}</h1>
143+
<h1 class="title">{section.post_by_id}</h1>
144144
</div>
145145
<div class="right">
146146
147147
<h3 class="subtext">
148-
{subtext}
148+
{section.post_text}
149149
</h3>
150150
151151
</div>
152152
{#if section.active}
153153
<div class="slider" transition:slide>
154-
{#each section.content as comment}
154+
<p>comment<br></p>
155+
<p>comment<br></p>
156+
157+
{#each section.comments as comment}
155158
<p>{comment}<br></p>
156159
{/each}
157160
</div>
158161
{/if}
159162
</section>
160163
{/each}
161-
</a>
162-
{/if}
164+
</a> -->
165+
{/if}

client/src/components/ClassDialog.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<button on:click={_onCancel}>
8787
Cancel
8888
</button>
89-
<button typpe = "submit" on:click={_onOkay}>
89+
<button type = "submit" on:click={_onOkay}>
9090
Add
9191
</button>
9292
</div>

client/src/components/Match.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<style lang="scss">
33
.card {
4-
padding: 1.5rem 1rem 3rem 1rem;
4+
pwadding: 1.5rem 1rem 3rem 1rem;
55
border-radius: 10px;
66
margin-bottom: 10px;
77
background: #15171b;

client/src/components/Nav.svelte

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,21 @@ li.dropdown {
8282
}
8383
</script> -->
8484
<script>
85-
export let classList = [
86-
{
87-
name: "Class 1",
88-
link: "class"
89-
},
90-
{
91-
name: "Class 2",
92-
link: "class"
93-
},
94-
{
95-
name: "Class 3",
96-
link: "class"
97-
}
98-
]
85+
// export let classList = [
86+
// {
87+
// name: "Class 1",
88+
// uuid: "class"
89+
// },
90+
// {
91+
// name: "Class 2",
92+
// uuid: "class"
93+
// },
94+
// {
95+
// name: "Class 3",
96+
// uuid: "class"
97+
// }
98+
// ]
99+
export let classList = [];
99100
</script>
100101

101102
<nav>
@@ -107,7 +108,7 @@ li.dropdown {
107108
<li class="dropdown"><a class="dropbtn">Classes</a>
108109
<div class="dropdown-content">
109110
{#each classList as c}
110-
<a href={c.link}>{c.name}</a>
111+
<a href='/class/{c.uuid}.svelte'>{c.name}</a>
111112
{/each}
112113
</div>
113114
</li>

client/src/components/PostDialog.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
export let hasForm = false;
55
export let onCancel = () => {};
66
export let onOkay = () => {};
7+
export let classId;
78
89
const { close } = getContext('simple-modal');
910
@@ -76,13 +77,14 @@
7677
type="text"
7778
bind:value
7879
on:keydown={e => e.which === 13 && _onOkay()} /> -->
79-
<form action="" method="POST">
80-
<input type="PostText" bind:value={post_text} name="posttext" placeholder="Post Text" required class="input-border">
80+
<form action="/addPost/" method="POST">
81+
<input type="postText" bind:value={post_text} name="postText" placeholder="Post Text" required class="input-border">
82+
<input type="hidden" value={classId} name="classId">
8183
<div class="buttons">
8284
<button on:click={_onCancel}>
8385
Cancel
8486
</button>
85-
<button typpe = "submit" on:click={_onOkay}>
87+
<button type = "submit" on:click={_onOkay}>
8688
Add
8789
</button>
8890
</div>

client/src/routers/auth.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ router.get('/profileDetails/', async(req, res, next) => {
107107
'Authorization': `Token ${req.session.key}`
108108
}
109109
})
110+
// console.log(response)
110111
const json = await response.json()
111112
req.session.mentor_recs = json.mentorData
112113
return res.json(json)

client/src/routers/userActions.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,44 @@ router.post('/applyMentor/', async(req, res, next) => {
4545
})
4646

4747
router.post('/createClass/', async(req, res, next) => {
48+
// const { slug } = req.params;
4849
const response = await post('api/class/', req.body, req.session.key)
49-
console.log(response)
50-
const uuid = 'index'
51-
res.redirect(`/class/${uuid}.svelte`)
50+
// console.log(response)
51+
const uuid = response['uuid']
52+
res.redirect(`/class/${response['uuid']}.svelte`)
53+
})
54+
55+
router.post('/addPost/', async(req, res, next) => {
56+
// const { slug } = req.params;
57+
const {postText, classId} = req.body;
58+
const response = await post('api/class/post/', req.body, req.session.key)
59+
// console.log("text: " + response['postText'])
60+
// console.log("addPost " + response['classId'])
61+
// const uuid = response['classId']
62+
console.log(classId)
63+
res.redirect(`/class/${classId}.svelte`)
64+
})
65+
66+
// router.get('/classDetails/', async(req, res, next) => {
67+
// const response = await get('api/class/', req.session.key)
68+
// const json = await response.json();
69+
// // console.log(response)
70+
// return json;
71+
72+
// })
73+
74+
router.get('/classDetails/', async(req, res, next) => {
75+
console.log(req.session.key)
76+
77+
const response = await fetch(`${baseUrl}api/class/`, {
78+
method: 'GET',
79+
headers: {
80+
'Authorization': `Token ${req.session.key}`
81+
}
82+
})
83+
const json = await response.json()
84+
return res.json(json)
5285
})
86+
87+
5388
export default router;

client/src/routes/_layout.svelte

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
<script>
2-
import Nav from '../components/Nav.svelte';
31

4-
</script>
52

63
<style lang="scss" global>
74
@import "../styles/global.scss";
85
</style>
96

107

118

12-
<Nav />
139

1410
<main>
1511
<slot></slot>

client/src/routes/class/[slug].svelte

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ form>* {
7171
export async function preload(page, session) {
7272
// authCheck(session, this.redirect);
7373
const { slug } = page.params;
74+
console.log(slug)
7475
const res = await this.fetch(`classDetails/`);
76+
console.log("after fetch")
7577
const classes = await res.json();
78+
console.log("after json")
7679
const uuid = slug.substring(0,36);
80+
console.log("uuid: " + uuid)
7781
return { classes, uuid };
7882
}
7983
</script>
@@ -87,25 +91,47 @@ form>* {
8791
import Nav from '../../components/Nav.svelte'
8892
8993
90-
export let classes, uuid, posts;
94+
export let classes, uuid, posts = [];
9195
console.log("class: ")
92-
console.log(posts)
93-
96+
// console.log(posts)
97+
// console.log("this")
9498
let i, ind;
95-
for (i = 0; i < classes.data.length; i++){
96-
// console.log(classes.data[i].title);
97-
if ( classes.data[i].uuid == uuid){
99+
for (i = 0; i < classes.classes.length; i++){
100+
// console.log("loop")
101+
// console.log(classes.classes[i].title);
102+
if ( classes.classes[i].uuid == uuid){
98103
ind = i;
99104
break;
100105
}
101106
}
102-
export let c = classes.data[ind];
107+
export let c = classes.classes[ind];
103108
console.log("thisclass")
109+
// console.log(classes.posts)
104110
console.log(c)
105111
112+
for (i = 0; i < classes.posts.length; i++){
113+
console.log("loop")
114+
console.log(classes.posts[i].post_by_id);
115+
if ( classes.posts[i].in_class_id == c.id){
116+
posts.push(classes.posts[i])
117+
}
118+
}
119+
120+
console.log("this post")
121+
console.log(posts)
122+
123+
export let classList = []
124+
for (i = 0; i < classes.classes.length; i ++){
125+
classList.push({
126+
name: classes.classes[i].title,
127+
uuid: classes.classes[i].uuid
128+
})
129+
}
130+
console.log(classList)
131+
106132
107133
</script>
108-
<Nav />
134+
<Nav classList={classList} />
109135

110136

111137
<TwoColumn>
@@ -114,17 +140,17 @@ form>* {
114140
<Card title={c.title} subtext={c.description} link="Some text" styleNumber="one" ispost={false}/>
115141
<div class="action-mini_wrapper">
116142
<Modal>
117-
<AddPost icon="users" label="Create New Post" uuid={uuid}/>
143+
<AddPost icon="users" label="Create New Post" classId={uuid}/>
118144
</Modal>
119145
<ActionMini link="" icon="book-read-streamline" label="Add Resources" />
120146
</div>
121147
</div>
122148

123149
<div ref = "childClass" slot="right">
124-
<!-- {#each postDetails as post} -->
125-
<Card title="user name" subtext="post text" link="" styleNumber="two" ispost={false} acc={true}/>
150+
{#each posts as post}
151+
<Card title={post.post_by_id} subtext={post.post_text} link="" styleNumber="two" ispost={false}/>
126152

127-
<!-- {/each} -->
153+
{/each}
128154
</div>
129155

130156
</TwoColumn>

0 commit comments

Comments
 (0)