From d2dce44868eb5d03ed2058a952371e07e8b0cdcc Mon Sep 17 00:00:00 2001 From: ennucore Date: Wed, 8 Mar 2023 16:57:40 +0100 Subject: [PATCH] Site constructor --- .idea/workspace.xml | 13 ++++++++++--- src/api.ts | 4 ++++ src/components/SiteSettings.vue | 10 ++++++---- src/result.ts | 10 ++++++++++ src/views/Explore.vue | 32 +++++++++++++++++++++++++++----- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 94c69cd..1a658e1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,9 @@ - + @@ -100,7 +100,7 @@ - + 1670844191163 @@ -249,7 +249,14 @@ - diff --git a/src/api.ts b/src/api.ts index 1fa5f7e..b6146c1 100644 --- a/src/api.ts +++ b/src/api.ts @@ -24,3 +24,7 @@ export const config = new Api(); export async function call_api(url: string) { return (await axios.get(config.api_url + url)).data; } + +export async function call_api_post(url: string, data: any) { + return (await axios.post(config.api_url + url, data)).data; +} diff --git a/src/components/SiteSettings.vue b/src/components/SiteSettings.vue index c414e59..df6517d 100644 --- a/src/components/SiteSettings.vue +++ b/src/components/SiteSettings.vue @@ -49,6 +49,7 @@ import Socket from "./Socket.vue"; import contenteditable from 'vue-contenteditable'; import {config} from "../api"; +import {SiteConstructorParams} from "../result"; export default { name: "SiteSettings", @@ -77,8 +78,8 @@ export default { return { site_rec, constructor_site, - constructor_params: {title: ''}, - saved_constructor_params: {title: ''}, + constructor_params: new SiteConstructorParams(''), + saved_constructor_params: new SiteConstructorParams(''), } }, watch: { @@ -92,8 +93,9 @@ export default { deep: true }, saved_constructor_params: { - handler: function (newVal) { - this.$emit('change-constructor', newVal); + handler: function (newVal, oldVal) { + if (newVal === oldVal) return; + this.constructor_params = newVal.copy(); }, deep: true }, diff --git a/src/result.ts b/src/result.ts index 3e63519..bf20b1f 100644 --- a/src/result.ts +++ b/src/result.ts @@ -2,6 +2,7 @@ import {Zone} from "@/zone"; import type {Message} from "@/utils"; +import type {Collection} from "@/collection"; import {call_api} from "@/api"; // let ex_collection = () => new Collection("example.ton", "Example collection"); @@ -150,4 +151,13 @@ export class SiteConstructorParams { this.domain = domain; this.title = title; } + + copy(): SiteConstructorParams { + return new SiteConstructorParams(this.domain, this.title); + } +} + +export async function get_constr_params(domain: string) { + let res = await call_api('get-site-data/' + domain); + return new SiteConstructorParams(res.domain, res.title); } diff --git a/src/views/Explore.vue b/src/views/Explore.vue index b3933ce..9bba45f 100644 --- a/src/views/Explore.vue +++ b/src/views/Explore.vue @@ -43,7 +43,8 @@
@@ -63,10 +64,10 @@ import DarkLayout from "../components/DarkLayout.vue"; import DomainBar from "../components/DomainBar.vue"; import RotateSquare2 from "../components/RotateSquare2.vue"; -import {get_domain_result, get_records, SiteConstructorParams} from "../result"; +import {get_constr_params, get_domain_result, get_records, SiteConstructorParams} from "../result"; import {convertAddress} from "../utils"; import contenteditable from 'vue-contenteditable'; -import {call_api} from "../api"; +import {call_api, call_api_post, config} from "../api"; import Socket from "../components/Socket.vue"; import SiteSettings from "../components/SiteSettings.vue"; @@ -96,12 +97,18 @@ export default { setInterval(() => get_domain_result(this.domain, this.$store.getters.address).then(r => { this.result = Object.assign({}, r); if (this.isMine) { + get_constr_params(this.domain).then(r => { + this.constructor_params = r; + this.saved_constructor_params = r; + this.updSettingsComponent(); + }); get_records(r.nft_info.address).then(r => { this.records = r; // this.timer = setTimeout(this.updRecords, 10000); + this.updSettingsComponent() }) } - }), 7000); + }), 10000); }, computed: { core_domain() { @@ -128,7 +135,11 @@ export default { return this.records && this.wallet_rec !== this.records.wallet; }, siteChanged() { - return this.records && this.site_rec !== this.records.site; + let constr_change = false; + if (this.site_rec === config.agorata_adnl) { + constr_change = this.constructor_params.title !== this.saved_constructor_params.title; + } + return this.records && (this.site_rec !== this.records.site || constr_change); }, settingsCompLoaded() { return this.$refs.site_settings !== undefined; @@ -190,6 +201,12 @@ export default { } this.records.site = this.site_rec; }, + async saveSiteConstr() { + await this.saveSite(); + await call_api_post('set-site-data', this.constructor_params); + this.saved_constructor_params = this.constructor_params; + this.updSettingsComponent(); + }, updRecords() { get_records(this.result.nft_info.address).then(r => { if (this.records.wallet !== r.wallet || this.records.site !== r.site) { @@ -219,6 +236,11 @@ export default { if (!this.loading && this.settingsCompLoaded) { this.updSettingsComponent(); } + }, + loading () { + if (!this.loading && this.settingsCompLoaded) { + this.updSettingsComponent(); + } } } }