-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: Add mobile mode to the conversation, support ctrl/shift/cmd/opt… #2615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
:close-on-click-modal="false" | ||
:close-on-press-escape="false" | ||
> | ||
|
||
<el-row :gutter="12"> | ||
<el-col :span="12"> | ||
<el-col :span="8"> | ||
<div class="border"> | ||
<p class="title p-16 bold"> | ||
{{ $t('views.applicationOverview.appInfo.EmbedDialog.fullscreenModeTitle') }} | ||
|
@@ -31,7 +32,30 @@ | |
</div> | ||
</div> | ||
</el-col> | ||
<el-col :span="12"> | ||
<el-col :span="8"> | ||
<div class="border"> | ||
<p class="title p-16 bold"> | ||
{{ $t('views.applicationOverview.appInfo.EmbedDialog.mobileModeTitle') }} | ||
</p> | ||
<img src="@/assets/window3.png" alt="" class="ml-8" height="150" /> | ||
<div class="code layout-bg border-t p-8"> | ||
<div class="flex-between p-8"> | ||
<span class="bold">{{ | ||
$t('views.applicationOverview.appInfo.EmbedDialog.copyInstructions') | ||
}}</span> | ||
<el-button text @click="copyClick(source3)"> | ||
<AppIcon iconName="app-copy"></AppIcon> | ||
</el-button> | ||
</div> | ||
<el-scrollbar height="150" always> | ||
<div class="pre-wrap p-8 pt-0"> | ||
{{ source3 }} | ||
</div> | ||
</el-scrollbar> | ||
</div> | ||
</div> | ||
</el-col> | ||
<el-col :span="8"> | ||
<div class="border"> | ||
<p class="title p-16 bold"> | ||
{{ $t('views.applicationOverview.appInfo.EmbedDialog.floatingModeTitle') }} | ||
|
@@ -76,6 +100,7 @@ const dialogVisible = ref<boolean>(false) | |
const source1 = ref('') | ||
|
||
const source2 = ref('') | ||
const source3 = ref('') | ||
|
||
const urlParams1 = computed(() => (props.apiInputParams ? '?' + props.apiInputParams : '')) | ||
const urlParams2 = computed(() => (props.apiInputParams ? '&' + props.apiInputParams : '')) | ||
|
@@ -84,6 +109,7 @@ watch(dialogVisible, (bool) => { | |
if (!bool) { | ||
source1.value = '' | ||
source2.value = '' | ||
source3.value = '' | ||
} | ||
}) | ||
|
||
|
@@ -105,6 +131,14 @@ src="${window.location.origin}/api/application/embed?protocol=${window.location. | |
)}&host=${window.location.host}&token=${val}${urlParams2.value}"> | ||
<\/script> | ||
` | ||
source3.value = `<iframe | ||
src="${application.location + val + urlParams1.value}&mode=mobile" | ||
style="width: 100%; height: 100%;" | ||
frameborder="0" | ||
allow="microphone"> | ||
</iframe> | ||
` | ||
|
||
dialogVisible.value = true | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few areas where the code can be improved:
Here's an updated version assuming you want to streamline it while keeping functionality intact: <script setup lang="ts">
import { onMounted, ref } from 'vue';
import AppIcon from '@/components/AppIcon.vue'
let dialogVisible = ref(false)
// Store initial states as array
const sources = [source1, source2, source3]
for(let i=0 ; i<sources.length ; ++i){
sources[i] = ref('');
}
const modeOptions = ["fullscreen", "mobile", "floating"];
const apiInputParams = ref(''); // Use this variable
onMounted(() => {
setSource(1); // initialize first mode
})
function copyClick(value: string): void {
navigator.clipboard.writeText(value);
}
function setSource(modeIndex: number): void {
let targetURL = application.location;
targets[modeIndex].value = `
<button onclick="openPopup('${targetURL}',${params})">Try It</button>
<script type='text/template'>
function openPopup(url,val){ window.open(`${window.location.origin}/api/application/embed/${mode}`,
`${window.location.hostname}:${window.location.port}`)
}
</script>`
switch (modeIndex) {
case 0:
break;
case 1:
targetURL = targetURL + val;
addTargetValue(src="${targetURL}${params}",height = '400',width = '400'), style = 'all');
break;
default:
addTargetValue(`<iframe src="${targetURL}${params}" style="width:${modeWidth}px;height:${modeHeight}px;"></iframe>`)
}
dialogVisible.value = true;
}
function addTargetValue(htmlContent: string, height?: number | string, width?: number | string, cssClass?: string): void{
modesHtml.append(htmlContent);
const frameElement = document.createElement("iframe");
if(height && typeof height === 'number'){
frameElement.style.height = height.toString();
}else if(width && typeof width === 'string'){
frameElement.style.width = width;
}
if(cssClass){
frameElement.className = cssClass
} else if(window.innerWidth > 600){
frameElement.src = window.document.baseURI+ "/assets/frame-full-width.html?url="+ encodeURIComponent(application.location.replace("https://github.com/","").replace(/\/$/, ""));
}else{
frameElement.src = window.document.baseURI+"/assets/frame-mobile.html?url="+encodeURIComponent(application.location.replace("https://github.com/",""));
}
} This snippet assumes that |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code snippet you provided has several areas that need attention:
Computed Property Optimization:
showUserInputContent
computed property is redundant because it effectively does the same thing asshowUserInput
. You can remove one of them to simplify the logic.Variable Redundancy:
_inputVisible
,_inputShowed
, and_focusStatus
are declared but not used. These should be removed or reassigned if they are meant to have a purpose.Template Syntax Simplification:
<template>
tags can be removed. For example, the innermost template tag can often be simplified.Conditional Rendering:
v-if
) and computed properties align. Sometimes, conditions might lead to unexpected behavior due to logical errors.Code Consistency:
Here’s an optimized version of the code considering these points:
Key Changes:
_inputVisible
,_inputShowed
, and_focusStatus
.<template>
tags.mode
to"embed"
instead of"emibe"
.This cleaned-up version reduces redundancy, maintains readability, and ensures the component behaves predictably. Make sure all changes align with your project's requirements and best practices.