44 <ion-toolbar >
55 <ion-buttons >
66 <ion-back-button default-href =" explore" @click =" closeModal" ></ion-back-button >
7- <ion-title >{{ title }}</ion-title >
7+ <ion-title >{{ title }} :D </ion-title >
88 </ion-buttons >
99 </ion-toolbar >
1010 </ion-header >
3333 </ion-card-content >
3434 </ion-card >
3535 <br />
36+ <ion-fab vertical =" bottom" horizontal =" end" slot =" fixed" >
37+ <ion-fab-button >
38+ <ion-icon :icon =" addOutline" ></ion-icon >
39+ </ion-fab-button >
40+ <ion-fab-list side =" top" >
41+ <ion-fab-button @click =" openInBrowser" data-desc =" Open in Browser" >
42+ <ion-icon :icon =" exitOutline" ></ion-icon >
43+ </ion-fab-button >
44+ <ion-fab-button @click =" favorite" :data-desc =" favText" >
45+ <ion-icon :icon =" favIcon" ></ion-icon >
46+ </ion-fab-button >
47+ <ion-fab-button @click =" love" :data-desc =" loveText" >
48+ <ion-icon :icon =" loveIcon" ></ion-icon >
49+ </ion-fab-button >
50+ </ion-fab-list >
51+ </ion-fab >
3652 </ion-content >
3753</ion-page >
3854</template >
3955
4056<script >
41- const axios = require (' axios' );
57+ import ' @capacitor-community/http' ;
58+ import {
59+ Plugins
60+ } from ' @capacitor/core' ;
61+ const {
62+ Http
63+ } = Plugins;
4264const utils = require (' ../utils.js' );
4365import {
4466 IonContent ,
@@ -50,8 +72,17 @@ import {
5072 modalController ,
5173 IonCard ,
5274 IonCardContent ,
53- IonRippleEffect
75+ IonRippleEffect ,
76+ IonIcon
5477} from ' @ionic/vue' ;
78+ import {
79+ addOutline ,
80+ exitOutline ,
81+ heartOutline ,
82+ starOutline ,
83+ star ,
84+ heart
85+ } from ' ionicons/icons' ;
5586import {
5687 defineComponent
5788} from ' vue' ;
@@ -67,12 +98,19 @@ export default defineComponent({
6798 },
6899 data () {
69100 return {
101+ session: JSON .parse (window .localStorage .getItem (' session' )) ? JSON .parse (window .localStorage .getItem (' session' ))[0 ] : null ,
70102 title: ' loading...' ,
71103 author: ' ' ,
72104 content: ' ' ,
73105 instructions: ' loading...' ,
74106 credits: ' ' ,
75- pfp: ' https://u.cubeupload.com/darkness3560/newscratchavataropti.png'
107+ pfp: ' https://u.cubeupload.com/darkness3560/newscratchavataropti.png' ,
108+ addOutline,
109+ exitOutline,
110+ favIcon: starOutline,
111+ favText: ' Favorite' ,
112+ loveIcon: heartOutline,
113+ loveText: ' Love'
76114 }
77115 },
78116 components: {
@@ -84,25 +122,54 @@ export default defineComponent({
84122 IonBackButton,
85123 IonCard,
86124 IonCardContent,
87- IonRippleEffect
125+ IonRippleEffect,
126+ IonIcon
88127 },
89128 mounted () {
129+ console .log (` Session` );
130+ console .log (this .session );
90131 this .loadProject ();
91132 },
92133 methods: {
93134 closeModal () {
94135 modalController .dismiss ();
95136 },
96137 loadProject () {
97- axios
98- .get (` https://itchy-api.vercel.app/api/project?id=${ this .id } ` )
138+ Http .request ({
139+ method: ' GET' ,
140+ url: ` https://api.scratch.mit.edu/projects/${ this .id } `
141+ })
99142 .then ((response ) => {
100143 this .instructions = utils .prepareText (response .data .instructions );
101144 this .credits = utils .prepareText (response .data .description );
102145 this .pfp = response .data .author .profile .images [" 90x90" ];
103146 this .title = response .data .title ;
104147 this .author = response .data .author .username ;
105- })
148+ });
149+ Http .request ({
150+ method: ' GET' ,
151+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /favorites/user/${ this .session .username } ` ,
152+ headers: {
153+ " x-token" : this .session .token
154+ }
155+ }).then ((response ) => {
156+ if (response .data .userFavorite ) {
157+ this .favIcon = star;
158+ this .favText = ' Unfavorite' ;
159+ }
160+ });
161+ Http .request ({
162+ method: ' GET' ,
163+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /loves/user/${ this .session .username } ` ,
164+ headers: {
165+ " x-token" : this .session .token
166+ }
167+ }).then ((response ) => {
168+ if (response .data .userLove ) {
169+ this .loveIcon = heart;
170+ this .loveText = ' Unlove' ;
171+ }
172+ });
106173 },
107174 async openAuthor () {
108175 const modal = await modalController
@@ -116,8 +183,105 @@ export default defineComponent({
116183 this .closeModal ();
117184 return modal .present ();
118185 },
186+ openInBrowser () {
187+ window .open (` https://scratch.mit.edu/projects/${ this .id } ` );
188+ },
189+ favorite () {
190+ Http .request ({
191+ method: ' GET' ,
192+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /favorites/user/${ this .session .username } ` ,
193+ headers: {
194+ " x-token" : this .session .token
195+ }
196+ }).then ((response ) => {
197+ if (response .data .userFavorite ) {
198+ Http .request ({
199+ method: ' DELETE' ,
200+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /favorites/user/${ this .session .username } ` ,
201+ headers: {
202+ " x-token" : this .session .token
203+ }
204+ }).then ((res ) => {
205+ if (res .status == 200 ) {
206+ this .favIcon = starOutline;
207+ this .favText = ' Favorite' ;
208+ }
209+ })
210+ } else {
211+ Http .request ({
212+ method: ' POST' ,
213+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /favorites/user/${ this .session .username } ` ,
214+ headers: {
215+ " x-token" : this .session .token
216+ }
217+ }).then ((res ) => {
218+ if (res .status == 200 ) {
219+ this .favIcon = star;
220+ this .favText = ' Unfavorite' ;
221+ }
222+ });
223+ }
224+ });
225+ },
226+ love () {
227+ Http .request ({
228+ method: ' GET' ,
229+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /loves/user/${ this .session .username } ` ,
230+ headers: {
231+ " x-token" : this .session .token
232+ }
233+ }).then ((response ) => {
234+ if (response .data .userFavorite ) {
235+ Http .request ({
236+ method: ' DELETE' ,
237+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /loves/user/${ this .session .username } ` ,
238+ headers: {
239+ " x-token" : this .session .token
240+ }
241+ }).then ((res ) => {
242+ if (res .status == 200 ) {
243+ this .loveIcon = heartOutline;
244+ this .loveText = ' Love' ;
245+ }
246+ });
247+ } else {
248+ Http .request ({
249+ method: ' POST' ,
250+ url: ` https://api.scratch.mit.edu/projects/${ this .id } /loves/user/${ this .session .username } ` ,
251+ headers: {
252+ " x-token" : this .session .token
253+ }
254+ }).then ((res ) => {
255+ if (res .status == 200 ) {
256+ this .loveIcon = heart;
257+ this .loveText = ' Unlove' ;
258+ }
259+ });
260+ }
261+ });
262+ }
119263 }
120264});
121265 </script >
122266<style scoped>
267+ ion-fab {
268+ transform : translateY (-56px );
269+ }
270+
271+ ion-fab-button [data-desc ] {
272+ position : relative ;
273+ }
274+
275+ ion-fab-button [data-desc ]::after {
276+ position : absolute ;
277+ content : attr (data-desc );
278+ z-index : 1 ;
279+ right : 55px ;
280+ bottom : 4px ;
281+ background-color : var (--ion-color-light );
282+ padding : 9px ;
283+ border-radius : 5px ;
284+ color : var (--ion-text-color );
285+ box-shadow : 0 3px 5px -1px rgba (0 , 0 , 0 , 0.2 ), 0 6px 10px 0 rgba (0 , 0 , 0 , 0.14 ), 0 1px 18px 0 rgba (0 , 0 , 0 , 0.12 );
286+ }
123287 </style >
0 commit comments