Skip to content

Commit

Permalink
Merge pull request #152 from radio4000/fix/single-channel2
Browse files Browse the repository at this point in the history
Fix r4-app selectedChannel prop
  • Loading branch information
oskarrough authored Oct 30, 2023
2 parents dcba1b5 + 56a0b81 commit 707be80
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 3 additions & 1 deletion examples/r4-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
const $app = document.createElement('r4-app')
const params = new URLSearchParams(window.location.search)
const channel = params.get('channel')
const singleChannel = params.get('single-channel')
const singleChannel = params.has('single-channel')

//$app.setAttribute('cdn', true)
//$app.setAttribute('cdn', 'https://jsdelivr.net/npm/@radio4000/components')
$app.setAttribute('href', window.location.origin + '/examples/r4-app/')
channel && $app.setAttribute('channel', channel)
singleChannel && $app.setAttribute('single-channel', true)
/* !import.meta.env.PROD && $app.setAttribute('themes-url', 'http://localhost:4001') */

console.log({channel, singleChannel})
document.querySelector('body').append($app)
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/components/r4-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class R4App extends LitElement {
this.refreshUserData.running = true

if (!this.user) {
this.selectedSlug = null
if (!this.singleChannel) this.selectedSlug = null
this.userChannels = []
this.followers = []
this.following = []
Expand Down
12 changes: 2 additions & 10 deletions src/pages/base-channel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {html, LitElement} from 'lit'
import {html} from 'lit'
import {sdk} from '@radio4000/sdk'
import R4Page from '../components/r4-page.js'
import urlUtils from '../libs/url-utils.js'

// Base class to extend from
export default class BaseChannel extends R4Page {
Expand All @@ -20,13 +19,6 @@ export default class BaseChannel extends R4Page {
searchParams: {type: Object, state: true},
}

async willUpdate(changedProperties) {
if (changedProperties.has('params')) {
console.log('fetching channel because params changed')
// await this.setChannel()
}
}

async connectedCallback() {
super.connectedCallback()
if (!this.channel) {
Expand Down Expand Up @@ -80,7 +72,7 @@ export default class BaseChannel extends R4Page {
return this.store.followers?.map((c) => c.slug).includes(this.config.selectedSlug)
}

// Set channel from the slug in the URL.
// Set channel from the config or URL params.
async setChannel() {
const slug = this.config.singleChannel && this.config.selectedSlug ? this.config.selectedSlug : this.params.slug

Expand Down

0 comments on commit 707be80

Please sign in to comment.