commit | author | age
|
bae328
|
1 |
import React, { Component } from "react"; |
JR |
2 |
import Structure from "./Layout"; |
|
3 |
|
|
4 |
import { |
|
5 |
BrowserRouter as Router, |
|
6 |
Switch, |
|
7 |
Route, |
|
8 |
} from "react-router-dom"; |
|
9 |
import SheltersView from "./Views/SheltersView"; |
|
10 |
import NewsView from "./Views/NewsView"; |
|
11 |
import ShelterFakeService from "./Services/ShelterFakeService"; |
|
12 |
import NewsFakeService from "./Services/NewsFakeService"; |
|
13 |
import AnimalFakeService from "./Services/AnimalFakeService"; |
|
14 |
import AnimalsView from "./Views/AnimalsView"; |
|
15 |
import HomeView from "./Views/HomeView"; |
|
16 |
import AdoptionFakeService from "./Services/AdoptionFakeService"; |
|
17 |
import ShelterRESTService from "./Services/ShelterRESTService"; |
|
18 |
import AdoptionRESTService from "./Services/AdoptionRESTService"; |
|
19 |
import AnimalRESTService from "./Services/AnimalRESTService"; |
|
20 |
import { NewsService } from "./Services/NewsService"; |
|
21 |
import { AnimalService } from "./Services/AnimalService"; |
|
22 |
import { AdoptionService } from "./Services/AdoptionService"; |
|
23 |
import { ShelterService } from "./Services/ShelterService"; |
|
24 |
import AnimalDetailsView from "./Views/AnimalDetailsView"; |
|
25 |
import ShelterDetailsView from "./Views/ShelterDetailsView"; |
|
26 |
import AnimalCreateView from "./Views/AnimalCreateView"; |
|
27 |
import Config from "./Config"; |
|
28 |
import NewsRESTService from "./Services/NewsRESTService"; |
|
29 |
import SheltersCreateView from "./Views/SheltersCreateView"; |
9f69d1
|
30 |
import NotificationsView from "./Views/NotificationsView"; |
bae328
|
31 |
|
JR |
32 |
|
|
33 |
// Initialize Backend Services |
|
34 |
let animalService: AnimalService; |
|
35 |
let adoptionService: AdoptionService; |
|
36 |
let shelterService: ShelterService; |
|
37 |
let newsService: NewsService; |
|
38 |
|
|
39 |
if (Config.ADOPTION_SERVICE_URL) { |
|
40 |
adoptionService = new AdoptionRESTService(Config.ADOPTION_SERVICE_URL); |
|
41 |
} else { |
|
42 |
console.log("Warning: No adoption service url provided. Using AdoptionFakeService"); |
|
43 |
adoptionService = new AdoptionFakeService(); |
|
44 |
} |
|
45 |
|
|
46 |
if (Config.ANIMAL_SERVICE_URL) { |
|
47 |
animalService = new AnimalRESTService(Config.ANIMAL_SERVICE_URL); |
|
48 |
} else { |
|
49 |
console.log("Warning: No animal service url provided. Using AnimalFakeService"); |
|
50 |
animalService = new AnimalFakeService(); |
|
51 |
} |
|
52 |
|
|
53 |
if (Config.SHELTER_SERVICE_URL) { |
|
54 |
shelterService = new ShelterRESTService(Config.SHELTER_SERVICE_URL); |
|
55 |
} else { |
|
56 |
console.log("Warning: No shelter service url provided. Using ShelterFakeService"); |
|
57 |
shelterService = new ShelterFakeService(); |
|
58 |
} |
|
59 |
|
|
60 |
if (Config.NEWS_ENABLED && Config.NEWS_SERVICE_URL) { |
|
61 |
newsService = new NewsRESTService(Config.NEWS_SERVICE_URL); |
|
62 |
} else { |
|
63 |
console.log("Warning: No news service url provided. Using NewsFakeService"); |
|
64 |
newsService = new NewsFakeService(); |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
// Declare the root application component |
|
70 |
export default class App extends Component { |
|
71 |
render() { |
|
72 |
return ( |
|
73 |
<Router basename="/frontend"> |
|
74 |
<Switch> |
|
75 |
<Structure> |
|
76 |
<Route path="/" exact > |
|
77 |
<HomeView /> |
|
78 |
</Route> |
|
79 |
<Route path="/shelters" exact> |
|
80 |
<SheltersView shelterService={shelterService} /> |
|
81 |
</Route> |
|
82 |
<Route path="/animals" exact> |
|
83 |
<AnimalsView |
|
84 |
animalService={animalService} |
|
85 |
adoptionService={adoptionService} |
|
86 |
/> |
|
87 |
</Route> |
|
88 |
{Config.NEWS_ENABLED && |
|
89 |
<Route path="/news" exact> |
|
90 |
<NewsView newsService={newsService} /> |
|
91 |
</Route> |
|
92 |
} |
|
93 |
<Route path={"/animals/details/:animalId"} render={(props) => |
|
94 |
<AnimalDetailsView {...props} |
|
95 |
animalService={animalService} |
|
96 |
adoptionService={adoptionService} |
|
97 |
/>} > |
|
98 |
</Route> |
|
99 |
<Route path="/manage/shelters/create" exact> |
|
100 |
<SheltersCreateView shelterService={shelterService} /> |
|
101 |
</Route> |
|
102 |
<Route path="/manage/animals/create" render={(props) => |
|
103 |
<AnimalCreateView {...props} |
9f69d1
|
104 |
shelterService={shelterService} |
bae328
|
105 |
animalService={animalService} |
JR |
106 |
|
9f69d1
|
107 |
/>}/> |
bae328
|
108 |
<Route path={"/shelters/:shelterId"} render={(props) => |
JR |
109 |
<ShelterDetailsView {...props} |
|
110 |
shelterService={shelterService} |
|
111 |
adoptionService={adoptionService} |
9f69d1
|
112 |
/>} /> |
d4efcf
|
113 |
<Route path={"/notifications"} render={() => |
9f69d1
|
114 |
<NotificationsView animalService={animalService}/> |
J |
115 |
}/> |
bae328
|
116 |
</Structure> |
JR |
117 |
</Switch> |
|
118 |
</Router> |
|
119 |
); |
|
120 |
} |
|
121 |
} |