Skip to content

Commit

Permalink
dev: Dialog is now InputDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
lscambo13 committed Jan 3, 2024
1 parent b490122 commit fc7d1a1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { saveDropdownPositions } from './js_modules/save_preferences.js';
import { getLastUpdated } from './js_modules/utils/getLastUpdated.js';
import { blurLevel } from './js_modules/utils/blurLevel.js';
import { isItChristmas } from './js_modules/utils/letItSnow.js';
import { Dialog } from './js_modules/utils/dialog.js';
import { InputDialog } from './js_modules/utils/inputDialog.js';
import { isTouchDevice } from './js_modules/utils/isTouchDevice.js';
import { enableSubmitButton } from './js_modules/utils/enableSubmitButton.js';

Expand Down Expand Up @@ -109,26 +109,26 @@ const wallpapersPanel = (str) => {
};

window.createNewBookmark = () => {
const dialogTitle = 'Add new bookmark';
const dialogDescription = `
const inputDialogTitle = 'Add new bookmark';
const inputDialogDescription = `
You may only use upto four letters as the bookmark name.`;
const bookmarkLabel = 'Bookmark name';
const bookmarkAddress = 'Link to website';

Dialog.show(
dialogTitle,
dialogDescription,
InputDialog.show(
inputDialogTitle,
inputDialogDescription,
[bookmarkLabel, bookmarkAddress],
'Save',
undefined,
null,
[() => enableSubmitButton(event, true), null],
() => {
const label = Dialog.getInputFields()[0];
const label = InputDialog.getInputFields()[0];
label.setAttribute('maxlength', 4);
label.setAttribute('placeholder', 'e.g. YT');

const address = Dialog.getInputFields()[1];
const address = InputDialog.getInputFields()[1];
address.setAttribute('placeholder', 'e.g. youtube.com');
address.value = 'https://';

Expand Down
16 changes: 8 additions & 8 deletions js_modules/custom_bookmarks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dialog } from './utils/dialog.js';
import { InputDialog } from './utils/inputDialog.js';
import { enableSubmitButton } from './utils/enableSubmitButton.js';
import { crossDisplay } from './utils/toggleDisplay.js';

Expand Down Expand Up @@ -112,9 +112,9 @@ export function editBookmark(event) {
const targetElement = event.target.parentNode;

const onChange = () => {
const checkbox = Dialog.getCheckboxField();
const modalSubmitButton = Dialog.getSubmitButton();
const inputFields = Dialog.getInputFields();
const checkbox = InputDialog.getCheckboxField();
const modalSubmitButton = InputDialog.getSubmitButton();
const inputFields = InputDialog.getInputFields();

if (checkbox.checked) {
modalSubmitButton.textContent = 'Delete';
Expand All @@ -134,17 +134,17 @@ export function editBookmark(event) {

const details = getBookmarkDetailsFromLocalStorage(targetElement.id);

Dialog.show('Edit bookmark',
InputDialog.show('Edit bookmark',
null,
['Name', 'Address'],
'Save',
'Cancel',
'Delete this bookmark',
[() => enableSubmitButton(event, true), onChange],
() => {
Dialog.getInputFields()[0].setAttribute('maxlength', '4');
Dialog.getInputFields()[0].value = details[1];
Dialog.getInputFields()[1].value = details[2];
InputDialog.getInputFields()[0].setAttribute('maxlength', '4');
InputDialog.getInputFields()[0].value = details[1];
InputDialog.getInputFields()[1].value = details[2];
},
).then((res) => {
if (res.checkboxChecked) {
Expand Down
10 changes: 5 additions & 5 deletions js_modules/load_preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from './constants.js';
import { displayClock, refreshGreeting } from './preferences.js';
import { fixBackgroundBlurOnResize } from './utils.js';
import { Dialog } from './utils/dialog.js';
import { InputDialog } from './utils/inputDialog.js';
import { enableSubmitButton } from './utils/enableSubmitButton.js';
import { intersectionObserver } from './utils/intersectionObserver.js';

Expand Down Expand Up @@ -239,7 +239,7 @@ function defaultWidget(value) {

export function askCustomText() {
const savedText = localStorage.getItem('customWidgetText');
Dialog.show(
InputDialog.show(
'Custom widget text',
'Enter text you want to set as the main widget.',
['Custom text'],
Expand All @@ -248,7 +248,7 @@ export function askCustomText() {
null,
[enableSubmitButton, null],
() => {
Dialog.getInputFields()[0].value = savedText;
InputDialog.getInputFields()[0].value = savedText;
},
).then((res) => {
localStorage.setItem('customWidgetText', res.inputValues[0]);
Expand All @@ -261,7 +261,7 @@ export function askCustomText() {

export function askCustomDomain() {
const savedDomain = localStorage.getItem('customDomain');
Dialog.show(
InputDialog.show(
'Custom widget text',
'Enter text you want to set as the main widget.',
['Custom text'],
Expand All @@ -270,7 +270,7 @@ export function askCustomDomain() {
null,
[enableSubmitButton, null],
() => {
Dialog.getInputFields()[0].value = savedDomain;
InputDialog.getInputFields()[0].value = savedDomain;
},
).then((res) => {
localStorage.setItem('customDomain', res.inputValues[0]);
Expand Down
12 changes: 6 additions & 6 deletions js_modules/onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DEF_PREF, DEF_WALLPAPER } from './constants.js';
import { updateUserNamePreview } from './load_preferences.js';
import { refreshGreeting } from './preferences.js';
import { updateUserNameText } from './strings.js';
import { Dialog } from './utils/dialog.js';
import { InputDialog } from './utils/inputDialog.js';
import { enableSubmitButton } from './utils/enableSubmitButton.js';

export function askUserName() {
Expand All @@ -22,7 +22,7 @@ export function askUserName() {
// };

if (userName) {
Dialog.show(
InputDialog.show(
'Update your name',
updateUserNameText,
['Change name to'],
Expand All @@ -31,8 +31,8 @@ export function askUserName() {
null,
[enableSubmitButton, null],
() => {
Dialog.getInputFields()[0].setAttribute('maxlength', 17);
Dialog.getInputFields()[0].value = userName;
InputDialog.getInputFields()[0].setAttribute('maxlength', 17);
InputDialog.getInputFields()[0].value = userName;
},
).then((res) => {
userName = res.inputValues[0];
Expand All @@ -48,7 +48,7 @@ export function askUserName() {
};

if (!userName) {
const onBoardingInProgress = Dialog.show(
const onBoardingInProgress = InputDialog.show(
'Welcome to Casa Mia',
`Hi! We are so excited to see you here.
Please fill out the following details before moving forward. `,
Expand All @@ -58,7 +58,7 @@ export function askUserName() {
null,
[enableSubmitButton, null],
() => {
Dialog.getInputFields()[0].setAttribute('maxlength', 17);
InputDialog.getInputFields()[0].setAttribute('maxlength', 17);
},
);
onBoardingInProgress.then((res) => {
Expand Down
6 changes: 3 additions & 3 deletions js_modules/utils/enableSubmitButton.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isUrlValid } from '../validators.js';
import { Dialog } from './dialog.js';
import { InputDialog } from './inputDialog.js';

export const enableSubmitButton = (event, alt = false) => {
const modalSubmitButton = Dialog.getSubmitButton();
const inputFields = Dialog.getInputFields();
const modalSubmitButton = InputDialog.getSubmitButton();
const inputFields = InputDialog.getInputFields();
for (const e of inputFields) {
if (e.value.length) modalSubmitButton.disabled = false;
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let modalCancelButton;
let tickBoxField;
let inputFields;

const showInputDialog = (
const showInputInputDialog = (
title = null,
description = null,
inputBoxes = ['Input A', 'Input B'],
Expand Down Expand Up @@ -135,8 +135,8 @@ const showInputDialog = (
return promise;
};

export const Dialog = {
show: showInputDialog,
export const InputDialog = {
show: showInputInputDialog,
getSubmitButton: () => {
return modalSubmitButton;
},
Expand Down

0 comments on commit fc7d1a1

Please sign in to comment.