diff --git a/src/components/Channel.vue b/src/components/Channel.vue index fc30cd1e..116afb7b 100644 --- a/src/components/Channel.vue +++ b/src/components/Channel.vue @@ -6,6 +6,16 @@

{{ channel.description }}

+ +
@@ -30,6 +40,11 @@ export default { channel: null, }; }, + computed: { + authenticated(_this) { + return _this.getAuthToken() !== undefined; + }, + }, mounted() { this.getChannelData(); }, @@ -65,6 +80,22 @@ export default { }); } }, + subscribeHandler() { + this.fetchJson(this.apiUrl() + "/subscribe", null, { + method: "POST", + body: JSON.stringify({ + // channelId: this.channel.id, + }), + headers: { + "Auth-Token": this.getAuthToken(), + "Content-Type": "application/json", + }, + }).then(resp => { + if (resp.status === "ok") { + alert("Subscribed!"); + } + }); + }, }, components: { ErrorHandler, diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue new file mode 100644 index 00000000..3be179e8 --- /dev/null +++ b/src/components/LoginPage.vue @@ -0,0 +1,66 @@ + + + diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue index b154e006..26bb6884 100644 --- a/src/components/Navigation.vue +++ b/src/components/Navigation.vue @@ -25,6 +25,12 @@
  • Preferences
  • +
  • + Login +
  • +
  • + Register +
  • @@ -60,6 +66,11 @@ export default { suggestionsVisible: false, }; }, + computed: { + shouldShowLogin(_this) { + return _this.getAuthToken() == null; + }, + }, methods: { onKeyUp(e) { if (e.key === "Enter") { diff --git a/src/components/RegisterPage.vue b/src/components/RegisterPage.vue new file mode 100644 index 00000000..afb4bc60 --- /dev/null +++ b/src/components/RegisterPage.vue @@ -0,0 +1,66 @@ + + + diff --git a/src/main.js b/src/main.js index 2df74d7e..525e9caa 100644 --- a/src/main.js +++ b/src/main.js @@ -136,6 +136,15 @@ const mixin = { window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; return theme; }, + getAuthToken() { + return this.getPreferenceString("authToken" + this.hashCode(this.apiUrl())); + }, + hashCode(s) { + return s.split("").reduce(function(a, b) { + a = (a << 5) - a + b.charCodeAt(0); + return a & a; + }, 0); + }, }, computed: { backgroundColor() { diff --git a/src/router/router.js b/src/router/router.js index 132a388a..1fb6e403 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -29,6 +29,16 @@ const routes = [ path: "/:path(channel|user|c)/:channelId/:videos?", component: () => import("../components/Channel.vue"), }, + { + path: "/login", + name: "Login", + component: () => import("../components/LoginPage.vue"), + }, + { + path: "/register", + name: "Register", + component: () => import("../components/RegisterPage.vue"), + }, ]; const router = createRouter({