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

Basic vue UI #133

Merged
merged 19 commits into from
Aug 16, 2021
Merged

Conversation

Henny022
Copy link

This is based on the new backend by @knusperkrone

@dirkriehle dirkriehle marked this pull request as ready for review March 27, 2021 11:32
email: string;
}

class ApiThing {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create singletons in js by

const apiThing = new ApiThing();
export apiThing;

This lets you just import {apiThing} from './.../ApiThing' and you don't have to pass it through all components!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApiThing is not a good name, and does too many things at once. I'd split up in AuthApi, PhotoApi and UserApi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on the name, I already renamed it to WahlzeitApi, just didn't commit that yet.
I made it a single class, since I'd say it only does a single thing, that being handling the interaction with the backend API (one class for one API).
Splitting that would require some base class that handles the basic communication that would be shared by all the individual API's.

I think that any code using a singleton is bad code for multiple reasons, but if it is the preferred solution in your project I can change that.
If I do split the the API class, that would make 3+ singletons.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I agree that the singleton approach is not optimal as well. In general, dependency injection is the way to go in my opinion. Using the props is a way to inject dependencies... However, I'd still go with the instance export way because it makes the component interface smaller. But maybe I'm wrong - did you look into best practices for vue regarding this?

Single-Responsibility is always a matter of perspective... Since the API is still slim, lets leave it as you designed it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vue has provide/inject for dependency injections, but that has some limitations and since I use the api in almost every component anyways I chose props. The documentation also isn't very clear on how to use it with Vue 3 and TS class components, and due to time constraints I couldn't do a lot of testing.
There are some plugins that would help here, but I didn't want to add those as additional dependencies.
I might just change it to a singleton for reading simplicity.

For the Single-Responsibility I just think that adding multiple classes with only 2-3 methods each would be overkill.


mounted() {
this.api
?.getPhoto(this.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls use the aync/await syntax for better code readablity: typescriptlang.org/docs/handbook/release-notes/typescript-1-7.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for other views

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what you mean.
So replace the use of promises with await?
The link you posted just leads me to typescript.org

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those promises look like spaghetti code, so please use the async/await syntax instead.

renamed class
using singleton to reduce used props
using await instead of promises
Added signup modal
Added search functionality (currently broken)
cleaned up the codebase
@georg-schwarz
Copy link
Collaborator

Hey Hendik, I just checked out your PR and saw a few issues in my editor:

(1) Please rebase your PR on the wahlzeit-40-new-ui branch
(2) Some template roots have multiple elements (only one allowed).
(3) Your alias-based imports (@) are shown as error. Is there something required to be configured locally?
(4) The Vetur plugin shows another error: Property '$router' does not exist on type 'App' - probably something is not configured in the shim?
(5) Please add the UI to the Docker setup. You can find a dockerfile for vue here: https://github.com/jvalue/open-data-service/blob/main/ui/Dockerfile

@georg-schwarz georg-schwarz merged commit 6478bac into dirkriehle:wahlzeit-40-new-ui Aug 16, 2021
This was referenced Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants