Skip to content

Commit

Permalink
iframeize app package
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Nov 15, 2023
1 parent 08b8c72 commit bf98945
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ TODO.md
+ display block
appBlockAppPackage

+ hide text chat on wait package

+ articles frame are not in iframe, iframeize it

improvements UI
5 changes: 2 additions & 3 deletions app/controllers/apps/packages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ def configure
}.with_indifferent_access
})

Rails.logger.debug @blocks
Rails.logger.debug "CLBLBLBLBL"
Rails.logger.debug @blocks[:kind]
# Rails.logger.debug @blocks
# Rails.logger.debug @blocks[:kind]
case @blocks[:kind]
when "configure", nil
@blocks[:kind] = "configure" if @blocks[:kind].blank?
Expand Down
19 changes: 15 additions & 4 deletions app/controllers/concerns/package_iframe_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,24 @@ def package_iframe
end

if params[:messengerFrame]
render turbo_stream: [
turbo_stream.update("bbbb", inline: html.html_safe),
turbo_stream.replace("header-content", partial: "messenger/base_header", locals: { app: @app })
] and return
# render turbo_stream: [
# turbo_stream.update("bbbb", inline: html.html_safe),
# turbo_stream.replace("header-content", partial: "messenger/base_header", locals: { app: @app })
# ] and return

respond_to do |format|
format.turbo_stream do
@html = html
render "apps/packages/package_iframe_internal", layout: false
end
format.html do
render html: html.html_safe, layout: false
end
end
end

render html: html.html_safe, layout: false

# rubocop:enable Rails/OutputSafety
end

Expand Down
2 changes: 0 additions & 2 deletions app/javascript/controllers/messenger_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ export default class extends Controller {
// console.log('Received message from parent:', event.data);
}



streamListener() {
const element = document.querySelector(
'#chaskiq-streams turbo-cable-stream-source'
Expand Down
56 changes: 28 additions & 28 deletions app/javascript/controllers/messenger_conversation_controller.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static targets = ["conversationPart"];
static targets = ['conversationPart'];

connect() {
this.observer = new MutationObserver(mutations => this.onMutation(mutations));
this.observer = new MutationObserver((mutations) =>
this.onMutation(mutations)
);
this.observeConversation();
this.checkForInput()
this.checkForInput();
}

disconnect() {
Expand All @@ -15,48 +17,46 @@ export default class extends Controller {

observeConversation() {
const conversationElement = this.element;
console.log("OVSERVE", this.element)
console.log('OVSERVE', this.element);
this.observer.observe(conversationElement, { childList: true });
}

onMutation(mutations) {
mutations.forEach(mutation => {
console.log(mutation)
mutations.forEach((mutation) => {
console.log(mutation);
if (mutation.type === 'childList') {
// Handle added or removed conversation parts
this.handleConversationChange();
this.handleConversationChange();
}
});
this.handleConversationChange();
console.log("mutation observed cycle")
console.log('mutation observed cycle');
}

handleConversationChange() {
// Your logic here, executed when conversation parts change
console.log('Conversation parts have changed.');
this.checkForInput()
this.checkForInput();
}

checkForInput(){
const state = this.isInputEnabled()
if(state){
document.getElementById("chat-editor").classList.remove("hidden")
}else {
document.getElementById("chat-editor").classList.add("hidden")
checkForInput() {
const state = this.isInputEnabled();
if (state) {
document.getElementById('chat-editor').classList.remove('hidden');
} else {
document.getElementById('chat-editor').classList.add('hidden');
}

console.log("INPUT RNABLED", state)
console.log('INPUT RNABLED', state);
}


isInputEnabled() {
const conversationData = this.element.dataset;

const conversationData = this.element.dataset
if (conversationData.closed === 'true') return true;

if(conversationData.closed === "true") return true
if (!this.hasConversationPartTarget) return true;

if(!this.hasConversationPartTarget) return true

/*if(!this.hasConversationTarget) return
if (this.conversationTarget.closed === 'closed') {
Expand All @@ -78,15 +78,15 @@ export default class extends Controller {
// strict comparison of false
if (message.blocks && message.blocks.wait_for_input === false) return true;
if (message.blocks && message.blocks.waitForInput === false) return true;*/
const message = this.conversationPartTargets[0]
const message = this.conversationPartTargets[0];

const data = message.dataset
const data = message.dataset;

if(data.blockKind === "app_package" || data.blockKind === "ask_option"){
if( data.replied === "true") return true
return false
if (data.blockKind === 'app_package' || data.blockKind === 'ask_option') {
if (data.replied === 'true') return true;
return false;
}

return true
return true;
}
}
}
2 changes: 1 addition & 1 deletion app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ def html_from_serialized
return if json.blank?

data = ActiveSupport::HashWithIndifferentAccess.new(json)
Dante::Renderer.new(raw: data).render
Dante::Renderer.new(raw: data, domain: Chaskiq::Config.get("HOST")).render
end
end

0 comments on commit bf98945

Please sign in to comment.