Skip to content
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

Remove reactive options #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"private": true,
"scripts": {
"dev": "rm -rf ./node_modules/.vite/ && vite",
"vite": "vite",
"build": "vue-tsc --skipLibCheck && vite build",
"preview": "vite preview",
"deploy": "vite build && gh-pages -d dist"
Expand All @@ -13,7 +14,7 @@
"vue": "^3.4.15"
},
"devDependencies": {
"@doiim/waku-chat-vue-plugin": "^0.8.27",
"@doiim/waku-chat-vue-plugin": "^0.8.29",
"@vitejs/plugin-vue": "^5.0.4",
"gh-pages": "^6.1.1",
"typescript": "^5.3.3",
Expand Down
214 changes: 1 addition & 213 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,93 +54,6 @@
/>
</div>
</div>

<hr class="split-section">
<h3>History Settings:</h3><br/>

<div class="behaviour-controls">


<div class="toggle-container">
<label class="toggle-label">
Load messages on scroll
<div class="toggle-switch">
<input
type="checkbox"
v-model="fetchMsgsOnScroll"
@change="updateFetchMsgsOnScroll"
>
<span class="slider"></span>
</div>
</label>
</div>

<div class="flex">
<div class="input-container">
<label for="fetchLimitInput">Messages {{fetchMsgsOnScroll ? 'per fetch' : 'to fetch'}}:</label>
<div>
<input
type="number"
v-model="fetchLimitInput"
id="fetchLimitInput"
:placeholder="fetchMsgsOnScroll ? '10' : '100'"
/>
</div>
</div>
<div class="input-container">
<label for="maxAttemptsInput">Max {{fetchMsgsOnScroll ? 'fetch attempts' : 'attempts'}}:</label>
<div>
<input
type="number"
v-model="maxAttemptsInput"
id="maxAttemptsInput"
placeholder="3"
/>
</div>
</div>
<div v-if="fetchMsgsOnScroll" class="input-container">
<label for="fetchTotalLimitInput">Max total messages:</label>
<div>
<input
type="text"
v-model="fetchTotalLimitInput"
id="fetchTotalLimitInput"
placeholder="0 = Full History"
/>
</div>
</div>
<div v-if="!fetchMsgsOnScroll" class="input-container message-age-selector">
<label for="messageAgeSelect">Time Range:</label>
<div>
<select
v-model="selectedMessageAge"
id="messageAgeSelect"
@change="updateMessageAge"
>
<option value="1">Last 24 hours</option>
<option value="3">Last 3 days</option>
<option value="7">Last 7 days</option>
<option value="14">Last 2 weeks</option>
<option value="30">Last 30 days</option>
<option value="custom">Custom...</option>
</select>
</div>
</div>
<div v-if="!fetchMsgsOnScroll && selectedMessageAge === 'custom'" class="input-container" >
<label for="customDays">Nº of days:</label>
<div>
<input
type="number"
v-model="customDays"
id="customDays"
min="1"
max="365"
@change="updateMessageAge"
/>
</div>
</div>
</div>
</div>
<hr class="split-section">
<h3>External Events:</h3><br/>
<div class="flex">
Expand Down Expand Up @@ -333,18 +246,13 @@
:balloonPos="computedBalloonPos"
:animationDirection="animation"
:chatSize="{ width: widthInput, height: heightInput }"
:fetchMsgsOnScroll="fetchMsgsOnScroll"
:fetchMaxAttempts="parseInt(maxAttemptsInput)"
:fetchTotalLimit="parseInt(fetchTotalLimitInput)"
:fetchLimit="parseInt(fetchLimitInput)"
:messageAgeToDownload="messageAge"
/>
</div>
</div>
</template>

<script setup lang="ts">
import { ref, computed, nextTick } from "vue";
import { ref, computed } from "vue";
const wakuChatRef = ref<any>(null);
const debugMode = ref(false);
const chatOpened = ref(false);
Expand Down Expand Up @@ -376,16 +284,6 @@ const heightInput = ref("576px");

const animation = ref("up");


const fetchMsgsOnScroll = ref(true);
const maxAttemptsInput = ref();
const fetchLimitInput = ref();
const fetchTotalLimitInput = ref();

const selectedMessageAge = ref('1');
const customDays = ref(1);
const messageAge = ref<number| undefined>(undefined);

const onConnect = () => {
message.value = "Connected to the Chat";
};
Expand Down Expand Up @@ -481,22 +379,6 @@ const computedBalloonPos = computed(() => ({
[balloonPosLeftRight.value]: `${balloonPosValue.value.horizontal}%`,
}));

const updateFetchMsgsOnScroll = async () => {
await nextTick();
if(fetchMsgsOnScroll.value == false) {
updateMessageAge();
}else{
messageAge.value = undefined;
}
};

const updateMessageAge = () => {
const days = selectedMessageAge.value === 'custom'
? customDays.value
: parseInt(selectedMessageAge.value);
const milliseconds = days * 24 * 60 * 60 * 1000;
messageAge.value = milliseconds;
};
</script>

<style scoped>
Expand Down Expand Up @@ -684,98 +566,4 @@ button {
margin: 20px 0;
}

.toggle-container {
display: flex;
align-items: center;
margin-bottom: 16px;
}

.toggle-label {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
cursor: pointer;
}

.toggle-switch {
position: relative;
display: inline-block;
width: 50px;
height: 24px;
margin-left: 16px;
}

.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 24px;
}

.slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}

.light input:checked + .slider {
background-color: #007bff;
}

.dark input:checked + .slider {
background-color: #2563eb;
}

input:checked + .slider:before {
transform: translateX(26px);
}

.light .slider {
background-color: #ccc;
}

.dark .slider {
background-color: #4b5563;
}

.message-age-selector select {
width: 100%;
padding: 8px;
padding-right: 24px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: var(--input-bg-color);
color: var(--text-color);
-webkit-appearance: menulist; /* For Safari */
-moz-appearance: menulist; /* For Firefox */
appearance: menulist; /* Standard */
}

.light .message-age-selector select {
--input-bg-color: #fff;
--text-color: #000;
}

.dark .message-age-selector select {
--input-bg-color: #374151;
--text-color: #d1d5db;
}
</style>