Skip to content

Commit

Permalink
Create ReactController
Browse files Browse the repository at this point in the history
  • Loading branch information
ycanardeau committed Jul 3, 2021
1 parent a92c890 commit d1e4a21
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 1 deletion.
12 changes: 12 additions & 0 deletions VocaDbWeb/Controllers/ReactController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;

namespace VocaDb.Web.Controllers
{
public class ReactController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
9 changes: 9 additions & 0 deletions VocaDbWeb/Scripts/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import './i18n';

const App = (): React.ReactElement => {
return <></>;
};

export default App;
21 changes: 21 additions & 0 deletions VocaDbWeb/Scripts/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';

i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
load: 'languageOnly',
fallbackLng: 'en',

interpolation: {
escapeValue: false,
},

react: {
useSuspense: false,
},
});
13 changes: 13 additions & 0 deletions VocaDbWeb/Scripts/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './App';

const app = document.getElementById('app');

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
app,
);
2 changes: 2 additions & 0 deletions VocaDbWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ void HandleHttpError(int code, string? description = null, string? msg = null)
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapFallbackToController(action: "Index", controller: "React");
});
}
}
Expand Down
43 changes: 43 additions & 0 deletions VocaDbWeb/Views/React/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@using System.Globalization
@using VocaDb.Model.DataContracts.Users
@using VocaDb.Model.Domain.Globalization
@using VocaDb.Model.Helpers
@using VocaDb.Model.Utils
@using VocaDb.Web.Models.Shared
@inherits VocaDbPage
@addTagHelper *, VocaDb.ReMikus

@{
Layout = null;

var stylesheet = Login.IsLoggedIn && !string.IsNullOrEmpty(Login.User.Stylesheet) ? Login.User.Stylesheet : Config.SiteSettings.DefaultStylesheet;
}

<!DOCTYPE html>
<html lang="@InterfaceLanguage.GetAvailableLanguageCode(CultureInfo.CurrentUICulture)">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vocaloid Database</title>

<link rel="shortcut icon" href="@(Config.Assets.FavIconUrl.EmptyToNull() ?? Url.Content("~/Content/favicon.ico"))" type="image/x-icon" />
<remikus path="/Content/css.css" />
@if (!string.IsNullOrEmpty(stylesheet))
{
<link href="@Url.Content("~/Content/Styles/" + stylesheet)" rel="stylesheet" type="text/css" />
}
<link href="@Url.Content("~/Content/Styles/Icons.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/redmond/jquery-ui-1.10.1.custom.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Scripts/qTip/jquery.qtip.css")" rel="stylesheet" type="text/css" />
<link rel="search" type="application/opensearchdescription+xml" title="@BrandableStrings.SiteName" href="@Config.SiteSettings.OpenSearchPath" />

<partial name="Partials/_GoogleAnalytics" />
</head>
<body class="vdb">
<div id="app"></div>
<script>window.vdb = @ToJS(new { Values = new GlobalValues(this) })</script>
<remikus path="/bundles/manifest.js" />
<remikus path="/bundles/vendor.js" />
<remikus path="/bundles/index.js" />
</body>
</html>
1 change: 1 addition & 0 deletions VocaDbWeb/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"forceConsistentCasingInFileNames": true,
"baseUrl": "./",
"paths": {
"@Components/*": ["Scripts/Components/*"],
"@DataContracts/*": ["Scripts/DataContracts/*"],
"@Helpers/*": ["Scripts/Helpers/*"],
"@KnockoutExtensions/*": ["Scripts/KnockoutExtensions/*"],
Expand Down
6 changes: 5 additions & 1 deletion VocaDbWeb/webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mix
processCssUrls: false,
})
.alias({
'@Components': path.join(__dirname, 'Scripts/Components'),
'@DataContracts': path.join(__dirname, 'Scripts/DataContracts'),
'@Helpers': path.join(__dirname, 'Scripts/Helpers'),
'@KnockoutExtensions': path.join(__dirname, 'Scripts/KnockoutExtensions'),
Expand Down Expand Up @@ -78,7 +79,10 @@ mix
.styles(
['wwwroot/Scripts/jqwidgets27/styles/jqx.base.css'],
'wwwroot/Scripts/jqwidgets27/styles/css.css',
);
)

.ts('Scripts/index.tsx', 'wwwroot/bundles')
.react();

if (mix.inProduction()) {
mix.version();
Expand Down

0 comments on commit d1e4a21

Please sign in to comment.