Skip to content

Commit 3298a9a

Browse files
authored
chore: nits (#56)
The following changes were made to the repository to either improve or simplify the project logics in-terms of naming, functionality etc... - Removed `devJargonsAppAuth` from `octokit/app` and Moved OAuth App's octokit export to `oauth` object, it just makes logical sense to use `app.oauth.octokit` as jargons.dev OAuth App octokit and use `app.octokit` as jargons.dev GitHub App - Removed addressed todo from `submitWord` function and renamed label to `via jargons-editor` from `via word-editor` in `submit-word` script - Documented, fixed typo/naming and add some todo to `recent-searches` island and `search` store - add todo `@todo implement logic to allow holding maximum of 5 words by removing older words when new a one gets added` - Renamed localstorage object name to `jargons.dev:recent_searches` from `devJargonsRecentSearches` - Documented the `word-editor` island and added disallowed cursor on its `Preview` component dummy navbar - Removed `label:":computer: via word-editor"` from the `doContributionStats` action to effectively removing narrowed Pull request search to compute word contribution which was biased towards contribution done via the jargons editor - Documented `useLockBody` and `useIsMacOS` hooks - Modified the word contribution PR templates, making appropriate use of semantics for formatting headings - Added `@todo deprecate the `options` params` to selected `word-editor.js` function to remind of possibly removing the `options` param which was initially added to set environment where the function is being executed from - this was initially added - Removed redundant `$userData.set()` operation performed on the add new word page server-side (doesn't even work in the first place), and implemented `javascript: history.back()` as return navigation `location` to allow quick navigation back - a trick to avoid re-fetching the contribution stats for the jargons editor all over again - Renamed `otherWordData` to `wordMetaData` in word edit page and implemented a custom return navigation label and location to return to the word currently being edited canceling the operation onclick of course - Integrated Navbar to the jargons editor - Added `@todo Nice to have: endpoint queries the GitHub to fetch words directly from jargons.dev repo using the requester's accessToken` to jargons.dev `browse` api - meant to suggest an implementation where the api is requesting for all words or r=single word directly from jargons.dev github repo using the user's token; this is similar to how the `dictionary` endpoint `POST` handler operates. 📖
1 parent b14d00e commit 3298a9a

19 files changed

Lines changed: 74 additions & 51 deletions

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ GITHUB_OAUTH_APP_CLIENT_SECRET=""
88

99
CRYPTO_SECRET_KEY="secret"
1010

11-
PUBLIC_PROJECT_REPO="babblebey/jargons.dev"
11+
PUBLIC_PROJECT_REPO="user/jargons.dev-test"
1212
PUBLIC_PROJECT_REPO_BRANCH_REF="refs/heads/main"

astro.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { defineConfig } from "astro/config";
2-
import tailwind from "@astrojs/tailwind";
32
import mdx from "@astrojs/mdx";
43
import react from "@astrojs/react";
5-
4+
import tailwind from "@astrojs/tailwind";
65
import vercel from "@astrojs/vercel/serverless";
76

87
// https://astro.build/config

src/components/islands/recent-searches.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { useStore } from "@nanostores/react";
33
import { $recentSearches } from "../../lib/stores/search.js";
44

55
/**
6+
* Recent Searches Component - An Island that displays a user's last 5 searches
7+
*
68
* @todo implement a default list instead of `null` when no `$recentSearch` is found
79
* @todo implement loading component to avoid flickering UI
810
*/
9-
export default function RecenctSearches() {
11+
export default function RecentSearches() {
1012
const recentSearches = useStore($recentSearches);
1113

1214
useEffect(() => {
13-
$recentSearches.set({...JSON.parse(localStorage.getItem("devJargonsRecentSearches"))})
15+
$recentSearches.set({...JSON.parse(localStorage.getItem("jargons.dev:recent_searches"))})
1416
}, []);
1517

1618
return Object.values(recentSearches).length ? (

src/components/islands/word-editor.jsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { capitalizeText } from "../../lib/utils/index.js";
66
import useWordEditor from "../../lib/hooks/use-word-editor.js";
77
import { $isWordSubmitLoading } from "../../lib/stores/dictionary.js";
88

9+
/**
10+
* Main Word Editor Component - Island
11+
*/
912
export default function WordEditor({ title = "", content = "", metadata = {}, action }) {
1013
return (
1114
<div className="w-full flex border rounded-lg">
@@ -21,6 +24,9 @@ export default function WordEditor({ title = "", content = "", metadata = {}, ac
2124
);
2225
}
2326

27+
/**
28+
* Detached Editor Submit Button Component - Island
29+
*/
2430
export function SubmitButton({ children = "Submit" }) {
2531
const isSubmitLoading = useStore($isWordSubmitLoading);
2632

@@ -39,6 +45,9 @@ export function SubmitButton({ children = "Submit" }) {
3945
);
4046
}
4147

48+
/**
49+
* Editor Markdown Input Component
50+
*/
4251
function Editor({ eTitle, eContent, eMetadata, className, action, ...props }) {
4352
const router = useRouter();
4453
const { title, setTitle, content, setContent } = useWordEditor();
@@ -112,6 +121,9 @@ function Editor({ eTitle, eContent, eMetadata, className, action, ...props }) {
112121
);
113122
}
114123

124+
/**
125+
* Editor Markdown Preview Component
126+
*/
115127
function Preview({ className, ...props }) {
116128
const { title, content } = useWordEditor();
117129

@@ -120,7 +132,7 @@ function Preview({ className, ...props }) {
120132
className={`${className} select-none`}
121133
{...props}
122134
>
123-
<div className="h-1 grow overflow-auto space-y-6 rounded-lg border p-5 shadow-lg scrollbar">
135+
<div className="h-1 grow overflow-auto rounded-lg border p-5 shadow-lg scrollbar">
124136
<DummyPreviewNavbar />
125137

126138
<div className="max-w-4xl space-y-8 mx-auto">
@@ -143,10 +155,13 @@ function Preview({ className, ...props }) {
143155
);
144156
}
145157

158+
/**
159+
* Editor Preview Section Dummy Navbar
160+
*/
146161
const DummyPreviewNavbar = () => (
147-
<div className="@container">
162+
<div className="@container mb-6">
148163
<nav className="flex items-center justify-between pb-4">
149-
<span className="flex items-center underline">
164+
<span className="flex items-center underline cursor-not-allowed">
150165
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-4 h-4">
151166
<path strokeLinecap="round" strokeLinejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
152167
</svg>
@@ -155,7 +170,7 @@ const DummyPreviewNavbar = () => (
155170
</span>
156171
</span>
157172

158-
<div>
173+
<div className="cursor-not-allowed">
159174
<div className="relative w-56 text-sm hidden @md:flex items-center justify-between border pl-2.5 p-1 space-x-2 border-gray-400 rounded-lg">
160175
<div className="flex items-center text-gray-400 space-x-2">
161176
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-5 h-5">

src/lib/actions/do-contribution-stats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export default async function doContributionStats(astroGlobal) {
1616
/**
1717
* @todo Implement narrowed search to project's main branch
1818
*/
19-
const baseQuery = `repo:${repoFullname} is:pull-request type:pr author:@me label:":computer: via word-editor"`;
20-
const baseStatsUrlQuery = `is:pr author:@me label:":computer: via word-editor"`;
19+
const baseQuery = `repo:${repoFullname} is:pull-request type:pr author:@me`;
20+
const baseStatsUrlQuery = `is:pr author:@me`;
2121

2222
/**
2323
* @todo [thoughts]: would be nice to have all these requests in one, and use a filter to separate by labels

src/lib/hooks/use-is-mac-os.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { useEffect, useState } from "react";
22

33
const MAC_OS_USER_AGENT_PART = /Mac|Macintosh|MacIntel|Mac OS X/;
44

5+
/**
6+
* Custom hook used to check if current user's machine is macOS
7+
* @returns {boolean}
8+
*/
59
export default function useIsMacOS() {
610
const [isMacOS, setIsMacOS] = useState(false);
711

src/lib/hooks/use-lock-body.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useLayoutEffect } from "react";
22

3+
/**
4+
* Cutom hook to help remove navigation-ability from web page
5+
*/
36
export default function useLockBody() {
47
useLayoutEffect(() => {
58
const originalStyle = window.getComputedStyle(document.body).overflow;

src/lib/octokit/app.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,14 @@ const app = new App({
99
const { data: { id } } = await app.octokit.request(`GET /repos/${import.meta.env.PUBLIC_PROJECT_REPO}/installation`);
1010

1111
/**
12-
* DevJargons Helper App's Octokit instance
13-
*/
14-
const devJargonsOctokit = await app.getInstallationOctokit(id);
15-
16-
/**
17-
* DevJargons Helper App's Auth Token
12+
* jargons.dev Helper GitHub App's Octokit instance
1813
*/
19-
const devJargonsAppAuth = await (
20-
async () => {
21-
const { data: { token } } = await devJargonsOctokit.request(`POST /app/installations/${id}/access_tokens`);
22-
return token;
23-
}
24-
)();
14+
const appOctokit = await app.getInstallationOctokit(id);
2515

2616
/**
27-
* OAuth App's Octokit instance
28-
*
29-
* @todo consider removing this later, its looking redundant
17+
* OAuth App's Octokit instance - useful for verifying user accessToken validity
3018
*/
31-
const octokit = new Octokit({
19+
const oauthAppOctokit = new Octokit({
3220
authStrategy: createOAuthAppAuth,
3321
auth: {
3422
clientId: import.meta.env.GITHUB_OAUTH_APP_CLIENT_ID,
@@ -84,10 +72,9 @@ function getUserOctokit({ token, ...options }) {
8472
};
8573

8674
export default {
87-
octokit,
88-
devJargonsAppAuth,
89-
devJargonsOctokit,
75+
octokit: appOctokit,
9076
oauth: {
77+
octokit: oauthAppOctokit,
9178
getWebFlowAuthorizationUrl,
9279
exchangeWebFlowCode,
9380
},

src/lib/stores/search.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const $recentSearches = map({});
1414
/**
1515
* Add search term to recent search history
1616
* @param {SearchedItem} item
17+
*
18+
* @todo implement logic to allow holding maximum of 5 words by removing older words when new a one gets added
1719
*/
1820
export function $addToRecentSearchesFn({ word, url }) {
1921
const lowercaseKey = word.toLowerCase();
@@ -31,5 +33,5 @@ export function $addToRecentSearchesFn({ word, url }) {
3133
return;
3234
}
3335

34-
localStorage.setItem("devJargonsRecentSearches", JSON.stringify($recentSearches.get()));
36+
localStorage.setItem("jargons.dev:recent_searches", JSON.stringify($recentSearches.get()));
3537
}

src/lib/submit-word.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import editWordPRTemp from "./templates/edit-word-pr.md.js";
1212
* @param {{ title: string, content: string }} word
1313
*
1414
* @todo implement (submit as) `draft` feature - [idea]
15-
* @todo implement `maintainer_can_modify` toggle - [idea]
1615
*/
1716
export async function submitWord(devJargonsOctokit, userOctokit, action, projectRepoDetails, forkedRepoDetails, word) {
1817
const { repoFullname, repoMainBranchRef } = projectRepoDetails;
@@ -46,7 +45,7 @@ export async function submitWord(devJargonsOctokit, userOctokit, action, project
4645
issue_number: response.data.number,
4746
labels: [
4847
`:book: ${action} word`,
49-
":computer: via word-editor"
48+
":computer: via jargons-editor"
5049
]
5150
});
5251

0 commit comments

Comments
 (0)