Move subscriptions settings to /subscriptions/settings path

And replace profile object with current user.
This commit is contained in:
silverpill 2022-09-02 22:39:17 +00:00
parent 1698082441
commit 2392167980
5 changed files with 43 additions and 23 deletions

View file

@ -1,5 +1,4 @@
<template> <template>
<h1>Manage subscriptions</h1>
<div class="subscription"> <div class="subscription">
<div class="connect-wallet" v-if="canConnectWallet()"> <div class="connect-wallet" v-if="canConnectWallet()">
<button class="btn" @click="connectWallet()">Connect wallet</button> <button class="btn" @click="connectWallet()">Connect wallet</button>
@ -72,7 +71,7 @@ import { $, $$, $computed, $ref } from "vue/macros"
import { DateTime } from "luxon" import { DateTime } from "luxon"
import { Profile, ProfileWrapper } from "@/api/users" import { ProfileWrapper } from "@/api/users"
import { import {
configureSubscriptions, configureSubscriptions,
getPricePerSec, getPricePerSec,
@ -95,15 +94,10 @@ import { useInstanceInfo } from "@/store/instance"
import { useCurrentUser } from "@/store/user" import { useCurrentUser } from "@/store/user"
import { ethereumAddressMatch } from "@/utils/ethereum" import { ethereumAddressMatch } from "@/utils/ethereum"
/* eslint-disable-next-line no-undef */ const { ensureAuthToken, ensureCurrentUser, setCurrentUser } = $(useCurrentUser())
const props = defineProps<{
profile: Profile,
}>()
const { ensureAuthToken, setCurrentUser } = $(useCurrentUser())
const { instance } = $(useInstanceInfo()) const { instance } = $(useInstanceInfo())
const { connectWallet: connectEthereumWallet, getSigner } = useWallet() const { connectWallet: connectEthereumWallet, getSigner } = useWallet()
const profile = new ProfileWrapper(props.profile) const profile = new ProfileWrapper(ensureCurrentUser())
const profileEthereumAddress = profile.getVerifiedEthereumAddress() const profileEthereumAddress = profile.getVerifiedEthereumAddress()
const subscriptionPrice = $ref<number>(1) const subscriptionPrice = $ref<number>(1)
let { walletAddress, walletError } = $(useWallet()) let { walletAddress, walletError } = $(useWallet())

View file

@ -14,6 +14,7 @@ import PublicTimeline from "@/views/PublicTimeline.vue"
import TagTimeline from "@/views/TagTimeline.vue" import TagTimeline from "@/views/TagTimeline.vue"
import SearchResultList from "@/views/SearchResultList.vue" import SearchResultList from "@/views/SearchResultList.vue"
import SubscriptionPage from "@/views/SubscriptionPage.vue" import SubscriptionPage from "@/views/SubscriptionPage.vue"
import SubscriptionsSettings from "@/views/SubscriptionsSettings.vue"
import EthereumPage from "@/views/Ethereum.vue" import EthereumPage from "@/views/Ethereum.vue"
import { useCurrentUser } from "@/store/user" import { useCurrentUser } from "@/store/user"
@ -131,6 +132,12 @@ const routes: Array<RouteRecordRaw> = [
component: ProfileForm, component: ProfileForm,
meta: { onlyAuthenticated: true }, meta: { onlyAuthenticated: true },
}, },
{
path: "/subscriptions/settings",
name: "subscriptions-settings",
component: SubscriptionsSettings,
meta: { onlyAuthenticated: true },
},
{ {
path: "/:pathMatch(.*)*", path: "/:pathMatch(.*)*",
redirect: { name: "home" }, redirect: { name: "home" },

View file

@ -52,7 +52,7 @@
<li v-if="canManageSubscriptions()"> <li v-if="canManageSubscriptions()">
<router-link <router-link
title="Manage subscriptions" title="Manage subscriptions"
:to="{ name: 'profile-subscription', params: { profileId: profile.id }}" :to="{ name: 'subscriptions-settings' }"
> >
Manage subscriptions Manage subscriptions
</router-link> </router-link>

View file

@ -1,10 +1,7 @@
<template> <template>
<sidebar-layout v-if="profile && isLocalUser()"> <sidebar-layout v-if="profile && isLocalUser()">
<template #content> <template #content>
<component <subscription :profile="profile"></subscription>
:is="isCurrentUser() ? SubscriptionSetup : Subscription"
:profile="profile"
></component>
</template> </template>
</sidebar-layout> </sidebar-layout>
</template> </template>
@ -17,11 +14,10 @@ import { useRoute } from "vue-router"
import { getProfile, Profile } from "@/api/users" import { getProfile, Profile } from "@/api/users"
import SidebarLayout from "@/components/SidebarLayout.vue" import SidebarLayout from "@/components/SidebarLayout.vue"
import Subscription from "@/components/Subscription.vue" import Subscription from "@/components/Subscription.vue"
import SubscriptionSetup from "@/components/SubscriptionSetup.vue"
import { useCurrentUser } from "@/store/user" import { useCurrentUser } from "@/store/user"
const route = useRoute() const route = useRoute()
const { currentUser, authToken } = $(useCurrentUser()) const { authToken } = $(useCurrentUser())
let profile = $ref<Profile | null>(null) let profile = $ref<Profile | null>(null)
onMounted(async () => { onMounted(async () => {
@ -37,11 +33,4 @@ function isLocalUser(): boolean {
} }
return profile.username === profile.acct return profile.username === profile.acct
} }
function isCurrentUser(): boolean {
if (!currentUser || !profile) {
return false
}
return currentUser.id === profile.id
}
</script> </script>

View file

@ -0,0 +1,30 @@
<template>
<sidebar-layout>
<template #content>
<h1>Manage subscriptions</h1>
<subscription-settings-ethereum v-if="isEthereum()"></subscription-settings-ethereum>
</template>
</sidebar-layout>
</template>
<script setup lang="ts">
import { $, $computed } from "vue/macros"
import SidebarLayout from "@/components/SidebarLayout.vue"
import SubscriptionSettingsEthereum from "@/components/SubscriptionSettingsEthereum.vue"
import { useInstanceInfo } from "@/store/instance"
const { instance } = $(useInstanceInfo())
const blockchain = $computed(() => instance?.blockchains[0])
function isEthereum(): boolean {
if (!blockchain) {
return false
}
return blockchain.chain_id.startsWith("eip155")
}
</script>
<style scoped lang="scss">
</style>