Skip to content

Commit 9e42472

Browse files
committed
integrated old wiki into docs
1 parent 31a7863 commit 9e42472

31 files changed

+841
-909
lines changed

TODO.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ nav_order: 5
88
- [ ] Add a "DevOps" section under WST processes for deployments and related stuff
99
- [ ] figure out how to add/link to images, and document that
1010
- [x] add WARNING, INFO and OPTION callouts
11-
- [ ] Work through all existing documentation and add it somewhere
11+
- [ ] Work through wiki
1212
- [ ] work through all pages, and either finalize or convert to drafts
1313
- [ ] add links etc to index.md
1414
- [ ] finish off and publish draft pages
15+
- [ ] Add gh wiki files to a GDrive, and change the wiki to point here instead
16+
- [ ] Change the main repo readme
1517

1618
## IDEAS / THOUGHTS
1719

1820
- add development tips and tricks
1921
- byebug
2022
- rails console
23+
- Add a "Repo Context" page with:
24+
- development vision
25+
- why rails?

wiki_imports/Building-Regulations-locally.md renamed to guides/Building-Regulations-locally.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Building Regulations Locally
33
layout: default
4-
parent: Wiki Imports
4+
parent: Guides
55
---
66

77
This page aims to guide you through the process of building the WCA Regulations and Guidelines, which is something that you may want to do when you first clone the website repository.

wiki_imports/Translating-the-website.md renamed to guides/Translating-the-website.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
title: Translating the Website
33
layout: default
4-
parent: Wiki Imports
4+
parent: Guides
55
---
66

7-
87
# TODO: add a note about how the website changes constantly, and translating the website is not a one time task, it's an ongoing commitment.
98

109
## Table of Contents

guides/creating-react-components.md

+198
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,201 @@ title: Creating React Components
33
parent: Guides
44
layout: default
55
---
6+
7+
This documentation is very new, so you should feel free to suggest changes.
8+
9+
## Preamble
10+
11+
The website is historically purely Rails, with a lot of jquery to handle user interaction.
12+
With the integration of Webpack to Rails, we started migrated our javascript and css codebase to Webpack,
13+
but it's still very much in progress.
14+
This means we serve our assets from two sources: sprockets (assets located in '/assets'), and webpack (assets located in '/packs').
15+
16+
New javascript developments should occur with webpack.
17+
18+
Packs can import javascript, stylesheets, or even images (Webpack will figure
19+
out the dependencies and what to include when).
20+
21+
## Creating a new component
22+
23+
Let's assume you want to write a new component to display the website posts,
24+
and you want to name it `PostsWidget`.
25+
26+
All of our components live under the aptly named folder `app/webpacker/components`.
27+
You are essentially free to write your code there as you please, but please consider the following as rule of thumb: If it's a simple component that resides within one file, just create it as `PostsWidget.js` and have fun. If it's a complex setup with multiple interacting files, create a folder `components/PostsWidget` and create an `index.js` and other `js` files in there.
28+
29+
The `index.js[x]` file should contain the main component you want to export,
30+
and declare itself in a manner that would work for normal pure-JS projects (i.e. `export`ing the component you want to use in Rails):
31+
```javascript
32+
import React from 'react';
33+
import { registerComponent } from '../wca/react-utils';
34+
function PostsWidget({
35+
msg,
36+
}) {
37+
return (
38+
<div>My message: {msg}</div>
39+
);
40+
}
41+
42+
export default PostsWidget;
43+
```
44+
45+
## Integrating the component to the website
46+
47+
Now that we have a very basic component exported, we most likely want to include
48+
it in some page of the website.
49+
Once you've found a view where to include your component, you will have to:
50+
- tell the website you'll need the component
51+
- render the component somewhere
52+
53+
There is an application helper for that:
54+
- `react_component` will let you emit a registered component.
55+
56+
In our case, assuming we want to use the widget on the posts index page,
57+
the `app/views/posts/index.html.erb` file would look like this:
58+
```erb
59+
<div class="container">
60+
<%= react_component("PostsWidget", {
61+
msg: "Hello world!",
62+
}, {
63+
id: "posts_widget",
64+
}) %>
65+
</div>
66+
```
67+
68+
The first mandatory argument to `render_react_component` is the name of the component,
69+
the same name used in the JS `export` (actually, there is a JavaScript `require` context running under the hood, so it's literally doing JS `require` with whatever name you pass it).
70+
The second argument is a keyword dict directly containing the properties you want to pass to the component.
71+
The third, optional argument is a keyword dict with other HTML options. For example, `id` may be used to set a specific
72+
id on the `div` holding the component.
73+
74+
In our example we use it to set the `msg` property.
75+
76+
77+
## Writing UI
78+
79+
Writing a message may be fun, but it doesn't go very far.
80+
We recently switched to [Fomantic UI (FUI)](https://fomantic-ui.com/) (which you may also know as Semantic UI)
81+
as our main framework, it has React bindings through the `semantic-ui-react` package.
82+
Documentation for all usable components is [here](https://react.semantic-ui.com/).
83+
84+
Basically if you want to include some components from FUI you would do something like that:
85+
```
86+
import {
87+
Button, Card, Icon, List, Pagination,
88+
} from 'semantic-ui-react';
89+
```
90+
91+
We don't import the whole FUI CSS by default.
92+
If you're using some components that were not already used by the website, make sure to edit our [global_style.js](https://github.com/thewca/worldcubeassociation.org/blob/0d0137379b5ce1a62e05f0a4dc390fef7aa8292e/WcaOnRails/app/webpacker/packs/global_styles.js) to include the CSS-es relevant to these components.
93+
If what you're using is extremely specific to the widget you're writing, you may consider only including the style in your widget's javascript file.
94+
95+
If you want to write custom (S)CSS that would be active only when that component is used, you can create a custom (s)css file in the same folder of your component and import it. Webpack will automatically include the style when loading the pack containing your component (again, see the real `posts_widget` example :)).
96+
97+
I won't go much more in details as the rest is just putting together React
98+
components, which is not the scope of that documentation.
99+
100+
101+
## Loading data from the website
102+
103+
Chances are that your new component will want to load some data from the website.
104+
In the case of our `PostsWidget`, we would like to get the list of posts, to display them.
105+
While we're using React to create the *View* for them, the *Model* and *Controller*
106+
part are handled by Rails.
107+
108+
Therefore we'll need:
109+
- to make rails give us the list of posts
110+
- somehow load them asynchronously in our component.
111+
112+
### Making the server send json data
113+
114+
The first part is achieved by making the `index` method of the `posts_controller`
115+
reply to us with a json containing the posts data.
116+
Here is roughly what it could look like:
117+
```ruby
118+
def index
119+
respond_to do |format|
120+
format.json do
121+
render json: {
122+
posts: Post.visible.order(created_at: :desc),
123+
}
124+
end
125+
format.html do
126+
render :index
127+
end
128+
end
129+
end
130+
```
131+
132+
It basically tells rails to:
133+
- if the client request json, render the visible posts as json, sorted with the most recent first
134+
- if the client request html (as it would by visiting the index page), we just
135+
render the html page without loading any data (because it will render the component
136+
which itself will request the data as json).
137+
138+
You can see the actual implementation of that endpoint (with extra options as which
139+
page to load, how many posts to load, ...) in `app/controller/posts_controller.rb`.
140+
141+
### Using these data in our component
142+
143+
Now that we have an endpoint to fetch data from, we need to use it from our component.
144+
We have a hook that can be used to fetch data from a particular
145+
endpoint.
146+
The `useLoadedData` hook is available in the `requests/loadable` module, and takes one parameter: an url to fetch from.
147+
148+
To make it clear, let's take this example:
149+
```javascript
150+
const PostsWidget = ({
151+
initialData,
152+
}) => {
153+
const { loadedData, loading, error } = useLoadedData(postsUrl());
154+
return (
155+
<>
156+
{error && (
157+
<Errored componentName="PostsWidget" />
158+
)}
159+
{loading && (
160+
<Loading />
161+
)}
162+
{!loading && loadedData && (
163+
<PostsList posts={loadedData.posts} />
164+
)}
165+
</>
166+
);
167+
};
168+
```
169+
170+
It would be then used like this: `<PostsWidget initialData={{}} />`.
171+
172+
In the code above, a lot of thing happen under the hood:
173+
- `postsUrl()` returns the route to the posts url (the route can be parametrize with additional data - such as a page number, a tag, or anything else).
174+
- `loadedData` will be filled by `useLoadedData`, and will be `null`
175+
until the data are loaded. When they are, it will contain the server response.
176+
In this case, it will contain a `posts` field with an array of posts.
177+
- `error` will also be provided by `useLoadedData`, and will be set only
178+
if something wrong occurred when fetching the data.
179+
- `PostsList` is an hypothetical component rendering a list of posts.
180+
181+
As you can see in the example, I used the generic `Loading` and `Errored` component
182+
to handle the cases where the data are loading or could not be fetched.
183+
184+
Note that you may choose to provide the component with some initial data.
185+
For instance: `<PostsWidget id={} initialData={{posts: [/* some data */]}}/>`
186+
187+
Again you can see a detailed usage in the actual code of `PostsWidget` :)
188+
189+
190+
## Writing data to the website
191+
192+
TODO: a similar `savable` hook is under development.
193+
194+
## I18n
195+
196+
Use the `I18n.t` function in place of `t` in Ruby.
197+
This needs to be imported from `i18n`, which is often `import I18n from '../../lib/i18n'`, although you may need to play with the path.
198+
199+
If the translation contains HTML, you can use the `I18nHTMLTranslate` component, which sanatizes first.
200+
201+
### Missing Translation
202+
If you see `[missing "*" translation]`, you may need to add the specific yml path you want to use to `WcaOnRails/config/i18n.yml`.
203+

index.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,60 @@ nav_order: 1
66

77
## Quick Links
88

9-
- [Quickstart](/contributing/quickstart)
9+
- [Quickstart]
1010

1111
## Contributing to the Docs
1212

13-
Our documentation is [open-source](https://github.com/thewca/web-dev-docs)! You can submit corrections or add documentation - but open an issue to discuss larger contributions first.
13+
Our documentation is [open-source]! You can submit corrections or add documentation - but open an issue to discuss larger contributions first.
1414

1515
## About
1616

17-
The [World Cube Association](https://www.worldcubeassociation.org/) ("WCA") governs twisty puzzle (think: Rubik's Cube) competitions around the world. There are a number of software resources which enable it to do this.
17+
The [World Cube Association] ("WCA") governs twisty puzzle (think: Rubik's Cube) competitions around the world. There are a number of software resources which enable it to do this.
1818

19-
The code for these websites is open-source and any contributors are welcome to submit PR's. The [WCA Software Team](https://www.worldcubeassociation.org/teams-committees#WST) ("WST") is responsible for maintaining and driving development on WCA's software. See below for a list of software being developed.
19+
The code for these websites is open-source and any contributors are welcome to submit PR's. The [WCA Software Team] ("WST") is responsible for maintaining and driving development on WCA's software. See below for a list of software being developed.
2020

2121
## Contacting WST
2222

2323
Remember, our repos are open-source - you don't have to be a member of WST to contribute!
2424

2525
* **Open an issue**: Create a link in the relevant repo - "WCA Software Resources" below contains links to all repos.
26-
* **General enquiry**: Submit an email to WST via the WCA's [contact form](https://www.worldcubeassociation.org/contact/website)
26+
* **General enquiry**: Submit an email to WST via the WCA's [contact form]
2727
* **Joining WST**: Currently (2023-09-10) WST is not accepting new members. We aim to onboard more volunteers by early 2024.
2828

2929
## WCA Software Resources
3030

3131
### Websites
3232

33-
#### [WorldCubeAssociation](https://www.worldcubeassociation.org/) ([repo]())
33+
#### [WorldCubeAssociation](https://www.worldcubeassociation.org/) ([repo](https://github.com/thewca/worldcubeassociation.org))
3434
- The main website for the WCA - commonly referred to as the "Monolith".
3535
- Primarily uses Ruby on Rails, transitioning to a React-based frontend.
3636

37-
#### WCA Live (repo):
37+
#### [WCA Live](live.worldcubeassociation.org/) ([repo](https://github.com/thewca/wca-live/)):
3838
- A website for capturing and displaying live results at WCA-sanctioned competitions.
3939
- Primarily uses Elixir and React, transitioning to a Rails-based backend with Elixir only used for serving results data to clients.
4040

41-
#### WCA Statistics (repo):
41+
#### [WCA Statistics](https://statistics.worldcubeassociation.org/) ([repo](https://github.com/thewca/statistics)):
4242
- Provides various interesting statistics outside the scope of the main website. Also provides an interface for SQL queries to be made against a "developer export" of the database.
4343
- Python backend, Javascript frontend.
4444

45-
#### Scrambles matcher
46-
- TODO
45+
#### [Scrambles matcher](https://scrambles-matcher.worldcubeassociation.org/) ([repo](https://github.com/thewca/scrambles-matcher))
46+
- Used by delegates to match scrambles to rounds and groups
47+
- Under a feature freeze (will be migrated to an integrated scramble management tool)
48+
- Written in Javascript
4749

4850

4951
### Other Software
5052

51-
#### TNoodle
52-
- TODO
53-
54-
55-
# TODO:
56-
- Add a "Repo Context" page with:
57-
- development vision
58-
- why rails?
59-
60-
53+
#### TNoodle ([repo](https://github.com/thewca/tnoodle))
54+
- Used by delegates to generate scrambles for competitions
55+
- Under a feature freeze (will be migrated to an integrated scramble management tool)
56+
- Written in Java
6157

6258
---
6359

64-
[WCA](https://www.worldcubeassociation.org/abouthttps://www.worldcubeassociation.org/about)
65-
[WST](https://www.worldcubeassociation.org/teams-committees#WST)
60+
[World Cube Association]: https://www.worldcubeassociation.org/about
61+
[WCA Software Team]: https://www.worldcubeassociation.org/about
62+
[WST]: https://www.worldcubeassociation.org/teams-committees#WST
63+
[open-source]: https://github.com/thewca/web-dev-docs
64+
[Quickstart]: /contributing/quickstart
65+
[contact form]: https://www.worldcubeassociation.org/contact/website

0 commit comments

Comments
 (0)