Skip to content

Commit

Permalink
fix: replace +title with useConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Sep 16, 2024
1 parent 6d6c5a3 commit 850fed0
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 42 deletions.
11 changes: 11 additions & 0 deletions boilerplates/react/files/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";
import { useConfig } from "vike-react/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
// Set <title>
title: movie.title

Check failure on line 18 in boilerplates/react/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 18 in boilerplates/react/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to
// the client; we should minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/react/files/pages/star-wars/@id/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/react/files/pages/star-wars/index/+data.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// https://vike.dev/data

import type { Movie, MovieDetails } from "../types.js";
import { useConfig } from "vike-react/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const moviesData = (await response.json()) as MovieDetails[];

config({
// Set <title>
title: `${moviesData.length} Star Wars Movies`

Check failure on line 17 in boilerplates/react/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 17 in boilerplates/react/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to the client; we should
// minimize what is sent over the network.
const movies = minimize(moviesData);

return movies;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/react/files/pages/star-wars/index/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/solid/files/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";
import { useConfig } from "vike-solid/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
// Set <title>
title: movie.title

Check failure on line 18 in boilerplates/solid/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 18 in boilerplates/solid/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to
// the client; we should minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/solid/files/pages/star-wars/@id/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/solid/files/pages/star-wars/index/+data.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// https://vike.dev/data

import type { Movie, MovieDetails } from "../types.js";
import { useConfig } from "vike-solid/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const moviesData = (await response.json()) as MovieDetails[];

config({
// Set <title>
title: `${moviesData.length} Star Wars Movies`

Check failure on line 17 in boilerplates/solid/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 17 in boilerplates/solid/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to the client; we should
// minimize what is sent over the network.
const movies = minimize(moviesData);

return movies;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/solid/files/pages/star-wars/index/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/vue/files/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";
import { useConfig } from "vike-vue/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
// Set <title>
title: movie.title

Check failure on line 18 in boilerplates/vue/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 18 in boilerplates/vue/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to
// the client; we should minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/vue/files/pages/star-wars/@id/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/vue/files/pages/star-wars/index/+data.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// https://vike.dev/data

import type { Movie, MovieDetails } from "../types.js";
import { useConfig } from "vike-vue/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const moviesData = (await response.json()) as MovieDetails[];

config({
// Set <title>
title: `${moviesData.length} Star Wars Movies`

Check failure on line 17 in boilerplates/vue/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 17 in boilerplates/vue/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to the client; we should
// minimize what is sent over the network.
const movies = minimize(moviesData);

return { data: movies };
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/vue/files/pages/star-wars/index/+title.ts

This file was deleted.

0 comments on commit 850fed0

Please sign in to comment.