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>
|
||||
|
||||
<button
|
||||
v-if="authenticated"
|
||||
class="btn"
|
||||
@click="subscribeHandler"
|
||||
v-t="{
|
||||
|
@ -50,7 +49,7 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
channel: null,
|
||||
subscribed: false,
|
||||
subscribed: this.authenticated ? false : this.isSubscribedLocally(this.channelId),
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
|
@ -69,6 +68,8 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
async fetchSubscribedStatus() {
|
||||
if (!this.channelId || !this.authenticated) return;
|
||||
|
||||
this.fetchJson(
|
||||
this.authApiUrl() + "/subscribed",
|
||||
{
|
||||
|
@ -113,6 +114,7 @@ export default {
|
|||
}
|
||||
},
|
||||
subscribeHandler() {
|
||||
if (this.authenticated) {
|
||||
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
|
@ -123,6 +125,9 @@ export default {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.handleLocalSubscriptions(this.channel.id);
|
||||
}
|
||||
this.subscribed = !this.subscribed;
|
||||
},
|
||||
},
|
||||
|
|
|
@ -80,7 +80,6 @@
|
|||
</button>
|
||||
<button
|
||||
class="btn"
|
||||
v-if="authenticated"
|
||||
@click="subscribeHandler"
|
||||
v-t="{
|
||||
path: `actions.${subscribed ? 'unsubscribe' : 'subscribe'}`,
|
||||
|
@ -427,7 +426,8 @@ export default {
|
|||
this.fetchComments().then(data => (this.comments = data));
|
||||
},
|
||||
async fetchSubscribedStatus() {
|
||||
if (!this.channelId || !this.authenticated) return;
|
||||
if (!this.channelId) return;
|
||||
if (!this.authenticated) this.subscribed = this.isSubscribedLocally(this.channelId);
|
||||
|
||||
this.fetchJson(
|
||||
this.authApiUrl() + "/subscribed",
|
||||
|
@ -444,6 +444,7 @@ export default {
|
|||
});
|
||||
},
|
||||
subscribeHandler() {
|
||||
if (this.authenticated) {
|
||||
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
|
@ -454,6 +455,9 @@ export default {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.handleLocalSubscriptions(this.channelId);
|
||||
}
|
||||
this.subscribed = !this.subscribed;
|
||||
},
|
||||
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: {
|
||||
theme() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue