Skip to content

Commit

Permalink
Remove some deprecated code and resolved a few content issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MBJean committed Jun 15, 2021
1 parent 1f811c7 commit b853746
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 33 deletions.
22 changes: 0 additions & 22 deletions backend/app/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
"""
from textwrap import dedent

from django.shortcuts import render


def render_react_view(request, component_name=None, **url_props):
"""
A view function to render views that are entirely managed
in the frontend by a single React component. This lets us use
Django url routing with React components.
:param request: Django request object to pass through
:param component_name: name of the React component to render into the 'root' div
of backend/templates/base.html
:param url_props: props to pass into the React component, consumed from Django's url parser
:return:
"""
template = 'base.html'
context = {
'component_name': component_name,
'props': url_props,
}
return render(request, template, context)


def print_header(header_str):
"""
Expand Down
4 changes: 2 additions & 2 deletions backend/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def example_id(request, example_id):
'page_metadata': {
'title': 'Example ID page'
},
'app_data': {
'component_props': {
'id': example_id
},
'app_component': 'ExampleId'
'component_name': 'ExampleId'
}

return render(request, 'index.html', context)
7 changes: 4 additions & 3 deletions backend/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{page_metadata['title']}</title>
<title>{{page_metadata.title}}</title>
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
{% render_bundle 'index' 'css' %}
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="app_root">
<p>Loading...</p>
</div>

{{app_data|json_script:"app_data"}}
{{app_component|json_script:"app_component"}}
{{component_props|json_script:"component_props"}}
{{component_name|json_script:"component_name"}}
{% render_bundle 'index' 'js' %}
</body>
</html>
12 changes: 6 additions & 6 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import Base from "./components/global/Base";
import ErrorNotFound from "./components/ErrorNotFound";
import ExampleId from "./components/ExampleId";

const APP_DATA_RAW = document.getElementById("app_data").text;
const APP_COMPONENT_RAW = document.getElementById("app_component").text;
const APP_DATA = JSON.parse(APP_DATA_RAW);
const APP_COMPONENT = JSON.parse(APP_COMPONENT_RAW);
const COMPONENT_PROPS_RAW = document.getElementById("component_props").text;
const COMPONENT_NAME_RAW = document.getElementById("component_name").text;
const COMPONENT_PROPS = JSON.parse(COMPONENT_PROPS_RAW);
const COMPONENT_NAME = JSON.parse(COMPONENT_NAME_RAW);

const COMPONENTS = {
ErrorNotFound,
ExampleId
};

const PreselectedComponent = COMPONENTS[APP_COMPONENT || "ErrorNotFound"];
const PreselectedComponent = COMPONENTS[COMPONENT_NAME || "ErrorNotFound"];

ReactDOM.render(
<Base>
<PreselectedComponent {...APP_DATA}/>
<PreselectedComponent {...COMPONENT_PROPS} />
</Base>,
document.getElementById("app_root")
);

0 comments on commit b853746

Please sign in to comment.