-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05ee9cb
commit a36794f
Showing
11 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
export const urlSlice = createSlice({ | ||
name: "url", | ||
initialState: "", | ||
reducers: { | ||
initUrl: () => { | ||
const query = new URLSearchParams(window.location.search); | ||
const url = query.get("url"); | ||
return url; | ||
}, | ||
setUrl: (_state, action) => { | ||
return action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { initUrl, setUrl } = urlSlice.actions; | ||
|
||
export default urlSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-disable react/prop-types */ | ||
import React, { useRef, useState, useEffect } from "react"; | ||
import axios from "axios"; | ||
|
||
import { useDispatch } from "react-redux"; | ||
import { setUrl } from "./../_redux/url"; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const Subpages = ({ url, auth, t }) => { | ||
const [error, setError] = useState(""); | ||
const [loading, setLoading] = useState(true); | ||
const [subpages, setSubpages] = useState([]); | ||
const loaded = useRef(false); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
if (loaded.current === false) { | ||
const API_URL = | ||
process.env.NODE_ENV === "development" | ||
? process.env.REACT_APP_API_LOCAL_SERVER | ||
: process.env.REACT_APP_API_SERVER; | ||
|
||
setLoading(true); | ||
axios({ | ||
method: "post", | ||
url: API_URL + "/api/getsubpages", | ||
data: { | ||
url, | ||
authKey: auth.authKey, | ||
}, | ||
}).then((res) => { | ||
setLoading(false); | ||
|
||
if (res.data.meta) { | ||
setSubpages(res.data.meta); | ||
setError(""); | ||
} else { | ||
setError(res.data.error); | ||
} | ||
}); | ||
|
||
loaded.current = true; | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<div> | ||
{loading ? ( | ||
<span>{t("Loading...")}</span> | ||
) : ( | ||
<div> | ||
{subpages.length > 0 ? ( | ||
<select | ||
style={{ width: 200 }} | ||
className="rounded-lg" | ||
onChange={(e) => { | ||
dispatch(setUrl(e.target.value)); | ||
}} | ||
> | ||
{subpages.map((u, key) => ( | ||
<option key={key} value={u.url}> | ||
/{u.url.match(/^https?:\/\/[a-zA-Z:.0-9]+\/(.*)$/)[1]} -{" "} | ||
{u.count} {u.count > 1 ? t("comments") : t("comment")} | ||
</option> | ||
))} | ||
</select> | ||
) : ( | ||
<span>{t("No subpages")}</span> | ||
)} | ||
|
||
{error && <span>{error}</span>} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Subpages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters