mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
hmm
This commit is contained in:
parent
1ebf153814
commit
e902c0b6e2
3 changed files with 47 additions and 24 deletions
|
@ -14,7 +14,6 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
v-if="authenticated"
|
|
||||||
class="btn"
|
class="btn"
|
||||||
@click="subscribeHandler"
|
@click="subscribeHandler"
|
||||||
v-t="{
|
v-t="{
|
||||||
|
@ -50,7 +49,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
channel: null,
|
channel: null,
|
||||||
subscribed: false,
|
subscribed: this.authenticated ? false : this.isSubscribedLocally(this.channelId),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -69,6 +68,8 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async fetchSubscribedStatus() {
|
async fetchSubscribedStatus() {
|
||||||
|
if (!this.channelId || !this.authenticated) return;
|
||||||
|
|
||||||
this.fetchJson(
|
this.fetchJson(
|
||||||
this.authApiUrl() + "/subscribed",
|
this.authApiUrl() + "/subscribed",
|
||||||
{
|
{
|
||||||
|
@ -113,16 +114,20 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscribeHandler() {
|
subscribeHandler() {
|
||||||
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
if (this.authenticated) {
|
||||||
method: "POST",
|
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
||||||
body: JSON.stringify({
|
method: "POST",
|
||||||
channelId: this.channel.id,
|
body: JSON.stringify({
|
||||||
}),
|
channelId: this.channel.id,
|
||||||
headers: {
|
}),
|
||||||
Authorization: this.getAuthToken(),
|
headers: {
|
||||||
"Content-Type": "application/json",
|
Authorization: this.getAuthToken(),
|
||||||
},
|
"Content-Type": "application/json",
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.handleLocalSubscriptions(this.channel.id);
|
||||||
|
}
|
||||||
this.subscribed = !this.subscribed;
|
this.subscribed = !this.subscribed;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -80,7 +80,6 @@
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="btn"
|
class="btn"
|
||||||
v-if="authenticated"
|
|
||||||
@click="subscribeHandler"
|
@click="subscribeHandler"
|
||||||
v-t="{
|
v-t="{
|
||||||
path: `actions.${subscribed ? 'unsubscribe' : 'subscribe'}`,
|
path: `actions.${subscribed ? 'unsubscribe' : 'subscribe'}`,
|
||||||
|
@ -427,7 +426,8 @@ export default {
|
||||||
this.fetchComments().then(data => (this.comments = data));
|
this.fetchComments().then(data => (this.comments = data));
|
||||||
},
|
},
|
||||||
async fetchSubscribedStatus() {
|
async fetchSubscribedStatus() {
|
||||||
if (!this.channelId || !this.authenticated) return;
|
if (!this.channelId) return;
|
||||||
|
if (!this.authenticated) this.subscribed = this.isSubscribedLocally(this.channelId);
|
||||||
|
|
||||||
this.fetchJson(
|
this.fetchJson(
|
||||||
this.authApiUrl() + "/subscribed",
|
this.authApiUrl() + "/subscribed",
|
||||||
|
@ -444,16 +444,20 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
subscribeHandler() {
|
subscribeHandler() {
|
||||||
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
if (this.authenticated) {
|
||||||
method: "POST",
|
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
||||||
body: JSON.stringify({
|
method: "POST",
|
||||||
channelId: this.channelId,
|
body: JSON.stringify({
|
||||||
}),
|
channelId: this.channelId,
|
||||||
headers: {
|
}),
|
||||||
Authorization: this.getAuthToken(),
|
headers: {
|
||||||
"Content-Type": "application/json",
|
Authorization: this.getAuthToken(),
|
||||||
},
|
"Content-Type": "application/json",
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.handleLocalSubscriptions(this.channelId);
|
||||||
|
}
|
||||||
this.subscribed = !this.subscribed;
|
this.subscribed = !this.subscribed;
|
||||||
},
|
},
|
||||||
handleScroll() {
|
handleScroll() {
|
||||||
|
|
14
src/main.js
14
src/main.js
|
@ -199,6 +199,20 @@ const mixin = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getLocalSubscriptions() {
|
||||||
|
return JSON.parse(localStorage.getItem("localSubscriptions"));
|
||||||
|
},
|
||||||
|
isSubscribedLocally(channelId) {
|
||||||
|
return this.getLocalSubscriptions().includes(channelId);
|
||||||
|
},
|
||||||
|
handleLocalSubscriptions(channelId) {
|
||||||
|
var localSubscriptions = this.getLocalSubscriptions();
|
||||||
|
if (localSubscriptions == null || localSubscriptions.size == 0) localSubscriptions = [channelId];
|
||||||
|
else if (localSubscriptions.includes(channelId))
|
||||||
|
localSubscriptions.splice(localSubscriptions.indexOf(channelId));
|
||||||
|
else localSubscriptions.push(channelId);
|
||||||
|
localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions));
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
theme() {
|
theme() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue