Compare commits

..

1 Commits

Author SHA1 Message Date
oguzhankoral 5d13912826 Recreate ApolloProvider whenever account switches
- It is a force-push of reload page whenever user switches account. It doesn't hurt
2024-02-01 00:53:55 +03:00
11 changed files with 55 additions and 84 deletions
@@ -15,7 +15,7 @@ module SpeckleConnector
Sketchup::ComponentInstance => INCLUDE_COMPONENT_ENTITY_ATTRIBUTES,
Sketchup::Group => INCLUDE_GROUP_ENTITY_ATTRIBUTES,
Sketchup::Face => INCLUDE_FACE_ENTITY_ATTRIBUTES,
Sketchup::Edge => INCLUDE_EDGE_ENTITY_ATTRIBUTES
Sketchup::Face => INCLUDE_EDGE_ENTITY_ATTRIBUTES
}.freeze
LEVEL_SHIFT_VALUE = SpeckleObjects::Geometry.length_to_native(1.5, 'm')
@@ -84,7 +84,7 @@ module SpeckleConnector
speckle_state = new_speckle_state
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
.attribute_dictionaries_to_speckle(component_instance, preferences[:model])
.attribute_dictionaries_to_speckle(component_instance, preferences)
att = dictionaries.any? ? { dictionaries: dictionaries } : {}
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler
.speckle_schema_to_speckle(component_instance)
+27 -41
View File
@@ -48,25 +48,21 @@
<v-img v-if="user.avatar" :src="user.avatar" />
<v-img v-else :src="`https://robohash.org/` + user.id + `.png?size=40x40`" />
</v-avatar>
<div>
<b>{{ user.name }}</b>
</div>
<div class="caption">
{{ user.company }}
<br />
{{ user.bio ? 'Bio: ' + user.bio : '' }}
</div>
<div>
<b>{{ user.name }}</b>
<br />
<b>{{ user.email }}</b>
</div>
<div class="caption">
<b>{{ activeAccount().serverInfo.url }}</b>
</div>
</v-card-text>
<v-card-text v-if="accounts()">
<v-divider class="my-3" />
<div v-for="account in accounts()" :key="account.id">
<v-btn
v-if="account.id != activeAccount().id"
v-if="account.userInfo.id != user.id"
rounded
large
class="my-1 elevation-0"
@@ -104,13 +100,14 @@
/>
</v-container>
<create-stream-dialog
v-if="accounts() && accounts().length !== 0"
v-if="accounts().length !== 0"
:is-f-e2-terms="preferences && preferences.user && preferences.user.fe2"
:is-f-e2="activeAccount().serverInfo.frontend2"
:account-id="activeAccount().userInfo.id"
:server-url="activeAccount().serverInfo.url"
/>
<v-container v-if="accounts() && accounts().length !== 0" fluid>
<router-view :stream-search-query="streamSearchQuery"/>
<v-container v-if="accounts().length !== 0" fluid>
<router-view :stream-search-query="streamSearchQuery" />
</v-container>
<v-container v-else>
<login/>
@@ -132,7 +129,6 @@
/*global sketchup*/
import { bus } from './main'
import userQuery from './graphql/user.gql'
import serverInfoQuery from './graphql/serverInfo.gql'
import { onLogin } from './vue-apollo'
import Login from "@/views/Login";
@@ -149,16 +145,13 @@ global.collectVersions = function (versions) {
global.loadAccounts = function (accounts) {
console.log('>>> SpeckleSketchup: Loading accounts', accounts)
localStorage.setItem('localAccounts', JSON.stringify(accounts))
let selectedAccountId = localStorage.getItem('selectedAccountId')
let uuid = localStorage.getItem('uuid')
if (accounts.length !== 0){
if (selectedAccountId) {
var account = accounts.find((acct) => acct['id'] === selectedAccountId)
if (account){
global.setSelectedAccount(account)
return
}
if (uuid) {
global.setSelectedAccount(accounts.find((acct) => acct['userInfo']['id'] === uuid))
} else {
global.setSelectedAccount(accounts.find((acct) => acct['isDefault']))
}
global.setSelectedAccount(accounts.find((acct) => acct['isDefault']))
}
}
@@ -166,8 +159,7 @@ global.setSelectedAccount = function (account) {
localStorage.setItem('selectedAccount', JSON.stringify(account))
localStorage.setItem('serverUrl', account['serverInfo']['url'])
localStorage.setItem('SpeckleSketchup.AuthToken', account['token'])
localStorage.setItem('selectedAccountId', account['id'])
localStorage.setItem('frontend2', account['serverInfo']['frontend2'])
localStorage.setItem('uuid', account['userInfo']['id'])
bus.$emit('selected-account-reloaded')
}
@@ -208,19 +200,8 @@ export default {
apollo: {
user: {
query: userQuery
},
serverInfo: {
query: serverInfoQuery
}
},
beforeMount() {
// Collect accounts from 'Accounts.db' by ruby sqlite3
sketchup.exec({name: "init_local_accounts", data: {}})
// Collect preferences to render UI according to it
sketchup.exec({name: "collect_preferences", data: {}})
// Collect versions to inform mixpanel
sketchup.exec({name: "collect_versions", data: {}})
},
mounted() {
bus.$on('selected-account-reloaded', async () => {
await onLogin(this.$apollo.provider.defaultClient)
@@ -241,23 +222,28 @@ export default {
this.branchText = this.preferences.user.fe2 ? 'Model' : 'Branch'
this.$vuetify.theme.dark = this.preferences.user.dark_theme
})
// Collect versions to inform mixpanel
sketchup.exec({name: "collect_versions", data: {}})
// Collect preferences to render UI according to it
sketchup.exec({name: "collect_preferences", data: {}})
// Collect accounts from 'Accounts.db' by ruby sqlite3
sketchup.exec({name: "init_local_accounts", data: {}})
},
methods: {
accounts() {
return JSON.parse(localStorage.getItem('localAccounts'))
},
activeAccount() {
return JSON.parse(localStorage.getItem('selectedAccount'))
activeAccount(){
return this.accounts().find((account) => account['isDefault'])
},
switchAccount(account) {
this.$mixpanel.track('Connector Action', { name: 'Account Select' })
global.setSelectedAccount(account)
// Force pushes to reload page to create ApolloClient from scratch
// setTimeout(() => {
// // timeout to wait a bit for potential sketchup.exec in the mean time calls
// location.reload()
// }, 200);
location.reload()
},
requestRefresh() {
sketchup.exec({name: 'reload_accounts', data: {}})
+1 -2
View File
@@ -145,8 +145,7 @@ export default {
prefetch: true,
variables() {
return {
id: this.sourceStreamId,
limit: 100
id: this.sourceStreamId
}
},
skip() {
+9 -11
View File
@@ -91,19 +91,19 @@
mdi-check
</v-icon>
<v-icon v-else small class="mr-1 float-left">mdi-source-branch</v-icon>
{{ branch.name }} ({{ branch && branch.commits ? branch.commits.totalCount : 0 }})
{{ branch.name }} ({{ branch.commits.totalCount }})
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
<v-menu offset-y>
<template #activator="{ on, attrs }">
<v-chip v-if="stream && stream.commits" small v-bind="attrs" v-on="on">
<v-chip v-if="stream.commits" small v-bind="attrs" v-on="on">
<v-icon small class="mr-1 float-left">mdi-source-commit</v-icon>
{{ selectedBranch.commits.items.length ? commitId : 'no commits' }}
{{ selectedBranch.commits.items.length ? commitId : 'no commits' }}
</v-chip>
</template>
<v-list v-if="selectedBranch && selectedBranch.commits" dense>
<v-list dense>
<v-list-item
v-for="(commit, index) in selectedBranch.commits.items"
:key="index"
@@ -221,8 +221,7 @@ export default {
query: streamQuery,
variables() {
return {
id: this.streamId,
limit: 100
id: this.streamId
}
}
},
@@ -362,9 +361,7 @@ export default {
return new Promise((resolve) => setTimeout(resolve, ms))
},
openInWeb() {
var url = localStorage.getItem('frontend2') === "true" ? `${localStorage.getItem('serverUrl')}/projects/${this.streamId}` : `${localStorage.getItem('serverUrl')}/streams/${this.streamId}`
window.open(url)
window.open(`${localStorage.getItem('serverUrl')}/streams/${this.streamId}`)
this.$mixpanel.track('Connector Action', { name: 'Open In Web' })
},
switchBranch(branchName) {
@@ -504,12 +501,13 @@ export default {
}
})
console.log('>>> SpeckleSketchUp: Sent to stream: ' + this.streamId, commit)
const url = localStorage.getItem('frontend2') === 'true' ? `${localStorage.getItem('serverUrl')}/projects/${this.streamId}/models/${this.selectedBranch.id}@${res.data.commitCreate}` : `${localStorage.getItem('serverUrl')}/streams/${this.streamId}/commits/${res.data.commitCreate}`
this.$eventHub.$emit('notification', {
text: 'Model selection sent!\n',
action: {
name: 'View in Web',
url: url
url: `${localStorage.getItem('serverUrl')}/streams/${this.streamId}/commits/${
res.data.commitCreate
}`
}
})
this.$apollo.queries.stream.refetch()
@@ -171,6 +171,10 @@ export default {
type: String,
default: null
},
isFE2: {
type: Boolean,
default: false
},
isFE2Terms: {
type: Boolean,
default: false
@@ -205,7 +209,7 @@ export default {
},
async getStream(){
try {
const streamWrapper = new StreamWrapper(this.createStreamByIdText, this.accountId, this.serverUrl)
const streamWrapper = new StreamWrapper(this.createStreamByIdText, this.accountId, this.serverUrl, this.isFE2)
let res = await this.$apollo.query({
query: gql`
query Stream($id: String!){
-6
View File
@@ -1,6 +0,0 @@
query{
serverInfo {
name
canonicalUrl
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
query Stream($id: String!, $limit: Int!) {
query Stream($id: String!) {
stream(id: $id) {
id
name
@@ -27,7 +27,7 @@ query Stream($id: String!, $limit: Int!) {
referencedObject
}
}
branches (limit: $limit) {
branches {
totalCount
items {
id
+3 -9
View File
@@ -1,12 +1,12 @@
require('url')
export class StreamWrapper {
constructor(streamIdOrUrl, accountId, serverUrl) {
this.isFE2 = this.checkIsFE2(streamIdOrUrl)
constructor(streamIdOrUrl, accountId, serverUrl, isFE2) {
this.isFE2 = isFE2
this.streamsKey = this.isFE2 ? 'projects/': 'streams/'
this.branchesKey = this.isFE2 ? 'models/': 'branches/'
this.commitsKey = this.isFE2 ? 'versions/': 'commits/'
this.originalOutput = streamIdOrUrl
this.originalOutput = streamIdOrUrl
try {
this.streamWrapperFromUrl(streamIdOrUrl)
}
@@ -17,12 +17,6 @@ export class StreamWrapper {
}
}
checkIsFE2(streamUrl){
const fe2UrlRegex = /\/projects\/(?<projectId>[\w\d]+)(?:\/models\/(?<model>[\w\d]+(?:@[\w\d]+)?)(?:,(?<additionalModels>[\w\d]+(?:@[\w\d]+)?))*)?/
const match = fe2UrlRegex.exec(streamUrl);
return match !== null;
}
streamWrapperFromUrl(streamUrl){
this.url = new URL(streamUrl)
this.segments = this.url.pathname.split('/').map((segment) => segment + '/')
+3 -7
View File
@@ -17,7 +17,7 @@
</div>
<div v-if="allStreamsList" class="mt-5">
<div v-for="stream in allStreamsList" :key="stream.id">
<stream-card :stream-id="stream.id"/>
<stream-card :stream-id="stream.id" />
</div>
<div class="actions text-center">
<v-btn
@@ -59,10 +59,7 @@ export default {
StreamCard: () => import('@/components/StreamCard')
},
props: {
streamSearchQuery: {
type: String,
default: null
}
streamSearchQuery: { type: String, default: null }
},
data() {
return {
@@ -124,13 +121,12 @@ export default {
if (!this.savedStreams){
this.savedStreams = []
this.savedStreams.push(streamId)
sketchup.exec({name: "save_stream", data: {stream_id: streamId}})
} else {
if (!this.savedStreams.includes(streamId)){
this.savedStreams.push(streamId)
sketchup.exec({name: "save_stream", data: {stream_id: streamId}})
}
}
sketchup.exec({name: "save_stream", data: {stream_id: streamId}})
})
sketchup.exec({name: "load_saved_streams", data: {}})
console.log('LAUNCHED')
+3 -3
View File
@@ -12,7 +12,7 @@ if (process.env.NODE_ENV === 'development') {
localStorage.setItem(AUTH_TOKEN, process.env.VUE_APP_DEV_TOKEN)
localStorage.setItem('serverUrl', process.env.VUE_APP_DEFAULT_SERVER)
} else if (!localStorage.getItem('serverUrl')) {
localStorage.setItem('serverUrl', 'https://app.speckle.systems')
localStorage.setItem('serverUrl', 'https://speckle.xyz')
}
const authLink = setContext((_, { headers }) => {
@@ -34,7 +34,7 @@ const defaultOptions = {
return (
(localStorage.getItem('serverUrl').includes('http')
? localStorage.getItem('serverUrl')
: 'https://app.speckle.systems') + '/graphql'
: 'https://speckle.xyz') + '/graphql'
)
},
@@ -43,7 +43,7 @@ const defaultOptions = {
wsEndpoint: (
(localStorage.getItem('serverUrl').includes('http')
? localStorage.getItem('serverUrl')
: 'https://app.speckle.systems') + '/graphql'
: 'https://speckle.xyz') + '/graphql'
).replace('http', 'ws'),
// LocalStorage token