Commit 1768772
authored
feat(word-editor): implement
This Pull Request implements the edit functionality for word on the word
editor. The edit operation takes the current change made to a word on
submit, perform a submit operation through the `handleSubmitWord`
handler and routes to the `/editor` page after successful edit
operation.
### Changes Made
- Added the dynamic word edit route at
`src/pages/editor/edit/[word].astro`; this route dynamically take the
word found on the route `word` param and operates with it
- Implemented the `doEditWord` action; which retrieves the current edit
word's `word` param and fetches an existing word (record) in dictionary
for the word using the `getExistingWord` function from the `word-editor`
script, and returns an object of the word
```js
/**
* Edit Word action - meant to be executed on `editor/edit/[word]` route
* @param {import("astro").AstroGlobal} astroGlobal
*/
export default async function doEditWord(astroGlobal) {
const { cookies, params: { word } } = astroGlobal;
const accessToken = cookies.get("jargons.dev:token", { decode: value =>
decrypt(value) });
const userOctokit = app.getUserOctokit({ token: accessToken.value });
const response = await getExistingWord(userOctokit,
PROJECT_REPO_DETAILS, word);
return response;
}
```
- Added a new props `action` to the `WordEditor` component,...
- `action` - this prop accepts either `new` or `edit` as value
- `metadata` - props to hold other words data from github api response
- `octokitAuths` props that hold authToken for current authenticated
user and jargons.dev app
- Added `gray-matter` to deps, used for parsing the content of the
`word.content_decoded` property allowing separation of the `title` and
`content` from the property which will then be passed as existing value
to the `WordEditor` component (from the `word-editor` island)
- Implemented the `resolveEditorActionFromPathname` utils function which
is used to compute the current word editor action from the current url
pathname which is `/editor/edit/[word]` for word edit and will be
`/editor/new` for new word addition
- Replace the `Editor` component (on `word-editor` island) wrapper `div`
with a `form` element
- Added a new `SubmitButton` component within the `word-editor`;
exported to be integrated as a separate island that is linked to the
word editor `form`; this component integrates a button that acts as the
submit button for the word editor `form`; on click this button, the
editor form submits
- Added a new boolean `$isWordSubmitLoading` state to `dictionary` store
for tracking when a word submission is in action
- Integrated the `SubmitButton` into the `Navbar` component with a
`client:load` directive in order to enable interactivity for submission
loading state
- Implemented the `handleSubmitWord` handler function; this function
currently handle the word `edit` operation (should handle `new` word
addition next); it takes the required `octokitAuth` tokens(this is the
user's authToken and the jargons.dev app authToken - it uses this to
create an octokit instance for the user and app respectively for
consumption in all other function execution that requires them as
param), `action` and `word` data; and handles all the process of
contribution by doing the following....
- Creates a fork on the current users' account
- Creates a new branch to commit change to
- Commits the changes to the new branch
- Create a PR to merge this branch to the main project repo
- Implemented the `doOctokitAuth` action which compute and avails the
authToken for currently authenticated user and the jargons.dev app;
which are consumed by the `handleSubmitWord` handler
- Extracted the `devJargonsOctokit` integration in the `submit-word`
script; replacing it with a param ensuring that the script's
`submitWord` function accepts the `devJargonsOctokit` as param; this
improves on the implementation at
https://github.com/babblebey/jargons.dev/pull/25
- Added a new `option` object param to the `updateExistingWord` and
`writeNewWord` with `env` property that accepts either `node` or
`browser`; this option is used to determine which encoding function/api
is used to encode the `content` for file write operation, i.e. `Buffer`
in node and `btoa` in browser or client-side
### Screencast
https://github.com/babblebey/jargons.dev/assets/25631971/4352565a-a38d-4e79-b93b-001263ff2456edit word action (#32)1 parent d775b92 commit 1768772
18 files changed
Lines changed: 417 additions & 25 deletions
File tree
- src
- components/islands
- lib
- actions
- handlers
- octokit
- stores
- templates
- utils
- pages
- api/github/oauth
- editor/edit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | | - | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | | - | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
11 | 19 | | |
12 | 20 | | |
13 | 21 | | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
18 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
19 | 46 | | |
20 | 47 | | |
21 | 48 | | |
22 | 49 | | |
23 | 50 | | |
24 | 51 | | |
25 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
26 | 63 | | |
27 | | - | |
| 64 | + | |
28 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
29 | 71 | | |
30 | 72 | | |
31 | 73 | | |
32 | | - | |
| 74 | + | |
33 | 75 | | |
34 | 76 | | |
35 | 77 | | |
| 78 | + | |
36 | 79 | | |
37 | 80 | | |
38 | 81 | | |
39 | 82 | | |
40 | 83 | | |
41 | 84 | | |
42 | 85 | | |
43 | | - | |
| 86 | + | |
44 | 87 | | |
45 | 88 | | |
46 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
0 commit comments