├── .prettierrc.js
├── babel.config.js
├── public
├── favicon.ico
└── index.html
├── src
├── assets
│ └── logo.png
├── views
│ ├── About.vue
│ ├── ErrorDisplay.vue
│ ├── EventDetails.vue
│ ├── EventList.vue
│ └── EventCreate.vue
├── main.js
├── services
│ └── EventService.js
├── components
│ └── EventCard.vue
├── router
│ └── index.js
├── store
│ └── index.js
└── App.vue
├── .gitignore
├── README.md
├── db.json
└── package.json
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | singleQuote: true,
3 | semi: false
4 | }
5 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ["@vue/cli-plugin-babel/preset"]
3 | };
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Code-Pop/Vuex_Fundamentals/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Code-Pop/Vuex_Fundamentals/HEAD/src/assets/logo.png
--------------------------------------------------------------------------------
/src/views/About.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
A site for events to better the world.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/views/ErrorDisplay.vue:
--------------------------------------------------------------------------------
1 |
2 | Oops! There was an error:
3 | {{ error }}
4 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import { createApp } from 'vue'
2 | import App from './App.vue'
3 | import router from './router'
4 | import store from './store'
5 |
6 | createApp(App)
7 | .use(store)
8 | .use(router)
9 | .mount('#app')
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 |
6 | # local env files
7 | .env.local
8 | .env.*.local
9 |
10 | # Log files
11 | npm-debug.log*
12 | yarn-debug.log*
13 | yarn-error.log*
14 | pnpm-debug.log*
15 |
16 | # Editor directories and files
17 | .idea
18 | .vscode
19 | *.suo
20 | *.ntvs*
21 | *.njsproj
22 | *.sln
23 | *.sw?
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Intro to State Management
2 |
3 | ## Project setup
4 | ```
5 | npm install
6 | ```
7 |
8 | ### Compiles and hot-reloads for development
9 | ```
10 | npm run serve
11 | ```
12 |
13 | ### Compiles and minifies for production
14 | ```
15 | npm run build
16 | ```
17 |
18 | ### Lints and fixes files
19 | ```
20 | npm run lint
21 | ```
22 |
23 | ### Customize configuration
24 | See [Configuration Reference](https://cli.vuejs.org/config/).
25 |
--------------------------------------------------------------------------------
/src/services/EventService.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 |
3 | const apiClient = axios.create({
4 | baseURL: 'http://localhost:3000',
5 | withCredentials: false,
6 | headers: {
7 | Accept: 'application/json',
8 | 'Content-Type': 'application/json'
9 | }
10 | })
11 |
12 | export default {
13 | getEvents() {
14 | return apiClient.get('/events')
15 | },
16 | getEvent(id) {
17 | return apiClient.get('/events/' + id)
18 | },
19 | postEvent(event) {
20 | return apiClient.post('/events', event)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/views/EventDetails.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{ event.title }}
4 |
{{ event.time }} on {{ event.date }} @ {{ event.location }}
5 |
{{ event.description }}
6 |
7 |
8 |
9 |
28 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | <%= htmlWebpackPlugin.options.title %>
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/views/EventList.vue:
--------------------------------------------------------------------------------
1 |
2 | Events for Good
3 |
4 |
5 |
6 |
7 |
8 |
32 |
33 |
40 |
--------------------------------------------------------------------------------
/src/components/EventCard.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | @{{ event.time }} on {{ event.date }}
8 |
{{ event.title }}
9 |
10 |
11 |
12 |
13 |
23 |
24 |
43 |
--------------------------------------------------------------------------------
/db.json:
--------------------------------------------------------------------------------
1 | {
2 | "events": [
3 | {
4 | "id": 123,
5 | "category": "animal welfare",
6 | "title": "Cat Adoption Day",
7 | "description": "Find your new feline friend at this event.",
8 | "location": "Meow Town",
9 | "date": "January 28, 2022",
10 | "time": "12:00",
11 | "organizer": "Kat Laydee"
12 | },
13 | {
14 | "id": 456,
15 | "category": "food",
16 | "title": "Community Gardening",
17 | "description": "Join us as we tend to the community edible plants.",
18 | "location": "Flora City",
19 | "date": "March 14, 2022",
20 | "time": "10:00",
21 | "organizer": "Fern Pollin"
22 | },
23 | {
24 | "id": 789,
25 | "category": "sustainability",
26 | "title": "Beach Cleanup",
27 | "description": "Help pick up trash along the shore.",
28 | "location": "Playa Del Carmen",
29 | "date": "July 22, 2022",
30 | "time": "11:00",
31 | "organizer": "Carey Wales"
32 | }
33 | ]
34 | }
--------------------------------------------------------------------------------
/src/router/index.js:
--------------------------------------------------------------------------------
1 | import { createRouter, createWebHistory } from 'vue-router'
2 | import EventList from '../views/EventList.vue'
3 | import EventDetails from '../views/EventDetails.vue'
4 | import EventCreate from '../views/EventCreate.vue'
5 | import ErrorDisplay from '../views/ErrorDisplay.vue'
6 | import About from '../views/About.vue'
7 |
8 | const routes = [
9 | {
10 | path: '/',
11 | name: 'EventList',
12 | component: EventList
13 | },
14 | {
15 | path: '/event/:id',
16 | name: 'EventDetails',
17 | props: true,
18 | component: EventDetails
19 | },
20 | {
21 | path: '/event/create',
22 | name: 'EventCreate',
23 | component: EventCreate
24 | },
25 | {
26 | path: '/error/:error',
27 | name: 'ErrorDisplay',
28 | props: true,
29 | component: ErrorDisplay
30 | },
31 | {
32 | path: '/about',
33 | name: 'About',
34 | component: About
35 | }
36 | ]
37 |
38 | const router = createRouter({
39 | history: createWebHistory(process.env.BASE_URL),
40 | routes
41 | })
42 |
43 | export default router
44 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "real-world-vue",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build",
8 | "lint": "vue-cli-service lint"
9 | },
10 | "dependencies": {
11 | "core-js": "^3.6.5",
12 | "uuid": "^8.3.2",
13 | "vue": "^3.5.25",
14 | "vue-router": "^4.6.3",
15 | "vuex": "^4.1.0"
16 | },
17 | "devDependencies": {
18 | "@vue/cli-plugin-babel": "~5.0.9",
19 | "@vue/cli-plugin-eslint": "~5.0.9",
20 | "@vue/cli-plugin-router": "~5.0.9",
21 | "@vue/cli-plugin-vuex": "~5.0.9",
22 | "@vue/cli-service": "~5.0.9",
23 | "@vue/compiler-sfc": "^3.0.0-0",
24 | "@vue/eslint-config-prettier": "^6.0.0",
25 | "axios": "^0.21.1",
26 | "babel-eslint": "^10.1.0",
27 | "eslint": "^7.5.0",
28 | "eslint-plugin-prettier": "^3.1.3",
29 | "eslint-plugin-vue": "^7.0.0-0",
30 | "json-server": "^0.17.4",
31 | "prettier": "^1.19.1",
32 | "whatwg-fetch": "^3.6.20"
33 | },
34 | "eslintConfig": {
35 | "root": true,
36 | "env": {
37 | "node": true
38 | },
39 | "extends": [
40 | "plugin:vue/vue3-essential",
41 | "eslint:recommended",
42 | "@vue/prettier"
43 | ],
44 | "parserOptions": {
45 | "parser": "babel-eslint"
46 | },
47 | "rules": {}
48 | },
49 | "browserslist": [
50 | "> 1%",
51 | "last 2 versions",
52 | "not dead"
53 | ]
54 | }
55 |
--------------------------------------------------------------------------------
/src/store/index.js:
--------------------------------------------------------------------------------
1 | import EventService from '@/services/EventService'
2 | import { createStore } from 'vuex'
3 |
4 | export default createStore({
5 | state: {
6 | user: 'Adam Jahr',
7 | events: [],
8 | event: null
9 | },
10 | mutations: {
11 | ADD_EVENT(state, event) {
12 | state.events.push(event)
13 | },
14 | SET_EVENTS(state, events) {
15 | state.events = events
16 | },
17 | SET_EVENT(state, event) {
18 | state.event = event
19 | }
20 | },
21 | actions: {
22 | createEvent({ commit }, event) {
23 | return EventService.postEvent(event)
24 | .then(() => {
25 | commit('ADD_EVENT', event)
26 | commit('SET_EVENT', event)
27 | })
28 | .catch(error => {
29 | throw error
30 | })
31 | },
32 | fetchEvents({ commit }) {
33 | return EventService.getEvents()
34 | .then(response => {
35 | commit('SET_EVENTS', response.data)
36 | })
37 | .catch(error => {
38 | throw error
39 | })
40 | },
41 | fetchEvent({ commit, state }, id) {
42 | const event = state.events.find(event => event.id === id)
43 | if (event) {
44 | commit('SET_EVENT', event)
45 | } else {
46 | return EventService.getEvent(id)
47 | .then(response => {
48 | commit('SET_EVENT', response.data)
49 | })
50 | .catch(error => {
51 | throw error
52 | })
53 | }
54 | }
55 | }
56 | })
57 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Events |
5 | About
6 | |
7 | Create Event
8 |
9 |
10 |
11 |
12 |
13 |
101 |
--------------------------------------------------------------------------------
/src/views/EventCreate.vue:
--------------------------------------------------------------------------------
1 |
2 | Create an event
3 |
4 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------