Cleanup unused frontend code (#653)

* frontend: remove unnecessary imports & js files

* frontend: cleanup code with elm-review - remove unused code

* frontend: remove duplicate viewport
This commit is contained in:
Marco Daniel Martins 2023-05-04 14:51:19 +02:00 committed by GitHub
parent 0d663f27fa
commit 0498effc41
Failed to generate hash of commit
8 changed files with 19 additions and 114 deletions

View file

@ -28,15 +28,13 @@ import Html.Attributes
) )
import Json.Decode import Json.Decode
import Page.Flakes exposing (Model(..)) import Page.Flakes exposing (Model(..))
import Page.Home
import Page.Options import Page.Options
import Page.Packages import Page.Packages
import RemoteData exposing (RemoteData(..)) import RemoteData exposing (RemoteData(..))
import Route exposing (SearchType(..)) import Route exposing (SearchType(..))
import Search import Search
exposing exposing
( Msg(..) ( NixOSChannel
, NixOSChannel
, decodeNixOSChannels , decodeNixOSChannels
, defaultFlakeId , defaultFlakeId
) )
@ -68,7 +66,6 @@ type alias Model =
type Page type Page
= NotFound = NotFound
| Home Page.Home.Model
| Packages Page.Packages.Model | Packages Page.Packages.Model
| Options Page.Options.Model | Options Page.Options.Model
| Flakes Page.Flakes.Model | Flakes Page.Flakes.Model
@ -113,7 +110,6 @@ init flags url navKey =
type Msg type Msg
= ChangedUrl Url.Url = ChangedUrl Url.Url
| ClickedLink Browser.UrlRequest | ClickedLink Browser.UrlRequest
| HomeMsg Page.Home.Msg
| PackagesMsg Page.Packages.Msg | PackagesMsg Page.Packages.Msg
| OptionsMsg Page.Options.Msg | OptionsMsg Page.Options.Msg
| FlakesMsg Page.Flakes.Msg | FlakesMsg Page.Flakes.Msg
@ -199,9 +195,6 @@ pageMatch m1 m2 =
( NotFound, NotFound ) -> ( NotFound, NotFound ) ->
True True
( Home _, Home _ ) ->
True
( Packages model_a, Packages model_b ) -> ( Packages model_a, Packages model_b ) ->
{ model_a | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked } { model_a | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked }
== { model_b | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked } == { model_b | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked }
@ -321,10 +314,6 @@ update msg model =
( ChangedUrl url, _ ) -> ( ChangedUrl url, _ ) ->
changeRouteTo model url changeRouteTo model url
( HomeMsg subMsg, Home subModel ) ->
Page.Home.update subMsg subModel model.nixosChannels
|> updateWith Home HomeMsg model
( PackagesMsg subMsg, Packages subModel ) -> ( PackagesMsg subMsg, Packages subModel ) ->
Page.Packages.update model.navKey subMsg subModel model.nixosChannels Page.Packages.update model.navKey subMsg subModel model.nixosChannels
|> updateWith Packages PackagesMsg model |> updateWith Packages PackagesMsg model
@ -337,7 +326,7 @@ update msg model =
Page.Flakes.update model.navKey subMsg subModel model.nixosChannels Page.Flakes.update model.navKey subMsg subModel model.nixosChannels
|> updateWith Flakes FlakesMsg model |> updateWith Flakes FlakesMsg model
( _, _ ) -> _ ->
-- Disregard messages that arrived for the wrong page. -- Disregard messages that arrived for the wrong page.
( model, Cmd.none ) ( model, Cmd.none )
@ -455,9 +444,6 @@ viewPage model =
NotFound -> NotFound ->
div [] [ text "Not Found" ] div [] [ text "Not Found" ]
Home _ ->
div [] [ text "Welcome" ]
Packages packagesModel -> Packages packagesModel ->
Html.map (\m -> PackagesMsg m) <| Page.Packages.view model.nixosChannels packagesModel Html.map (\m -> PackagesMsg m) <| Page.Packages.view model.nixosChannels packagesModel

View file

@ -26,11 +26,10 @@ import Html.Events exposing (onClick)
import Http exposing (Body) import Http exposing (Body)
import Page.Options exposing (Msg(..)) import Page.Options exposing (Msg(..))
import Page.Packages exposing (Msg(..)) import Page.Packages exposing (Msg(..))
import RemoteData exposing (RemoteData(..)) import RemoteData
import Route import Route
exposing exposing
( Route(..) ( SearchType(..)
, SearchType(..)
) )
import Search import Search
exposing exposing

View file

@ -1,45 +0,0 @@
module Page.Home exposing (Model, Msg, init, update, view)
import Html exposing (Html, div, text)
import Search exposing (NixOSChannel)
-- MODEL
type alias Model =
()
init : ( Model, Cmd Msg )
init =
( (), Cmd.none )
-- UPDATE
type Msg
= NoOp
update :
Msg
-> Model
-> List NixOSChannel
-> ( Model, Cmd Msg )
update msg model _ =
case msg of
NoOp ->
( model, Cmd.none )
-- VIEW
view : Model -> Html Msg
view _ =
div [] [ text "Home" ]

View file

@ -3,9 +3,7 @@ module Page.Packages exposing
, Msg(..) , Msg(..)
, decodeResultAggregations , decodeResultAggregations
, decodeResultItemSource , decodeResultItemSource
, encodeBuckets
, init , init
, initBuckets
, makeRequest , makeRequest
, makeRequestBody , makeRequestBody
, update , update
@ -14,7 +12,6 @@ module Page.Packages exposing
, viewSuccess , viewSuccess
) )
import Browser.Events exposing (Visibility(..))
import Browser.Navigation import Browser.Navigation
import Html import Html
exposing exposing
@ -47,12 +44,11 @@ import Json.Decode.Pipeline
import Json.Encode import Json.Encode
import Maybe import Maybe
import Regex import Regex
import Route exposing (Route(..), SearchType) import Route exposing (SearchType)
import Search import Search
exposing exposing
( Details(..) ( Details
, NixOSChannel , NixOSChannel
, decodeResolvedFlake
, viewBucket , viewBucket
) )
import Utils import Utils

View file

@ -6,13 +6,10 @@ module Route exposing
, allTypes , allTypes
, fromUrl , fromUrl
, href , href
, replaceUrl
, routeToString , routeToString
, searchTypeToString
, searchTypeToTitle , searchTypeToTitle
) )
import Browser.Navigation
import Html import Html
import Html.Attributes import Html.Attributes
import Route.SearchQuery exposing (SearchQuery) import Route.SearchQuery exposing (SearchQuery)
@ -164,11 +161,6 @@ href targetRoute =
Html.Attributes.href (routeToString targetRoute) Html.Attributes.href (routeToString targetRoute)
replaceUrl : Browser.Navigation.Key -> Route -> Cmd msg
replaceUrl navKey route =
Browser.Navigation.replaceUrl navKey (routeToString route)
fromUrl : Url.Url -> Maybe Route fromUrl : Url.Url -> Maybe Route
fromUrl url = fromUrl url =
-- The RealWorld spec treats the fragment like a path. -- The RealWorld spec treats the fragment like a path.

View file

@ -11,14 +11,11 @@ module Search exposing
, ResultItem , ResultItem
, SearchResult , SearchResult
, Sort(..) , Sort(..)
, closeButton
, decodeAggregation , decodeAggregation
, decodeNixOSChannels , decodeNixOSChannels
, decodeResolvedFlake , decodeResolvedFlake
, decodeResult
, defaultFlakeId , defaultFlakeId
, elementId , elementId
, fromSortId
, init , init
, makeRequest , makeRequest
, makeRequestBody , makeRequestBody
@ -36,7 +33,6 @@ module Search exposing
import Base64 import Base64
import Browser.Dom import Browser.Dom
import Browser.Events exposing (Visibility(..))
import Browser.Navigation import Browser.Navigation
import Html import Html
exposing exposing
@ -379,7 +375,6 @@ type Msg a b
| ToggleSort | ToggleSort
| BucketsChange String | BucketsChange String
| ChannelChange String | ChannelChange String
| FlakeChange String
| SubjectChange SearchType | SubjectChange SearchType
| QueryInput String | QueryInput String
| QueryInputSubmit | QueryInputSubmit
@ -464,16 +459,6 @@ update toRoute navKey msg model nixosChannels =
|> ensureLoading nixosChannels |> ensureLoading nixosChannels
|> pushUrl toRoute navKey |> pushUrl toRoute navKey
FlakeChange flake ->
{ model
| channel = flake
, show = Nothing
, buckets = Nothing
, from = 0
}
|> ensureLoading nixosChannels
|> pushUrl toRoute navKey
SubjectChange subject -> SubjectChange subject ->
{ model { model
| searchType = subject | searchType = subject

View file

@ -2,29 +2,22 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NixOS Search</title> <title>NixOS Search</title>
<script type="text/javascript" src="https://nixos.org/js/jquery.min.js"></script> <link rel="stylesheet" href="https://nixos.org/bootstrap/css/bootstrap.min.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="https://nixos.org/bootstrap/css/bootstrap-responsive.min.css"/>
<script type="text/javascript" src="https://nixos.org/bootstrap/js/bootstrap.min.js"></script> <link rel="shortcut icon" type="image/png" href="https://nixos.org/favicon.png"/>
<link rel="stylesheet" href="https://nixos.org/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://nixos.org/bootstrap/css/bootstrap-responsive.min.css" /> <link rel="search" type="application/opensearchdescription+xml" title="NixOS packages"
href="/desc-search-packages.xml">
<link rel="shortcut icon" type="image/png" href="https://nixos.org/favicon.png" /> <link rel="search" type="application/opensearchdescription+xml" title="NixOS options"
href="/desc-search-options.xml">
<link rel="search" type="application/opensearchdescription+xml" title="NixOS packages"
href="/desc-search-packages.xml">
<link rel="search" type="application/opensearchdescription+xml" title="NixOS options" href="/desc-search-options.xml">
</head> </head>
<body> <body></body>
<script src="https://nixos.org/js/jquery.min.js"></script>
<script src="https://nixos.org/bootstrap/js/bootstrap.min.js"></script>
</body>
</html> </html>

View file

@ -1,8 +1,7 @@
module Example exposing (fuzzTest, unitTest, viewTest) module Example exposing (fuzzTest, unitTest, viewTest)
import Expect exposing (Expectation) import Expect
import Fuzz exposing (Fuzzer, int, list, string) import Fuzz exposing (int)
import Main exposing (..)
import Test exposing (..) import Test exposing (..)
import Test.Html.Query as Query import Test.Html.Query as Query
import Test.Html.Selector exposing (tag, text) import Test.Html.Selector exposing (tag, text)