-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Web Tutorial PR: trcaz #967
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
base: 18.0
Are you sure you want to change the base?
Conversation
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.
Amazing job
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.
You named your commit sections 8-9 but this contains section 10 🤨
88c95bf
to
bc43839
Compare
Co-authored-by: Cemal Faruk Güney <[email protected]>
Co-authored-by: Cemal Faruk Güney <[email protected]>
Co-authored-by: Cemal Faruk Güney <[email protected]>
b73ff1c
to
9d8ff02
Compare
8630778
to
143eec9
Compare
|
||
export class PieChart extends Component { | ||
static template = "awesome_dashboard.pie_chart"; | ||
static props = { data: {optional: false}} |
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.
Every prop is required by default. You don't have to write it unless it's optional: true
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.
I know but I just didn't want to type check the data because it's json and annoying but I still wanted to require the data prop
} | ||
|
||
setup() { | ||
this.size = this.props.size || 1 |
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.
You can also use defaultProps
async function loadData() { | ||
console.log("slt") | ||
const newStats = await rpc("/awesome_dashboard/statistics"); | ||
Object.keys(newStats).forEach((k) => stats[k] = newStats[k]) |
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.
why can't you do something like stats = newStats?
why did you have to iterate over the keys?
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.
When I did that it didn't register the change, maybe because it overwrote the useState, idk
I can try again
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.
Nope doesn't work with stats = newStats
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.
Object.assign(stats, newStats)
maybe
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.
How on god's green earth was I supposed to find that out
…ials into 18.0-web-tutorial-trcaz
14a06af
to
82c0d40
Compare
</t> | ||
|
||
<t t-foreach="items" t-as="item" t-key="item.id"> | ||
<DashboardItem size="item.size"> |
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.
What happens if they don't have size? I saw that you don't have a default value
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.
this.size = this.props.size || 1
import { _t } from "@web/core/l10n/translation"; | ||
import { DashboardItem } from "./dashboard_item"; | ||
import { PieChart } from "./pie_chart/pie_chart"; | ||
import { browser } from "@web/core/browser/browser"; |
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.
👀
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.
?
this.stats = useState(useService("awesome_dashboard.statistics")); | ||
this.items = registry.category("awesome_dashboard").getAll(); | ||
this.dialog = useService("dialog"); | ||
this.state = useState({ itemsNotShown: browser.localStorage.getItem("itemsNotShown")?.split(",") || []}); |
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.
this.state = useState({ itemsNotShown: browser.localStorage.getItem("itemsNotShown")?.split(",") || []}); | |
this.state = useState({ itemsNotShown: localStorage.getItem("itemsNotShown")?.split(",") || []}); |
just localStorage should be enough. Or maybe I'm dreaming 📦
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.
idk I had no idea how to do it so I just looked it up
this.stats = useState(useService("awesome_dashboard.statistics")); | ||
this.items = registry.category("awesome_dashboard").getAll(); | ||
this.dialog = useService("dialog"); | ||
this.state = useState({ itemsNotShown: browser.localStorage.getItem("itemsNotShown")?.split(",") || []}); |
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.
It's confusing to have a state variable called state when you already have other state variables (stats). Either put stats
in state
or take itemsNotShown
outside of state
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.
But isn't state used to pass mutable variables? I put the ones that change in this.state and the others just in this
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.
I never heard a rule like that, did you see it somewhere 👀
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.
No but it makes more sense to me :)
class SettingsDialog extends Component { | ||
static template = "awesome_dashboard.SettingsDialog"; | ||
static components = { Dialog, CheckBox }; | ||
static props = ["dashboard", "items", "itemsNotShown"]; | ||
|
||
setup() { | ||
this.items = useState(this.props.items); | ||
this.items.forEach((item) => { item.shown = !this.props.itemsNotShown.includes(item.id)}); | ||
} | ||
|
||
toggleItem (ev, item) { | ||
item.shown = ev; | ||
|
||
const newItemsNotShown = Object.values(this.items) | ||
.filter((i) => !i.shown) | ||
.map((i) => i.id) | ||
|
||
browser.localStorage.setItem("itemsNotShown", newItemsNotShown); | ||
|
||
this.props.dashboard.state.itemsNotShown = newItemsNotShown; | ||
} | ||
} |
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.
Deserves its own file imo
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 tutorial solution doesn't share the same opinion
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.
🤠 are we looking at the solution now
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.
Well when the exercise says "code something you have no idea how to do and we give you no docs for with components you don't know the name of in a framework you don't know" I don't feel like trying
|
||
browser.localStorage.setItem("itemsNotShown", newItemsNotShown); | ||
|
||
this.props.dashboard.state.itemsNotShown = newItemsNotShown; |
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.
uuuhh so you're getting the parent as a prop, then changing the state of the parent in the child. Why don't you handle all of this in the parent. You can create the toggleItem (or similar) function in the parent and pass the function to the child as a prop
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.
I was gonna write a witty answer but instead I'll just commit another solution that will comply entirely with what I was gonna write & will probably irritate you even more
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.
I hope you like it
setup() { | ||
this.items = useState(this.props.items); | ||
this.items.forEach((item) => { item.shown = !this.props.itemsNotShown.includes(item.id)}); | ||
this.items.forEach((item) => { item.shown = !this.props.dashboard.state.itemsNotShown.includes(item.id)}); |
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.
I hate everything about this.
Good job 👍
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.
That way I only have to pass 1 prop: the dashboard, and not: itemsNotShown and 15update methods 😄
if (this.pieChart) { | ||
this.pieChart.destroy(); | ||
} |
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.
if (this.pieChart) { | |
this.pieChart.destroy(); | |
} | |
this.pieChart?.destroy(); |
this.buildChart(); | ||
}); | ||
|
||
onWillUnmount(() => { if (this.pieChart) {this.pieChart.destroy()}; }); |
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.
onWillUnmount(() => { if (this.pieChart) {this.pieChart.destroy()}; }); | |
onWillUnmount(() => {this.pieChart?.destroy(); }); |
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.
Hum hum...
No description provided.