Skip to content

Commit 562fc06

Browse files
committedFeb 10, 2023
fix components
1 parent 30fecb0 commit 562fc06

9 files changed

+940
-306
lines changed
 

‎.eslintrc.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"prettier"
5+
],
6+
"plugins": [],
7+
"parserOptions": {
8+
"ecmaVersion": 2022,
9+
"sourceType": "module"
10+
},
11+
"env": {
12+
"es6": true,
13+
"node": true,
14+
"browser": true
15+
}
16+
}

‎.prettierrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

‎package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
"preview": "vite preview"
1010
},
1111
"devDependencies": {
12-
"autoprefixer": "^10.4.8",
13-
"postcss": "^8.4.14",
14-
"tailwindcss": "^3.1.7",
15-
"typescript": "^4.6.4",
16-
"vite": "^3.0.0"
12+
"autoprefixer": "^10.4.13",
13+
"eslint": "^8.33.0",
14+
"eslint-config-prettier": "^8.6.0",
15+
"postcss": "^8.4.21",
16+
"prettier": "^2.8.4",
17+
"tailwindcss": "^3.2.6",
18+
"typescript": "^4.9.5",
19+
"vite": "^4.1.1"
1720
},
1821
"dependencies": {
19-
"@odoo/owl": "2.0.0-beta-16"
22+
"@odoo/owl": "2.0.5"
2023
}
2124
}

‎pnpm-lock.yaml

+890-267
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/Root.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,19 @@ state.selectedTechnology: <t t-esc="toJsonString(state.selectedTechnology)"/>
7070
export type MenuItem = {
7171
id: string;
7272
name: string;
73+
callBack?: (menuItem: MenuItem) => void;
74+
};
75+
76+
export type RootState = {
77+
menuItems: MenuItem[];
78+
selectedMenu?: MenuItem;
79+
searchData: { id: number; name: string }[];
80+
selectedTechnology?: { id?: number; name: string };
7381
};
7482
export class Root extends Component {
7583
static template = ROOT_TEMPLATE;
7684
static components = { MyComponent, DropDown, AutoCompleteInput };
77-
state = useState({
85+
state = useState<RootState>({
7886
menuItems: [
7987
{
8088
id: "item-1",
@@ -92,7 +100,7 @@ export class Root extends Component {
92100
callBack: (menuItem: MenuItem) => this.clickMenu(menuItem),
93101
},
94102
],
95-
selectedMenu: {},
103+
selectedMenu: undefined,
96104
searchData: [
97105
{ id: 1, name: "Rollup.js" },
98106
{ id: 2, name: "Webpack" },
@@ -104,20 +112,15 @@ export class Root extends Component {
104112
{ id: 8, name: "Vue" },
105113
{ id: 9, name: "React" },
106114
],
107-
selectedTechnology: null,
115+
selectedTechnology: undefined,
108116
});
109117

110118
clickMenu(menuItem: MenuItem) {
111-
console.log(menuItem);
112-
// Object.assign(this.state, { selectedMenu: menuItem });
113119
this.state.selectedMenu = menuItem;
114-
console.log("this.state.selectedMenu", this.state.selectedMenu);
115120
}
116121

117122
onOptionChosen(selectedTechnology: { name: string; optional: boolean }) {
118-
Object.assign(this.state, {
119-
selectedTechnology,
120-
});
123+
this.state.selectedTechnology = selectedTechnology;
121124
}
122125

123126
toJsonString(obj: object) {

‎src/components/AutoCompleteInput.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ export class AutoCompleteInput extends Component {
7373
reset() {
7474
// this.trigger("input", "");
7575
// this.trigger("chosen", { selectedTechnology: null });
76-
Object.assign(this.state, {
77-
chosenOption: "",
78-
searchTerm: "",
79-
showOptions: false,
80-
});
76+
this.state.chosenOption = "";
77+
this.state.searchTerm = "";
78+
this.state.showOptions = false;
8179
}
8280

8381
handleShowOptions(evt: Event) {

‎src/components/DropDown.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, useState, xml, useExternalListener, useRef } from "@odoo/owl";
1+
import {
2+
Component,
3+
useState,
4+
xml,
5+
useExternalListener,
6+
useRef,
7+
} from "@odoo/owl";
28

39
const DROPDOWN_TEMPLATE = xml/*xml*/ `
410
<div t-ref="DropDown" class="relative inline-block text-left">
@@ -56,6 +62,7 @@ export class DropDown extends Component {
5662
optional: true,
5763
},
5864
dropdownLeft: { type: Boolean, optional: true },
65+
slots: {},
5966
};
6067
state = useState({ open: false });
6168
dropdownContainerRef = useRef("DropDown");

‎src/main.ts

-17
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,3 @@ import { Root } from "./Root";
55

66
const app = new App(Root, { dev: true });
77
app.mount(document.getElementById("app")!, {});
8-
9-
const addSpaces = (input: string, spacesToAdd: number) => {
10-
for (let i = 0; i < spacesToAdd; i++) {
11-
input += " ";
12-
}
13-
return input;
14-
};
15-
16-
const recursiveAddSpaces = (input: string, spacesToAdd: number): string => {
17-
if (spacesToAdd === 0) {
18-
return input;
19-
}
20-
return recursiveAddSpaces(input + " ", spacesToAdd - 1);
21-
};
22-
23-
console.log(addSpaces("Hello", 2));
24-
console.log(recursiveAddSpaces("Hello", 2));

‎tailwind.config.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
content: ["./index.html", "./src/**/*.{vue,js,ts,jsx,tsx,xml}"],
44
theme: {
55
extend: {
6-
backgroundImage: (theme) => ({
6+
backgroundImage: () => ({
77
"storefront-colour": "url('/storefront-colour.svg')",
88
}),
99
colors: {

0 commit comments

Comments
 (0)
Please sign in to comment.