Skip to content

Commit

Permalink
Revert "Wire frontend for appstream translations"
Browse files Browse the repository at this point in the history
This reverts commit 2036e06.
  • Loading branch information
razzeee committed May 26, 2024
1 parent e9585a8 commit 930a9ff
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 51 deletions.
3 changes: 0 additions & 3 deletions backend/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def get_appstream(
pattern=r"^[A-Za-z_][\w\-\.]+$",
examples=["org.gnome.Glade"],
),
locale: str = "en",
):
## TODO: Use locale to return the correct language - but fallback to english if not available

if value := db.get_json_key(f"apps:{app_id}"):
return value

Expand Down
8 changes: 1 addition & 7 deletions backend/tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,13 @@ def test_apps_by_non_existent_developer(client):


def test_appstream_by_appid(client, snapshot):
response = client.get("/appstream/org.sugarlabs.Maze?locale=en")
assert response.status_code == 200
assert snapshot("test_appstream_by_appid_en.json") == response.json()


def test_appstream_by_appid_fallback(client, snapshot):
response = client.get("/appstream/org.sugarlabs.Maze")
assert response.status_code == 200
assert snapshot("test_appstream_by_appid.json") == response.json()


def test_appstream_by_non_existent_appid(client):
response = client.get("/appstream/NonExistent?locale=en")
response = client.get("/appstream/NonExistent")
assert response.status_code == 404
assert response.json() is None

Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/apps/[appDetails].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const getStaticProps: GetStaticProps = async ({
}

let eolMessage: string = null
const app = await (await fetchAppstream(appId as string, locale)).data
const app = await (await fetchAppstream(appId as string)).data

if (!app) {
eolMessage = (await getEolMessageAppidEolMessageAppIdGet(appId as string))
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/apps/manage/[appId]/accept-invite/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const getStaticProps: GetStaticProps = async ({
locale,
params: { appId },
}) => {
const app = (await fetchAppstream(appId as string, locale))?.data
const app = (await fetchAppstream(appId as string))?.data

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/apps/manage/[appId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const getStaticProps: GetStaticProps = async ({
axios.defaults.baseURL = process.env.NEXT_PUBLIC_API_BASE_URI

const [{ data: app }, { data: vendingConfig }] = await Promise.all([
fetchAppstream(appId as string, locale),
fetchAppstream(appId as string),
getGlobalVendingConfigVendingConfigGet(),
])

Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/apps/purchase/[appId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getStaticProps: GetStaticProps = async ({
axios.defaults.baseURL = process.env.NEXT_PUBLIC_API_BASE_URI

const [{ data: app }, { data: vendingConfig }] = await Promise.all([
fetchAppstream(appId as string, locale),
fetchAppstream(appId as string),
getGlobalVendingConfigVendingConfigGet(),
])

Expand Down
23 changes: 9 additions & 14 deletions frontend/src/asyncs/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ import { Appstream } from "../types/Appstream"
* Fetches the appstream data for a set of apps (e.g. the user's).
* @param appIds array of app identifiers to fetch data for
*/
export async function getAppsInfo(
appIds: string[],
locale: string,
): Promise<Appstream[]> {
export async function getAppsInfo(appIds: string[]): Promise<Appstream[]> {
const responses = await Promise.allSettled(
appIds.map(async (id) => ({
id,
response: await axios
.get<Appstream>(`${APP_DETAILS(id, locale)}`)
.catch(() => {
return {
data: {
id: id,
name: id,
} as Appstream,
} as AxiosResponse<Appstream>
}),
response: await axios.get<Appstream>(`${APP_DETAILS(id)}`).catch(() => {
return {
data: {
id: id,
name: id,
} as Appstream,
} as AxiosResponse<Appstream>
}),
})),
)

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/moderation/AppModeration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const AppModeration: FunctionComponent<Props> = ({ appId }) => {

const appInfoQuery = useQuery({
queryKey: ["app", appId],
queryFn: () => getAppsInfo([appId], "en"),
queryFn: () => getAppsInfo([appId]),
enabled: !!appId,
})

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/moderation/ModerationTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ const ModerationTabs: FunctionComponent = () => {

return {
apps: apps.data,
appstream: await getAppsInfo(
apps.data.apps.map((app) => app.appid),
"en",
),
appstream: await getAppsInfo(apps.data.apps.map((app) => app.appid)),
}
},
})
Expand Down
10 changes: 2 additions & 8 deletions frontend/src/components/user/UserApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ import { doRefreshDevFlatpaksAuthRefreshDevFlatpaksPost } from "src/codegen"
interface Props {
variant: "dev" | "owned" | "invited"
customButtons?: JSX.Element
locale: string
}

const UserApps: FunctionComponent<Props> = ({
variant,
customButtons,
locale,
}) => {
const UserApps: FunctionComponent<Props> = ({ variant, customButtons }) => {
const { t } = useTranslation()
const user = useUserContext()
const userDispatch = useUserDispatch()
Expand All @@ -28,14 +23,13 @@ const UserApps: FunctionComponent<Props> = ({
const [page, setPage] = useState(1)

const queryDevApplications = useQuery({
queryKey: [`${variant}-apps`, page, pageSize, locale],
queryKey: [`${variant}-apps`, page, pageSize],
queryFn: async () => {
return getAppsInfo(
user.info[`${variant}_flatpaks`].slice(
(page - 1) * pageSize,
(page - 1) * pageSize + pageSize,
),
locale,
)
},
enabled: !!user.info,
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Category } from "./types/Category"
const BASE_URI: string = process.env.NEXT_PUBLIC_API_BASE_URI

export const APPSTREAM_URL: string = `${BASE_URI}/appstream`
export const APP_DETAILS = (id: string, locale: string): string =>
`${APPSTREAM_URL}/${id}?locale=${locale}`
export const APP_DETAILS = (id: string): string => `${APPSTREAM_URL}/${id}`
export const SUMMARY_DETAILS = (id: string): string =>
`${BASE_URI}/summary/${id}`
export const STATS_DETAILS = (id: string): string => `${BASE_URI}/stats/${id}`
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ export async function fetchAppstreamList() {
return axios.get<string[]>(APPSTREAM_URL)
}

export async function fetchAppstream(appId: string, locale: string) {
return axios
.get<Appstream>(`${APP_DETAILS(appId, locale)}`)
.catch((error) => {
return {
data: null,
}
})
export async function fetchAppstream(appId: string) {
return axios.get<Appstream>(`${APP_DETAILS(appId)}`).catch((error) => {
return {
data: null,
}
})
}

export async function fetchSummary(appId: string) {
Expand Down

0 comments on commit 930a9ff

Please sign in to comment.